You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tandede (via GitHub)" <gi...@apache.org> on 2026/08/19 18:46:44 UTC

[PR] [Fix][Relax] Honor ONNX Reshape zero semantics [tvm]

tandede opened a new pull request, #20161:
URL: https://github.com/apache/tvm/pull/20161

   ONNX Reshape uses zero entries to copy the corresponding input dimension by default. The Relax importer currently constant-folds those shapes through NumPy without applying that rule, so a valid shape such as `[0, 3]` fails for a `(2, 3)` tensor. Conversely, when `allowzero=1`, passing the zero through `relax.op.reshape` invokes Relax's own zero-copy convention instead of preserving the literal zero dimension.
   
   This change normalizes copied dimensions before constant folding when `allowzero` is disabled. When it is enabled, the shape tensor is materialized as a symbolic `ShapeExpr`, preserving literal zero dimensions without applying Relax's zero-copy shortcut.
   
   The regression tests cover both the default all-constant path and an executable `allowzero=1` model with a `(0, 2)` output.
   
   Fixes #20151
   
   Testing:
   
   ```
   pre-commit run --files python/tvm/relax/frontend/onnx/onnx_frontend.py tests/python/relax/test_frontend_onnx.py
   pytest -q tests/python/relax/test_frontend_onnx.py -k reshape
   pytest -q -n 4 tests/python/relax/test_frontend_onnx.py -k 'not test_clip_v13'
   ```
   
   The first two commands pass, and the broad run reports 493 passed, 9 skipped, and 4 xfailed. Running the entire file also reports three `test_clip_v13` failures that reproduce unchanged on a clean `main` worktree in the same environment.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Fix][Relax] Honor ONNX Reshape zero semantics [tvm]

Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #20161:
URL: https://github.com/apache/tvm/pull/20161#issuecomment-5390846594

   Thanks LGTM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Fix][Relax] Honor ONNX Reshape zero semantics [tvm]

Posted by "tandede (via GitHub)" <gi...@apache.org>.
tandede commented on PR #20161:
URL: https://github.com/apache/tvm/pull/20161#issuecomment-5384301096

   > allowzero only changes zero semantics, but this branch also bypasses -1 inference. A valid non-constant (3, 4) input with shape [-1, 2] and allowzero=1 reaches runtime with a literal -1 and fails with std::bad_alloc. Please keep the normal reshape path when no literal zero is present and add a regression test.
   
   Thanks for catching this. You’re right that `allowzero` should only change the interpretation when the target shape actually contains a literal zero; it should not bypass normal `-1` inference.
   
   I narrowed the special path to constant target shapes containing zero. With `allowzero=1` and `[-1, 2]`, a non-constant `(3, 4)` input now follows the normal reshape path and produces `(6, 2)`.
   
   I added the requested regression test and pushed the update in d20b94e. All five Reshape-related tests and the changed-file pre-commit checks pass.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Fix][Relax] Honor ONNX Reshape zero semantics [tvm]

Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #20161:
URL: https://github.com/apache/tvm/pull/20161


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org