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] Make the ONNX Importer More Static #7429

Merged
merged 6 commits into from
Feb 13, 2021

Conversation

mbrookhart
Copy link
Contributor

@mbrookhart mbrookhart commented Feb 9, 2021

We've been hitting a lot of issues in more complicated ONNX models where results of something like dynamic strided slice feed into an op like dynamic reshape, causing dynamic ranks to appear and crash the importer. To fix this, I decided it might be good to try to progagate constant information through the importer during import instead of trying to retroactively remove dynamic ops in a pass. To do that, I changed the freeze_params behavior of the importer to create constants before import, and made the importer fold constants through the importer as they are seen. Additionally, I edited the ops to only construct dynamic ops if the inputs are not constant.

In sum, this ends up creating many fewer dynamic ops in the ONNX importer, and so we see many fewer dynamic rank issues when importing models.

cc @masahi @jwfromm @electriclilies

@tmoreau89 found a serious performance regression on #7368, this change takes the import + dynamic_to_static of ONNX Bert Large from 20+ minutes to < 30s.

Copy link
Contributor

@electriclilies electriclilies left a comment

Choose a reason for hiding this comment

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

Overall, looks good to me -- I just left one comment about code style.

python/tvm/relay/frontend/onnx.py Outdated Show resolved Hide resolved
@mbrookhart mbrookhart changed the title [WIP][ONNX] Make the ONNX Importer More Static [ONNX] Make the ONNX Importer More Static Feb 12, 2021
@mbrookhart mbrookhart changed the title [ONNX] Make the ONNX Importer More Static [WIP][ONNX] Make the ONNX Importer More Static Feb 12, 2021
@mbrookhart mbrookhart changed the title [WIP][ONNX] Make the ONNX Importer More Static [ONNX] Make the ONNX Importer More Static Feb 12, 2021
@mbrookhart
Copy link
Contributor Author

@masahi @jwfromm @tmoreau89 I think this is ready for review

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

Really nice work @mbrookhart!!

@tmoreau89 tmoreau89 merged commit 4e211a7 into apache:main Feb 13, 2021
@tmoreau89
Copy link
Contributor

Thank you @mbrookhart @electriclilies @junrushao1994 the PR has been merged

Lokiiiiii pushed a commit to Lokiiiiii/tvm that referenced this pull request Mar 2, 2021
* Construct static Ops if inputs are Constant

* Expose FoldConstant as a function in addition to the pass

* refactor onnx importer to do more static imports by constant folding

fix pylint

* fix test regressions

* fix style, two bugs

* pipe freeze_params through sub_graphs when importing loops and control flow
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Mar 2, 2021
* Construct static Ops if inputs are Constant

* Expose FoldConstant as a function in addition to the pass

* refactor onnx importer to do more static imports by constant folding

fix pylint

* fix test regressions

* fix style, two bugs

* pipe freeze_params through sub_graphs when importing loops and control flow
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.

5 participants