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] Handle multiple imports #13065

Merged
merged 2 commits into from
Oct 17, 2022

Conversation

AndrewZhaoLuo
Copy link
Contributor

Ref: https://github.com/onnx/onnx/blob/main/docs/IR.md

Right now we take the first imported op set as the operator version for rest of conversion. This assumes the first imported op set is the default (ai.onnx), however this is not necessarily the case.

In the future, we need to support multiple operator sets well (see #10950). For now, we just try to find the default (ai.onnx) namespace and use that for the opset version.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Oct 13, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: onnx See #10317 for details
  • Built docs for commit e4a0c87 can be found here.

Generated by tvm-bot

@AndrewZhaoLuo
Copy link
Contributor Author

cc @sfvaroglu

@AndrewZhaoLuo
Copy link
Contributor Author

@jwfromm

Copy link
Contributor

@jwfromm jwfromm left a comment

Choose a reason for hiding this comment

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

This is a good starting point, thanks @AndrewZhaoLuo!

for opset_identifier in model.opset_import:
# As per https://github.com/onnx/onnx/blob/main/docs/IR.md
# All operator sets except the default one must specify the operator version
if str(opset_identifier.name) in ["ai.onnx", ""]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if its inconsistent but the models I'm looking at use opset_identifer.domain rather than name. Also, it seems like if there is only one import there is no domain name, just the version and its assumed the domain is ai.onnx. This is at least the case for resnet50-v1-7 which is used in the tests.

Copy link
Contributor Author

@AndrewZhaoLuo AndrewZhaoLuo Oct 14, 2022

Choose a reason for hiding this comment

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

It should be domain yeah, fixed.

for opset_identifier in model.opset_import:
# As per https://github.com/onnx/onnx/blob/main/docs/IR.md
# All operator sets except the default one must specify the operator version
if str(opset_identifier.domain) in ["ai.onnx", ""]:
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 this will still run into some issues. When there is only one opset_import, it doesnt have a domain name, just a version. We'll need to add a special case when the length of model.opset_import is 1 and just pull out the version directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean opset_identifier won't have the attribute "domain", or that it will return the empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be an earlier ONNX spec which we do not support.

Copy link
Contributor

Choose a reason for hiding this comment

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

It returns an empty string despite having a version that needs to be respected. If we dont handle this case we'll fail the import_model test.

Copy link
Contributor Author

@AndrewZhaoLuo AndrewZhaoLuo Oct 14, 2022

Choose a reason for hiding this comment

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

Hmm in the code, it should be fine with the "" (we check if the string is "" or ai.onnx), I'll investigate this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test fail was due to known error #13067.

@AndrewZhaoLuo
Copy link
Contributor Author

@tvm-bot rerun

@AndrewZhaoLuo
Copy link
Contributor Author

PTAL @jwfromm

@AndrewZhaoLuo AndrewZhaoLuo force-pushed the aluo/onnx-fix-namespaces branch from 1e29caa to e4a0c87 Compare October 14, 2022 22:21
@jwfromm
Copy link
Contributor

jwfromm commented Oct 17, 2022

LGTM, thank you @AndrewZhaoLuo

@jwfromm jwfromm merged commit c14f5e1 into apache:main Oct 17, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
* onnx get right import

* fixins
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
* onnx get right import

* fixins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants