[Bug] [Relax][ONNX] Min import fails on symbolic broadcast
- Dominant language
- Python
- Stars
- 13.7k
- Forks
- 4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 112
Description
### Expected behavior
The Relax ONNX frontend should import a valid ONNX Min with symbolic input shapes.
### Actual behavior
The script constructs a valid ONNX model. `onnx.checker.check_model` and ONNX Runtime session construction succeed. `from_onnx` fails while converting `Min`:
```text
Error converting operator Min, with inputs: [x, y]
Traceback (most recent call last):
...
File ".../python/tvm/relax/frontend/onnx/onnx_frontend.py", line 2420, in compute_broadcast_shape
target.append(max(ai, bi))
...
ValueError: Cannot use and / or / not operator to Expr, hint: use tvm.tirx.all / tvm.tirx.any, if it is None checking, use node is not None
```
### Environment
* OS: macOS 15.6 (Darwin 24.6.0, arm64)
* Python: 3.12.2
* TVM: c7b458e946bc4266915da582457476bdcd9705ae (tag v0.26.0; package reports 0.26.dev0)
* ONNX: 1.17.0
* ONNX Runtime: 1.21.1
* Frontend: `tvm.relax.frontend.onnx.from_onnx`
### Steps to reproduce
The following self-contained script constructs the model:
```python
#!/usr/bin/env python3
"""Reproduce the Relax ONNX symbolic-broadcast Min import failure."""
import onnx
import onnxruntime as ort
from onnx import TensorProto, helper
from tvm.relax.frontend.onnx import from_onnx
def main() -> None:
x = helper.make_tensor_value_info("x", TensorProto.FLOAT, ["n", 4])
y = helper.make_tensor_value_info("y", TensorProto.FLOAT, ["n", 4])
out = helper.make_tensor_value_info("out", TensorProto.FLOAT, ["n", 4])
graph = helper.make_graph(
[helper.make_node("Min", ["x", "y"], ["out"])],
"min_symbolic_broadcast",
[x, y],
[out],
)
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 18)])
onnx.checker.check_model(model)
ort.InferenceSession(model.SerializeToString(), providers=["CPUExecutionProvider"])
from_onnx(model, opset=18, keep_params_in_input=True)
if __name__ == "__main__":
main()
```
### Analysis
`compute_broadcast_shape` uses Python `max` and boolean logic on input dimensions. When a dimension is a symbolic `tirx.Expr`, Python boolean conversion raises before a Relax graph is produced.
### Triage
* needs-triage
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the self-contained reproduction and inspect compute_broadcast_shape in python/tvm/relax/frontend/onnx/onnx_frontend.py around line 2420, reached through tvm.relax.frontend.onnx.from_onnx. Done means the symbolic-shape Min model imports successfully without the Python Expr boolean-conversion error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100