Minor clean up for test_jit (#15368)
authorWanchao Liang <wanchaol@users.noreply.github.com>
Wed, 19 Dec 2018 02:23:55 +0000 (18:23 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 19 Dec 2018 02:26:37 +0000 (18:26 -0800)
Summary:
* remove None args in functional tests
* remove some expect files that are not necessary
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15368

Differential Revision: D13512349

Pulled By: wanchaol

fbshipit-source-id: 304cffff966487d15c373057ae8ad114ef8aa7f9

test/expect/TestJit.test_function_default_values-bool.expect [deleted file]
test/expect/TestJit.test_function_default_values-none.expect [deleted file]
test/expect/TestJit.test_function_default_values-simple.expect [deleted file]
test/expect/TestJit.test_function_default_values-type_hints.expect [deleted file]
test/expect/TestJit.test_scopes.expect [deleted file]
test/expect/TestJit.test_simple.expect [deleted file]
test/test_jit.py

diff --git a/test/expect/TestJit.test_function_default_values-bool.expect b/test/expect/TestJit.test_function_default_values-bool.expect
deleted file mode 100644 (file)
index edf5ba7..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-graph(%x : Tensor
-      %a : Tensor
-      %flag : Tensor) {
-  %3 : int = prim::Constant[value=1]()
-  %4 : bool = prim::Bool(%flag)
-  %result : Tensor = prim::If(%4)
-    block0() {
-      -> (%x)
-    }
-    block1() {
-      %result.1 : Tensor = aten::add(%x, %a, %3)
-      -> (%result.1)
-    }
-  return (%result);
-}
diff --git a/test/expect/TestJit.test_function_default_values-none.expect b/test/expect/TestJit.test_function_default_values-none.expect
deleted file mode 100644 (file)
index f47ed8a..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-graph(%x : int?) {
-  return (%x);
-}
diff --git a/test/expect/TestJit.test_function_default_values-simple.expect b/test/expect/TestJit.test_function_default_values-simple.expect
deleted file mode 100644 (file)
index 782d216..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-graph(%x : Tensor
-      %a : Tensor
-      %b : Tensor
-      %c : Tensor) {
-  %4 : int = prim::Constant[value=1]()
-  %5 : Tensor = aten::add(%x, %a, %4)
-  %6 : Tensor = aten::add(%5, %b, %4)
-  %7 : Tensor = aten::add(%6, %c, %4)
-  return (%7);
-}
diff --git a/test/expect/TestJit.test_function_default_values-type_hints.expect b/test/expect/TestJit.test_function_default_values-type_hints.expect
deleted file mode 100644 (file)
index b32b966..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-graph(%x : Tensor
-      %a : float
-      %b : int) {
-  %3 : int = prim::Constant[value=1]()
-  %4 : Tensor = aten::add(%x, %a, %3)
-  %5 : Tensor = aten::add(%4, %b, %3)
-  return (%5);
-}
diff --git a/test/expect/TestJit.test_scopes.expect b/test/expect/TestJit.test_scopes.expect
deleted file mode 100644 (file)
index 3cbbb0b..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-graph(%0 : Double(1)
-      %1 : Double(1)) {
-  %2 : int = prim::Constant[value=1]()
-  %3 : Double(1) = aten::add(%0, %1, %2)
-  %4 : Double(1) = aten::mul(%0, %3), scope: Foo
-  %5 : Double(1) = aten::tanh(%4), scope: Foo/Bar
-  %6 : Double(1) = aten::sigmoid(%5), scope: Foo
-  return (%6);
-}
diff --git a/test/expect/TestJit.test_simple.expect b/test/expect/TestJit.test_simple.expect
deleted file mode 100644 (file)
index bfa7408..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-graph(%0 : Double(1)
-      %1 : Double(1)) {
-  %2 : int = prim::Constant[value=1]()
-  %3 : Double(1) = aten::add(%0, %1, %2)
-  %4 : Double(1) = aten::mul(%0, %3)
-  %5 : Double(1) = aten::tanh(%4)
-  %6 : Double(1) = aten::sigmoid(%5)
-  return (%6);
-}
index 760f902..82f89ca 100644 (file)
@@ -534,9 +534,7 @@ class TestJit(JitTestCase):
         def f(x, y):
             return torch.sigmoid(torch.tanh(x * (x + y)))
 
-        trace, z = torch.jit.get_trace_graph(f, (x, y))
-        self.assertExpectedGraph(trace)
-        self.assertExportImport(trace, (x, y))
+        self.checkTrace(f, (x, y))
 
     def test_restore_device(self):
         # main purpose is checking map_location works
@@ -779,9 +777,7 @@ class TestJit(JitTestCase):
                 out = torch.sigmoid(out)
             return out
 
-        trace, z = torch.jit.get_trace_graph(f, (x, y))
-        self.assertExpectedGraph(trace)
-        self.assertExportImport(trace, (x, y))
+        self.checkTrace(f, (x, y))
 
     def test_scopes_intermediate_node(self):
 
@@ -1981,7 +1977,6 @@ class TestJit(JitTestCase):
         def simple_fn(x, a=a, b=b, c=outer_var + outer_var2):
             return x + a + b + c
 
-        self.assertExpectedGraph(simple_fn.graph, "simple")
         self.assertEqual(
             simple_fn(torch.ones(1)),
             torch.ones(1) + 0.5 + 10 + (20 + 30))
@@ -2000,7 +1995,6 @@ class TestJit(JitTestCase):
                 result = x + a
             return result
 
-        self.assertExpectedGraph(bool_fn.graph, "bool")
         self.assertEqual(bool_fn(torch.ones(1)), torch.ones(1) + 9)
         self.assertEqual(
             bool_fn(torch.ones(1), torch.tensor(1), torch.tensor(True)),
@@ -2011,7 +2005,6 @@ class TestJit(JitTestCase):
             # type: (Optional[int]) -> Optional[int]
             return x
 
-        self.assertExpectedGraph(none_fn.graph, "none")
         self.assertEqual(none_fn(), None)
         self.assertEqual(none_fn(1), 1)
 
@@ -2020,7 +2013,6 @@ class TestJit(JitTestCase):
             # type: (Tensor, float, int) -> Tensor
             return x + a + b
 
-        self.assertExpectedGraph(hints.graph, "type_hints")
         self.assertEqual(hints(torch.ones(1)), torch.ones(1) + 0.5 + 10)
 
         with self.assertRaisesRegex(RuntimeError, "Expected a default value"):
@@ -4404,11 +4396,7 @@ a")
         var_int = [2, -2]
         var_float = [1.4321, -1.2]
 
-        ops = ['+', '-', '*', '%', '<', '<=', '>', '>=', '==', '!=']
-        # TODO: turn this on for py3 (and add PY3 division semantics)
-        ops_py2_only = ['/']
-        if PY2:
-            ops.extend(ops_py2_only)
+        ops = ['+', '-', '*', '%', '<', '<=', '>', '>=', '==', '!=', '/']
 
         float_tensor = torch.randn(5, 5, device=device)
         double_tensor = torch.randn(5, 5, dtype=torch.double, device=device)
@@ -10646,19 +10634,17 @@ EXCLUDE_MODULE_EXPORT_IMPORT = {
 #   kwargs for function,                                     // optional
 # )
 nn_functional_tests = [
-    # TODO: default arguments for None type not supported, add
-    # manually as argument, remove when ATen default arg system ready
-    ('conv1d', (S, S, S), ((S, S, S), None)),
-    ('conv2d', (S, S, S, S), ((S, S, S, S), None)),
-    ('conv3d', (S, S, S, S, S), ((S, S, S, S, S), None)),
-    ('conv_transpose1d', (S, S, S), ((S, S, S), None)),
-    ('conv_transpose2d', (S, S, S, S), ((S, S, S, S), None)),
-    ('conv_transpose3d', (S, S, S, S, S), ((S, S, S, S, S), None)),
+    ('conv1d', (S, S, S), ((S, S, S),)),
+    ('conv2d', (S, S, S, S), ((S, S, S, S),)),
+    ('conv3d', (S, S, S, S, S), ((S, S, S, S, S),)),
+    ('conv_transpose1d', (S, S, S), ((S, S, S),)),
+    ('conv_transpose2d', (S, S, S, S), ((S, S, S, S),)),
+    ('conv_transpose3d', (S, S, S, S, S), ((S, S, S, S, S),)),
     ('conv_tbc', (S, S, S), ((S, S, S), (S,), 2)),
     ('avg_pool1d', (S, S, S), (3,)),
     ('avg_pool2d', (S, S, S, S), (3,)),
     ('avg_pool3d', (S, S, S, S, S), (3,)),
-    ('fractional_max_pool2d', (S, S, S, S), (3, [2, 3], None)),
+    ('fractional_max_pool2d', (S, S, S, S), (3, [2, 3],)),
     ('max_pool1d', (S, S, S), (2, 1)),
     ('max_pool1d', (S, S, S), (2, 1, 1, 1, False, True), 'with_indices'),
     ('max_pool2d', (S, S, S, S), (2, 1)),
@@ -10708,16 +10694,16 @@ nn_functional_tests = [
     ('tanh', (S, S, S), (),),
     ('sigmoid', (S, S, S), (),),
     ('log_softmax', (S, S, S), (0,),),
-    ('linear', (S, S), ((M, S), None),),
-    ('bilinear', (S, S, S), ((S, S, M), torch.zeros(M, S, M), None),),
+    ('linear', (S, S), ((M, S),),),
+    ('bilinear', (S, S, S), ((S, S, M), torch.zeros(M, S, M),),),
     ('embedding', torch.tensor([[1, 2, 4, 5], [4, 3, 2, 5]]), (torch.rand(6, 3), ),),
     ('embedding_bag', torch.tensor([1, 2, 4, 2]), (torch.rand(5, 3), torch.tensor([0, 4]),),),
     ('batch_norm', (S, S), (non_differentiable(torch.randn(S)), non_differentiable(torch.ones(S)), ),),
     ('instance_norm', (S, S, S), (non_differentiable(torch.zeros(S)), non_differentiable(torch.ones(S))),),
-    ('layer_norm', (S, S, S, S), ([5], None, None),),
-    ('group_norm', (S, S, S), (1, torch.rand(5), None),),
+    ('layer_norm', (S, S, S, S), ([5],),),
+    ('group_norm', (S, S, S), (1, torch.rand(5),),),
     ('local_response_norm', (S, S, S), (2, ),),
-    ('nll_loss', F.log_softmax(torch.randn(3, 5), dim=0), (torch.tensor([1, 0, 4]), None, None),),
+    ('nll_loss', F.log_softmax(torch.randn(3, 5), dim=0), (torch.tensor([1, 0, 4]),),),
     ('poisson_nll_loss', torch.rand(S, 2), (torch.rand(S, 2),),),
     ('poisson_nll_loss', torch.rand(S, 2), (torch.rand(S, 2), True, True), 'full'),
     ('kl_div', F.log_softmax(torch.randn(S, 10), 1), (F.softmax(torch.randn(S, 10), 1),),),
@@ -10749,20 +10735,20 @@ nn_functional_tests = [
     ('gumbel_softmax', (S, S), (2.,),),
     ('gumbel_softmax', (S, S), (2., True,), 'hard'),
     ('multilabel_margin_loss', torch.tensor([[0.2, -0.2, 0.07]]), (torch.tensor([[0, 0, 1]]),),),
-    ('multi_margin_loss', (S, S), (non_differentiable(torch.randint(S, (S, ), dtype=torch.int64)), \
+    ('multi_margin_loss', (S, S), (non_differentiable(torch.randint(S, (S, ), dtype=torch.int64)),
                                    1, 1., non_differentiable(torch.randn(S))),),
-    ('binary_cross_entropy', torch.randn(3, 2).sigmoid(), (non_differentiable(torch.rand(3, 2)), \
+    ('binary_cross_entropy', torch.randn(3, 2).sigmoid(), (non_differentiable(torch.rand(3, 2)),
                                                            non_differentiable(torch.randn(3, 2))),),
     ('binary_cross_entropy', torch.randn(3, 2).sigmoid(),
         (non_differentiable(torch.rand(3, 2)),
          non_differentiable(torch.randn(3, 2)), None, None, 'mean'), 'size_average'),
-    ('ctc_loss', torch.rand(S, S, S).log_softmax(2).detach().requires_grad_(), \
-     (torch.randint(1, S, (S, S), dtype=torch.long), torch.full((S,), S, dtype=torch.long), \
+    ('ctc_loss', torch.rand(S, S, S).log_softmax(2).detach().requires_grad_(),
+     (torch.randint(1, S, (S, S), dtype=torch.long), torch.full((S,), S, dtype=torch.long),
       torch.randint(1, S, (S,), dtype=torch.long))),
     ('upsample', torch.randn(S, S, M, M), (None, 2), 'with_scale'),
-    ('upsample', torch.randn(S, S, M, M), (4, None), 'with_size'),
+    ('upsample', torch.randn(S, S, M, M), (4,), 'with_size'),
     ('interpolate', torch.randn(S, S, M, M), (None, 2.), 'with_scale'),
-    ('interpolate', torch.randn(S, S, M, M), (4, None), 'with_size'),
+    ('interpolate', torch.randn(S, S, M, M), (4,), 'with_size'),
 ]