Skip to content

[Fix][Relax][ONNX] Fix Range dtype for PrimExpr bounds#20000

Open
viiccwen wants to merge 2 commits into
apache:mainfrom
viiccwen:fix/onnx-range-primexpr-dtype
Open

[Fix][Relax][ONNX] Fix Range dtype for PrimExpr bounds#20000
viiccwen wants to merge 2 commits into
apache:mainfrom
viiccwen:fix/onnx-range-primexpr-dtype

Conversation

@viiccwen

Copy link
Copy Markdown
Contributor

The ONNX Range importer uses the dtype of the start value as the output dtype for relax.op.arange. The frontend previously passed start.ty.dtype, which is a PrimType wrapper rather than the underlying DataType expected by arange.

This patch passes the underlying dtype with start.ty.dtype.dtype.

The regression test covers a shape-derived bound produced by Shape -> Gather -> Range, and checks that the imported Relax IR contains R.arange(..., dtype="int64").

Verification:

  • python -m pytest tests/python/relax/test_frontend_onnx.py::test_range_with_primexpr_limit -q
  • pre-commit run --files python/tvm/relax/frontend/onnx/onnx_frontend.py tests/python/relax/test_frontend_onnx.py

Fixes #19999.

Signed-off-by: viiccwen <vicwen@apache.org>
@viiccwen viiccwen marked this pull request as ready for review July 14, 2026 04:03

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the ONNX frontend in TVM Relax to correctly extract the data type when handling the Range operator, changing start.ty.dtype to start.ty.dtype.dtype. It also adds a new unit test, test_range_with_primexpr_limit, to verify the behavior of the Range operator when the limit is a PrimExpr. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Signed-off-by: viiccwen <vicwen@apache.org>
@viiccwen

Copy link
Copy Markdown
Contributor Author

Looks like something wrong with Ruff, I add a small lint cleanup to fix it. 🤔

@viiccwen

Copy link
Copy Markdown
Contributor Author

cc @tlopex, @guan404ming. ✨🙌

Sign up for free to 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.

[Bug] Relax ONNX frontend passes PrimType wrapper as Range dtype for shape-derived bounds

1 participant