Skip to content

Rewriter: keep Reshape allowzero valid when materializing the shape - #3119

Open
ni (nniiovoo) wants to merge 1 commit into
microsoft:mainfrom
nniiovoo:fix/materialize-reshape-allowzero
Open

ni (nniiovoo) wants to merge 1 commit into
microsoft:mainfrom
nniiovoo:fix/materialize-reshape-allowzero

Conversation

@nniiovoo

Copy link
Copy Markdown

Fixes #3118

MaterializeReshapeShape always emitted Reshape(..., allowzero=1). allowzero only exists from opset 14, so optimize() 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 sets allowzero=1 only 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, which allowzero=1 does 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, including test_allowzero_attribute_preserved, still pass.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

optimize() adds allowzero to Reshape in opset 13 models

1 participant