Skip to content

[Relax][ONNX] Accept 1-D scalar inputs in NonMaxSuppression#19843

Open
guan404ming wants to merge 1 commit into
apache:mainfrom
guan404ming:fix/onnx-nms-scalar-shape1
Open

[Relax][ONNX] Accept 1-D scalar inputs in NonMaxSuppression#19843
guan404ming wants to merge 1 commit into
apache:mainfrom
guan404ming:fix/onnx-nms-scalar-shape1

Conversation

@guan404ming

Copy link
Copy Markdown
Member

Related Issue

closes #19693

Why

NumPy 2.x raises TypeError on int(np.array([3])), so importing an ONNX NonMaxSuppression whose scalar params are 1-D single-element tensors (shape[1], common from exporters) crashed.

How

  • Cast the constant max_output_boxes_per_class / iou_threshold / score_threshold via .numpy().item(), which accepts both 0-D and 1-element tensors (matching the existing param-Var path).
  • Add an import test feeding 1-D scalar constants (the default folding path that the existing test_nms misses).

@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 use .numpy().item() instead of .numpy() when converting 1-D single-element constants to Python scalars, ensuring compatibility with NumPy 2.x. A test case has also been added to verify this behavior. The review feedback points out that iou_threshold is missing a relax.Var handling path in both _impl_v10 and _impl_v1 implementations, which could cause it to be silently ignored and overridden to its default value when provided as a variable.

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.

Comment thread python/tvm/relax/frontend/onnx/onnx_frontend.py
Comment thread python/tvm/relax/frontend/onnx/onnx_frontend.py
@guan404ming guan404ming force-pushed the fix/onnx-nms-scalar-shape1 branch from 79d747a to ddc4246 Compare June 19, 2026 16:29
@guan404ming guan404ming requested a review from tlopex June 19, 2026 16:30
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] NonMaxSuppression crashes on 1-D single-element scalar inputs (NumPy 2.x)

1 participant