Skip to content

Conversation

liqunfu
Copy link
Collaborator

@liqunfu liqunfu commented Aug 8, 2022

Description
to extend OptionalHasElement and OptionalGetElement to accept tensor and sequence types

Motivation and Context
Before the 2 optional ops only accept optional types. This limits its use in cases where input can be both optional and other types. This PR generalizes the 2 ops so it become more flexible.

liqunfu added 2 commits August 8, 2022 15:04
… sequence types

Signed-off-by: Liqun Fu <liqfu@microsoft.com>
Signed-off-by: Liqun Fu <liqfu@microsoft.com>
@liqunfu liqunfu requested review from a team as code owners August 8, 2022 22:21
Signed-off-by: Liqun Fu <liqfu@microsoft.com>
@liqunfu liqunfu added the topic: operator Issues related to ONNX operators label Aug 8, 2022
input_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto)
node = onnx.helper.make_node(
'OptionalHasElement',
inputs=['optional_input'],
Copy link
Contributor

@gramalingam gramalingam Aug 9, 2022

Choose a reason for hiding this comment

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

Another test-case where inputs=[] or input=[''] would be useful.

How about test-cases for optional_get_element?

OpSchema()
.SetDoc(OptionalHasElement_ver1_doc)
.SetDoc(OptionalHasElement_ver18_doc)
.Input(0, "input", "The optional input.", "O")
Copy link
Contributor

Choose a reason for hiding this comment

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

The input should be made into an optional input.

Signed-off-by: Liqun Fu <liqfu@microsoft.com>
Signed-off-by: Liqun Fu <liqfu@microsoft.com>
@@ -48,6 +48,8 @@ def prepare_dir(path: str) -> None:
output_dir, f'test_data_set_{i}')
prepare_dir(data_set_dir)
for j, input in enumerate(inputs):
if input is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Trying to understand this: this file is about model inputs/outputs, right, and not about node/op inputs/outputs. For model inputs/outputs there is no possibility of optional-input/output of kind 1 (static), right? I don't understand why this is being triggered. (May be some fix in the model-generator is required if it is adding an unnecessary model-input?)

Copy link
Contributor

Choose a reason for hiding this comment

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

I am worried things will break if a model has an input X, and there is no corresponding input-file in the test-folder.

# OptionalHasElement takes a tensor or optional as input
for input_type_proto in [tensor_type_proto, optional_type_proto]:
input_name_options = {
'empty': 'optional_input',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the combination of input_type_proto == tensor_type_proto and above ('empty': 'optional_input') is not a valid combination to test? That might also be triggering the change to cmd_tools.py below?

…input

Signed-off-by: Liqun Fu <liqfu@microsoft.com>
Signed-off-by: Liqun Fu <liqfu@microsoft.com>
Signed-off-by: Liqun Fu <liqfu@microsoft.com>
if sys.byteorder == "big":
# Convert endian from big to little
convert_endian(tensor)
if arr is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change still required (after eliminating that test-case)? Wondering why this change is needed.

Signed-off-by: Liqun Fu <liqfu@microsoft.com>
Signed-off-by: Liqun Fu <liqfu@microsoft.com>
Copy link
Contributor

@gramalingam gramalingam left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@liqunfu liqunfu enabled auto-merge (squash) August 15, 2022 21:20
@liqunfu liqunfu merged commit a5e72dc into onnx:main Aug 16, 2022
broune pushed a commit to broune/onnx that referenced this pull request May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: operator Issues related to ONNX operators
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants