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 "viiccwen (via GitHub)" <gi...@apache.org> on 2026/07/14 04:10:38 UTC
[PR] [Fix][Relax][ONNX] Recover ConstantOfShape initializer shape [tvm]
viiccwen opened a new pull request, #20002:
URL: https://github.com/apache/tvm/pull/20002
`ConstantOfShape` uses its input tensor as shape metadata. When that input is an initializer and `keep_params_in_input=True`, the Relax ONNX frontend should recover the initializer value from `params` instead of treating the input as an opaque runtime value.
This patch applies `get_constant` to the `ConstantOfShape` shape input before shape handling. It also guards the constant-shape folding path so it only calls `len(shape)` on `relax.ShapeExpr` values.
The regression test covers an initializer-backed shape input imported with `keep_params_in_input=True` and checks that the resulting Relax function has the expected output shape and dtype.
A separate lint follow-up commit removes stale `F821` suppressions from two DLight files so the repository-wide CI lint is clean.
Verification:
- `python -m pytest tests/python/relax/test_frontend_onnx.py::test_constantofshape_initializer_shape_with_keep_params_in_input -q`
- `pre-commit run --all-files`
Fixes #20001.
--
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][ONNX] Recover ConstantOfShape initializer shape [tvm]
Posted by "viiccwen (via GitHub)" <gi...@apache.org>.
viiccwen commented on code in PR #20002:
URL: https://github.com/apache/tvm/pull/20002#discussion_r3575977625
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2138,7 +2138,11 @@ def _impl_v9(cls, bb, inputs, attr, params):
shape = relax.ShapeExpr(list(shape.data.numpy()))
# Special case where requested shape are constant
- if len(shape) == 1 and all([isinstance(x, tirx.IntImm) for x in shape]):
+ if (
+ isinstance(shape, relax.ShapeExpr)
+ and len(shape) == 1
+ and all([isinstance(x, tirx.IntImm) for x in shape])
+ ):
Review Comment:
Yeah, It's correct, I'll fix it.
--
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][ONNX] Recover ConstantOfShape initializer shape [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #20002:
URL: https://github.com/apache/tvm/pull/20002
--
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][ONNX] Recover ConstantOfShape initializer shape [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #20002:
URL: https://github.com/apache/tvm/pull/20002#discussion_r3575965102
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2138,7 +2138,11 @@ def _impl_v9(cls, bb, inputs, attr, params):
shape = relax.ShapeExpr(list(shape.data.numpy()))
# Special case where requested shape are constant
- if len(shape) == 1 and all([isinstance(x, tirx.IntImm) for x in shape]):
+ if (
+ isinstance(shape, relax.ShapeExpr)
+ and len(shape) == 1
+ and all([isinstance(x, tirx.IntImm) for x in shape])
+ ):
Review Comment:

Using a list comprehension inside `all()` creates a temporary list in memory before evaluating. We can optimize this by using a generator expression instead, which allows short-circuiting and avoids unnecessary memory allocation.
```suggestion
if (
isinstance(shape, relax.ShapeExpr)
and len(shape) == 1
and all(isinstance(x, tirx.IntImm) for x in shape)
):
```
--
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