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 "guan404ming (via GitHub)" <gi...@apache.org> on 2026/06/19 16:00:38 UTC
[PR] [Relax][ONNX] Accept 1-D scalar inputs in NonMaxSuppression [tvm]
guan404ming opened a new pull request, #19843:
URL: https://github.com/apache/tvm/pull/19843
## 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).
--
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] [Relax][ONNX] Accept 1-D scalar inputs in NonMaxSuppression [tvm]
Posted by "cbalint13 (via GitHub)" <gi...@apache.org>.
cbalint13 merged PR #19843:
URL: https://github.com/apache/tvm/pull/19843
--
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] [Relax][ONNX] Accept 1-D scalar inputs in NonMaxSuppression [tvm]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #19843:
URL: https://github.com/apache/tvm/pull/19843#discussion_r3443639004
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -4927,12 +4927,12 @@ def _impl_v10(cls, bb, inputs, attr, params):
max_output_boxes_per_class = 0 # Default value
if iou_threshold is not None and isinstance(iou_threshold, relax.Constant):
- iou_threshold = float(iou_threshold.data.numpy())
+ iou_threshold = float(iou_threshold.data.numpy().item())
else:
iou_threshold = 0.5 # Default value
Review Comment:
fixed. Added the relax.Var path for iou_threshold to match the other params.
--
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] [Relax][ONNX] Accept 1-D scalar inputs in NonMaxSuppression [tvm]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #19843:
URL: https://github.com/apache/tvm/pull/19843#discussion_r3443639978
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -5016,12 +5016,12 @@ def _impl_v1(cls, bb, inputs, attr, params):
max_output_boxes_per_class = 0 # Default value
if iou_threshold is not None and isinstance(iou_threshold, relax.Constant):
- iou_threshold = float(iou_threshold.data.numpy())
+ iou_threshold = float(iou_threshold.data.numpy().item())
else:
iou_threshold = 0.5 # Default value
Review Comment:
Done, same fix applied here.
--
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] [Relax][ONNX] Accept 1-D scalar inputs in NonMaxSuppression [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19843:
URL: https://github.com/apache/tvm/pull/19843#discussion_r3443529311
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -4927,12 +4927,12 @@ def _impl_v10(cls, bb, inputs, attr, params):
max_output_boxes_per_class = 0 # Default value
if iou_threshold is not None and isinstance(iou_threshold, relax.Constant):
- iou_threshold = float(iou_threshold.data.numpy())
+ iou_threshold = float(iou_threshold.data.numpy().item())
else:
iou_threshold = 0.5 # Default value
Review Comment:

The `iou_threshold` parameter is missing a `relax.Var` handling path, unlike `max_output_boxes_per_class` and `score_threshold`. If `iou_threshold` is provided as a `relax.Var` (for example, when `keep_params_in_input=True`), it will be silently ignored and overridden to the default value of `0.5`. We should add the `relax.Var` path to resolve it from `params` to ensure correctness and consistency.
```python
if iou_threshold is not None and isinstance(iou_threshold, relax.Constant):
iou_threshold = float(iou_threshold.data.numpy().item())
elif iou_threshold is not None and isinstance(iou_threshold, relax.Var):
var_name = iou_threshold.name_hint
if var_name in params[1]:
_, param_value = params[1][var_name]
iou_threshold = float(param_value.numpy().item())
else:
iou_threshold = 0.5 # Default value
else:
iou_threshold = 0.5 # Default value
```
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -5016,12 +5016,12 @@ def _impl_v1(cls, bb, inputs, attr, params):
max_output_boxes_per_class = 0 # Default value
if iou_threshold is not None and isinstance(iou_threshold, relax.Constant):
- iou_threshold = float(iou_threshold.data.numpy())
+ iou_threshold = float(iou_threshold.data.numpy().item())
else:
iou_threshold = 0.5 # Default value
Review Comment:

Similarly, in `AllClassNMS._impl_v1`, the `iou_threshold` parameter is missing a `relax.Var` handling path. We should add the `relax.Var` path here as well to resolve it from `params` for correctness and consistency.
```python
if iou_threshold is not None and isinstance(iou_threshold, relax.Constant):
iou_threshold = float(iou_threshold.data.numpy().item())
elif iou_threshold is not None and isinstance(iou_threshold, relax.Var):
var_name = iou_threshold.name_hint
if var_name in params[1]:
_, param_value = params[1][var_name]
iou_threshold = float(param_value.numpy().item())
else:
iou_threshold = 0.5 # Default value
else:
iou_threshold = 0.5 # Default value
```
--
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