Repository navigation
Rewriter: keep Reshape allowzero valid when materializing the shape - #3119
Open
ni (nniiovoo) wants to merge 1 commit into
Open
ni (nniiovoo) wants to merge 1 commit into
ni (nniiovoo) wants to merge 1 commit into
Conversation
MaterializeReshapeShape always emitted Reshape with allowzero=1. The attribute only exists from opset 14, so optimize() turned valid opset-13 models into models onnxruntime rejects. Keep the original allowzero and set allowzero=1 only when a materialized dim is 0. Skip the rewrite when that is not possible: before opset 14, or when the 0 dim comes with a -1. Signed-off-by: NNIIOVO <haimingni44@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3118
MaterializeReshapeShapealways emittedReshape(..., allowzero=1).allowzeroonly exists from opset 14, sooptimize()turned valid opset-13 models into models onnxruntime rejects ("Unrecognized attribute: allowzero").The rule now keeps the original
allowzero(including a reference to a function attribute) and setsallowzero=1only when a materialized dim is actually 0. For a shape with a 0 dim, it skips the rewrite before opset 14, or when the new shape would also contain-1, whichallowzero=1does not allow.Added tests for opset 13, 0 dims and a referenced
allowzero. They fail on main and pass with the fix. The existing tests, includingtest_allowzero_attribute_preserved, still pass.