From bc290a580e25eb82b28bbfb231c1b161a12bca44 Mon Sep 17 00:00:00 2001 From: Jorn Tuyls Date: Tue, 27 Apr 2021 05:15:17 -0700 Subject: [PATCH] Fix unit tests for Relay padding layer translation fixes --- .../relay_tools/test_relay_l2_convolution.py | 9 ++-- .../test_relay_l3_math_and_transform.py | 6 ++- tests/unit/frontend/tvm/test_relay.py | 47 +++++++++---------- tests/unit/frontend/tvm/test_relay_io.py | 23 +++++---- 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/tests/unit/frontend/tvm/relay_tools/test_relay_l2_convolution.py b/tests/unit/frontend/tvm/relay_tools/test_relay_l2_convolution.py index 5e522cc..995eee6 100644 --- a/tests/unit/frontend/tvm/relay_tools/test_relay_l2_convolution.py +++ b/tests/unit/frontend/tvm/relay_tools/test_relay_l2_convolution.py @@ -380,15 +380,12 @@ def test_padding(self): xg = xf_relay.from_relay(mod, {}) layers = xg.get_layers() - assert len(layers) == 3 + assert len(layers) == 2 - assert layers[0].type[0] == "Constant" + assert layers[0].type[0] == "Input" assert "relay_id" in layers[0].attrs - - assert layers[1].type[0] == "Input" - assert "relay_id" in layers[1].attrs - X = layers[2] + X = layers[1] assert X.type[0] == "Pad" assert X.bottoms == ["var"] assert X.shapes == [-1, 2, 5, 5] diff --git a/tests/unit/frontend/tvm/relay_tools/test_relay_l3_math_and_transform.py b/tests/unit/frontend/tvm/relay_tools/test_relay_l3_math_and_transform.py index b04222a..6028d3a 100644 --- a/tests/unit/frontend/tvm/relay_tools/test_relay_l3_math_and_transform.py +++ b/tests/unit/frontend/tvm/relay_tools/test_relay_l3_math_and_transform.py @@ -175,6 +175,7 @@ def test_reshape(self): # 1 c = relay.expr.const(np.ones((2, 3, 4), dtype=np.float32)) net = relay.reshape(c, (4, 0, 2)) + net = relay.Tuple([net]) net = relay.Function([], net) mod = tvm.IRModule.from_expr(net) mod = relay.transform.InferType()(mod) @@ -188,6 +189,7 @@ def test_reshape(self): # 2 c = relay.expr.const(np.ones((2, 3, 4), dtype=np.float32)) net = relay.reshape(c, (6, 1, -1)) + net = relay.Tuple([net]) net = relay.Function([], net) mod = tvm.IRModule.from_expr(net) mod = relay.transform.InferType()(mod) @@ -201,6 +203,7 @@ def test_reshape(self): # 3 c = relay.expr.const(np.ones((2, 3, 4), dtype=np.float32)) net = relay.reshape(c, (-2,)) + net = relay.Tuple([net]) net = relay.Function([], net) mod = tvm.IRModule.from_expr(net) mod = relay.transform.InferType()(mod) @@ -214,6 +217,7 @@ def test_reshape(self): # 4 c = relay.expr.const(np.ones((2, 3, 4, 5), dtype=np.float32)) net = relay.reshape(c, (-3, -3)) + net = relay.Tuple([net]) net = relay.Function([], net) mod = tvm.IRModule.from_expr(net) mod = relay.transform.InferType()(mod) @@ -343,7 +347,7 @@ def test_transpose_constant(self): data = relay.var("data", relay.TensorType((1, 3, 2, 2), "float32")) net = relay.transpose(data, axes=(0, 2, 3, 1)) - + net = relay.Tuple([net]) net = relay.Function(relay.analysis.free_vars(net), net) mod = tvm.IRModule.from_expr(net) diff --git a/tests/unit/frontend/tvm/test_relay.py b/tests/unit/frontend/tvm/test_relay.py index 397787d..6c9943e 100644 --- a/tests/unit/frontend/tvm/test_relay.py +++ b/tests/unit/frontend/tvm/test_relay.py @@ -75,18 +75,17 @@ def test_simple_network(self): layers = xgraph.get_layers() - assert layers[0].type[0] == "Constant" - assert layers[1].type[0] == "Input" - assert layers[2].type[0] == "Pad" - assert layers[3].type[0] == "Convolution" - assert layers[4].type[0] == "BatchNorm" - assert layers[5].type[0] == "ReLU" - assert layers[6].type[0] == "Mean" - assert layers[7].type[0] == "Reshape" - assert layers[8].type[0] == "Dense" - assert layers[9].type[0] == "BiasAdd" - assert layers[10].type[0] == "Softmax" - assert layers[11].type[0] == "Reshape" + assert layers[0].type[0] == "Input" + assert layers[1].type[0] == "Pad" + assert layers[2].type[0] == "Convolution" + assert layers[3].type[0] == "BatchNorm" + assert layers[4].type[0] == "ReLU" + assert layers[5].type[0] == "Mean" + assert layers[6].type[0] == "Reshape" + assert layers[7].type[0] == "Dense" + assert layers[8].type[0] == "BiasAdd" + assert layers[9].type[0] == "Softmax" + assert layers[10].type[0] == "Reshape" @unittest.skipIf(skip, "Could not import TVM and/or TVM frontend") def test_simple_network_cvx(self): @@ -118,18 +117,18 @@ def test_simple_network_cvx(self): assert len(xgraph.get_input_names()) == 1 layers = xgraph.get_layers() - assert layers[0].type[0] == "Constant" - assert layers[1].type[0] == "StrInput" - assert layers[1].shapes == [-1] - assert layers[2].type[0] == "Cvx" - assert layers[2].shapes == [-1, 3, 224, 224] - assert layers[3].type[0] == "Pad" - assert layers[4].type[0] == "Convolution" - assert layers[5].type[0] == "ReLU" - - assert layers[1].tops == ["data_cvx"] - assert layers[2].bottoms == ["data"] - assert layers[2].tops[0][:7] == "nn.pad-" + # assert layers[0].type[0] == "Constant" + assert layers[0].type[0] == "StrInput" + assert layers[0].shapes == [-1] + assert layers[1].type[0] == "Cvx" + assert layers[1].shapes == [-1, 3, 224, 224] + assert layers[2].type[0] == "Pad" + assert layers[3].type[0] == "Convolution" + assert layers[4].type[0] == "ReLU" + + assert layers[0].tops == ["data_cvx"] + assert layers[1].bottoms == ["data"] + assert layers[1].tops[0][:7] == "nn.pad-" @unittest.skipIf(skip, "Could not import TVM and/or TVM frontend") def test_conv2d_transpose(self): diff --git a/tests/unit/frontend/tvm/test_relay_io.py b/tests/unit/frontend/tvm/test_relay_io.py index 7cc2515..ad9de2a 100644 --- a/tests/unit/frontend/tvm/test_relay_io.py +++ b/tests/unit/frontend/tvm/test_relay_io.py @@ -93,18 +93,17 @@ def test_simple_network(self): layers = xgraph.get_layers() - assert layers[0].type[0] == "Constant" - assert layers[1].type[0] == "Input" - assert layers[2].type[0] == "Pad" - assert layers[3].type[0] == "Convolution" - assert layers[4].type[0] == "BatchNorm" - assert layers[5].type[0] == "ReLU" - assert layers[6].type[0] == "Mean" - assert layers[7].type[0] == "Reshape" - assert layers[8].type[0] == "Dense" - assert layers[9].type[0] == "BiasAdd" - assert layers[10].type[0] == "Softmax" - assert layers[11].type[0] == "Reshape" + assert layers[0].type[0] == "Input" + assert layers[1].type[0] == "Pad" + assert layers[2].type[0] == "Convolution" + assert layers[3].type[0] == "BatchNorm" + assert layers[4].type[0] == "ReLU" + assert layers[5].type[0] == "Mean" + assert layers[6].type[0] == "Reshape" + assert layers[7].type[0] == "Dense" + assert layers[8].type[0] == "BiasAdd" + assert layers[9].type[0] == "Softmax" + assert layers[10].type[0] == "Reshape" os.remove(json_file) os.remove(params_file)