Skip to content

[ONNX] Make the ONNX Importer More Static - #7429

Merged
tmoreau89 merged 6 commits into
apache:mainfrom
mbrookhart:more_static_onnx_importer
Feb 13, 2021
Merged

[ONNX] Make the ONNX Importer More Static#7429
tmoreau89 merged 6 commits into
apache:mainfrom
mbrookhart:more_static_onnx_importer

Conversation

@mbrookhart

@mbrookhartmbrookhart commented Feb 9, 2021

Copy link
Copy Markdown
Contributor

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.

@mbrookhart
mbrookhartforce-pushed the more_static_onnx_importer branch from 9303222 to 52f09eeCompareFebruary 9, 2021 21:25
@mbrookhart
mbrookhartforce-pushed the more_static_onnx_importer branch from 70894a1 to 6e7b71cCompareFebruary 10, 2021 20:40

@electriclilieselectriclilies left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadpython/tvm/relay/frontend/onnx.py Outdated
@mbrookhart
mbrookhartforce-pushed the more_static_onnx_importer branch from 6e7b71c to 9c2c5a6CompareFebruary 12, 2021 18:03
@mbrookhartmbrookhart changed the title [WIP][ONNX] Make the ONNX Importer More Static[ONNX] Make the ONNX Importer More StaticFeb 12, 2021
@mbrookhartmbrookhart changed the title [ONNX] Make the ONNX Importer More Static[WIP][ONNX] Make the ONNX Importer More StaticFeb 12, 2021
@mbrookhartmbrookhart changed the title [WIP][ONNX] Make the ONNX Importer More Static[ONNX] Make the ONNX Importer More StaticFeb 12, 2021
@mbrookhart

Copy link
Copy Markdown
ContributorAuthor

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

@junrushaojunrushao left a comment

Copy link
Copy Markdown
Member

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:mainFeb 13, 2021
@tmoreau89

Copy link
Copy Markdown
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 freeto 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

@mbrookhart@tmoreau89@electriclilies@junrushao@jwfromm