Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONNX] Support optional outputs for ONNX nodes #7818

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3202,6 +3202,24 @@ def from_onnx(self, graph, opset, get_output_expr=False):
outputs_num = 1
else:
outputs_num = len(op)
if outputs_num > 1:
valid_outputs = [False] * outputs_num
for i in range(len(node_output)):
if node_output[i] != "":
valid_outputs[i] = True
if not all(valid_outputs):
tup = op.astuple()
if isinstance(tup, _expr.Tuple):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does op.astuple not always return an _expr.Tuple?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we use TupleWrapper for other nodes, like call nodes with multiple outputs, see split:

return TupleWrapper(_make.split(data, indices_or_sections, axis), ret_size)

outputs = [tup.fields[i] for i, valid in enumerate(valid_outputs) if valid]
else:
outputs = [op[i] for i, valid in enumerate(valid_outputs) if valid]

if len(outputs) == 1:
op = outputs[0]
else:
op = _expr.TupleWrapper(outputs, len(outputs))
outputs_num = len(outputs)
node_output = [output for output in node_output if output != ""]
assert (
len(node_output) == outputs_num
), "Number of output mismatch {} vs {} in {}.".format(
Expand Down
6 changes: 0 additions & 6 deletions tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -4138,9 +4138,6 @@ def verify_cumsum(indata, axis, exclusive=0, reverse=0, type="float32"):
unsupported_onnx_tests = [
"test_basic_convinteger/",
"test_cast_DOUBLE_to_FLOAT16/",
"test_cast_FLOAT16_to_DOUBLE/",
"test_cast_FLOAT16_to_FLOAT/",
"test_cast_FLOAT_to_FLOAT16/",
"test_cast_FLOAT_to_STRING/",
"test_cast_STRING_to_FLOAT/",
"test_compress_0/",
Expand Down Expand Up @@ -4171,9 +4168,6 @@ def verify_cumsum(indata, axis, exclusive=0, reverse=0, type="float32"):
"test_hardmax_one_hot/",
"test_isinf_negative/",
"test_isinf_positive/",
"test_lstm_defaults/",
"test_lstm_with_initial_bias/",
"test_lstm_with_peepholes/",
"test_matmulinteger/",
"test_maxpool_2d_dilations/",
"test_maxpool_2d_same_lower/",
Expand Down