From d8833bdbbe48c8dedd23875aeeb80a8374eb151d Mon Sep 17 00:00:00 2001 From: Valery Chernov Date: Tue, 31 Jan 2023 15:48:13 +0400 Subject: [PATCH] [ONNX] Support SequenceEmpty op (#13866) * add SequenceEmpty * add SequenceEmpty test * pylint fix --------- Co-authored-by: Valery Chernov --- python/tvm/relay/frontend/onnx.py | 10 +++++++ tests/python/frontend/onnx/test_forward.py | 32 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index 93429a863889..8b4a0cc5e8d3 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -6148,6 +6148,15 @@ def _impl_v11(cls, inputs, attr, params): return _expr.Tuple(inputs) +class SequenceEmpty(OnnxOpConverter): + """Operator converter for sequence empty op.""" + + @classmethod + def _impl_v11(cls, inputs, attr, params): + # Construct an empty tuple. + return _expr.Tuple([]) + + class SequenceErase(OnnxOpConverter): """Operator converter for sequence erase op.""" @@ -6523,6 +6532,7 @@ def _get_convert_map(opset): "LinearRegressor": LinearRegressor.get_converter(opset), # Sequence operators "SequenceConstruct": SequenceConstruct.get_converter(opset), + "SequenceEmpty": SequenceEmpty.get_converter(opset), "SequenceErase": SequenceErase.get_converter(opset), "SequenceInsert": SequenceInsert.get_converter(opset), "SequenceLength": SequenceLength.get_converter(opset), diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 3e1af4086784..dd172d1ddea6 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -7829,6 +7829,38 @@ 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_empty_sequence(target, dev): + """test_empty_sequence""" + + # Test creating an empty tensor sequence. + empty_node = helper.make_node( + "SequenceEmpty", + inputs=[], + outputs=["empty_sequence"], + ) + + length_node = helper.make_node("SequenceLength", inputs=["empty_sequence"], outputs=["output"]) + + graph_outputs = [helper.make_tensor_value_info("output", TensorProto.INT64, [])] + + graph_nodes = [empty_node, length_node] + + graph = helper.make_graph( + graph_nodes, + "Sequence_empty_test", + inputs=[], + outputs=graph_outputs, + ) + + model = helper.make_model( + graph, + producer_name="Sequence_empty_test", + ) + + verify_with_ort_with_inputs(model, [], target=target, dev=dev) + + def test_exporting_node_renamed_model(): """test exproting model when export_node_renamed_model is set"""