From ada7c6fece606f1f653ea7e16598d32922aecc4f Mon Sep 17 00:00:00 2001 From: rqg Date: Wed, 11 Jan 2023 11:35:36 +0800 Subject: [PATCH 1/5] fix: onnx Pad operator `constant_value` omit use default value 0 --- python/tvm/relay/frontend/onnx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index 328b5d7bd8d7..3a722bd8d91e 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -1942,7 +1942,7 @@ def _impl_v2(cls, inputs, attr, params): @classmethod def _impl_v11(cls, inputs, attr, params): pads = inputs[1] - if len(inputs) == 3: + if len(inputs) == 3 and inputs[2] is not None: value = fold_constant(_op.take(inputs[2], _op.const(0))) else: value = 0.0 From d16d89519fb6b025c7cda31cef8d241a1ed1f470 Mon Sep 17 00:00:00 2001 From: rqg Date: Wed, 11 Jan 2023 13:28:42 +0800 Subject: [PATCH 2/5] fix format problem --- python/tvm/relay/frontend/onnx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index 3a722bd8d91e..0afd9b173f20 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -1942,7 +1942,7 @@ def _impl_v2(cls, inputs, attr, params): @classmethod def _impl_v11(cls, inputs, attr, params): pads = inputs[1] - if len(inputs) == 3 and inputs[2] is not None: + if len(inputs) == 3 and inputs[2] is not None: value = fold_constant(_op.take(inputs[2], _op.const(0))) else: value = 0.0 From ec486ed08c6890894167e2b34c358de8dd31ee26 Mon Sep 17 00:00:00 2001 From: rqg Date: Thu, 12 Jan 2023 14:32:28 +0800 Subject: [PATCH 3/5] add onnx Pad unit test --- tests/python/frontend/onnx/test_forward.py | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 09206b341dd9..dfe99025fc97 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -7348,5 +7348,33 @@ def verify_sequence_ops(tensor_shape, num_tensors, axis=0, position=0, new_axis= verify_sequence_ops((3, 3, 3, 3), 4, axis=2, new_axis=1) +@tvm.testing.parametrize_targets +def test_pad_constant_value(target, dev): + """test_pad_constant_value""" + + def verify_pad_constant_value(constant_value): + tensor_shape = [1, 2, 257, 126] + tensor_values = [np.random.uniform(size=tensor_shape).astype("float32")] + graph_inputs = [helper.make_tensor_value_info("input", TensorProto.FLOAT, tensor_shape)] + graph_outputs = [helper.make_tensor_value_info("output", TensorProto.FLOAT, None)] + pads = helper.make_tensor("pads", TensorProto.INT64, [8], [0, 0, 0, 2, 0, 0, 0, 0]) + pad_node = helper.make_node("Pad", ["input", "pads", constant_value], ["output"], mode="constant") + graph_nodes = [pad_node] + graph = helper.make_graph( + graph_nodes, + "test_pad_constant_value", + inputs=graph_inputs, + outputs=graph_outputs, + initializer=[pads] + ) + model = helper.make_model( + graph, + producer_name="test_pad_constant_value", + ) + verify_with_ort_with_inputs(model, tensor_values, target=target, dev=dev) + + verify_pad_constant_value("") + + if __name__ == "__main__": tvm.testing.main() From 9c932561c3bbd0814d784308cdc65e32cc773355 Mon Sep 17 00:00:00 2001 From: rqg Date: Thu, 12 Jan 2023 15:37:49 +0800 Subject: [PATCH 4/5] fix python format --- tests/python/frontend/onnx/test_forward.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 467af678e9ff..a84de82f3bab 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -7708,14 +7708,16 @@ def verify_pad_constant_value(constant_value): graph_inputs = [helper.make_tensor_value_info("input", TensorProto.FLOAT, tensor_shape)] graph_outputs = [helper.make_tensor_value_info("output", TensorProto.FLOAT, None)] pads = helper.make_tensor("pads", TensorProto.INT64, [8], [0, 0, 0, 2, 0, 0, 0, 0]) - pad_node = helper.make_node("Pad", ["input", "pads", constant_value], ["output"], mode="constant") + pad_node = helper.make_node( + "Pad", ["input", "pads", constant_value], ["output"], mode="constant" + ) graph_nodes = [pad_node] graph = helper.make_graph( graph_nodes, "test_pad_constant_value", inputs=graph_inputs, outputs=graph_outputs, - initializer=[pads] + initializer=[pads], ) model = helper.make_model( graph, From c6be2eac05f7252adb70f13fe11515feef63d84a Mon Sep 17 00:00:00 2001 From: rqg Date: Sun, 29 Jan 2023 14:27:04 +0800 Subject: [PATCH 5/5] fix test `tests/node/websock_rpc_test.py` --- web/emcc/tvmjs_support.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/emcc/tvmjs_support.cc b/web/emcc/tvmjs_support.cc index aa9546f3b71a..6395bfbb08f4 100644 --- a/web/emcc/tvmjs_support.cc +++ b/web/emcc/tvmjs_support.cc @@ -162,7 +162,7 @@ class AsyncLocalSession : public LocalSession { // pass the callback as the last argument. setter(num_args, packed_callback); - auto* pf = static_cast(func); + auto* pf = static_cast(func); pf->CallPacked(TVMArgs(values.data(), type_codes.data(), num_args + 1), &temp); } else if (func == get_time_eval_placeholder_.get()) { // special handle time evaluator.