Expected behavior
The Relax ONNX frontend should preserve ONNX integer Div semantics. ONNX defines integer Div as truncating division, rounding toward zero.
This behavior should hold both for constant tensors and for shape-derived scalar values represented as Relax/TIR primitive expressions.
Actual behavior
When an ONNX Div has integer inputs and one input is a shape-derived PrimExpr, the importer can fold it through NumPy floating-point division. This produces a floating-point TIR value such as T.float64(128.67676767) instead of an integer value such as T.int64(128).
If that result is then used as a slice bound or another index value, Relax import can fail because the downstream operator expects an integer primitive expression.
One failing pattern is:
Shape -> Gather -> Div -> Slice
where the Div result is used as the end argument of Slice.
Environment
- Component: Relax ONNX frontend
- Affected file:
python/tvm/relax/frontend/onnx/onnx_frontend.py
- Reproduced with a local TVM checkout using the Python ONNX frontend tests
Steps to reproduce
Create a graph where Shape(x)[0] is divided by an int64 constant and used as a
Slice bound:
x: float32[386]
Shape(x) -> Gather(axis=0) -> Div(3) -> Slice(x, starts=[0], ends=[Div result])
The importer may fail with an error similar to:
relax.strided_slice requires the end argument to be a tuple of int64 PrimExpr values
...
the end argument (T.float64(128.66666666666666),) has type T.Tuple(T.float64)
Expected behavior
The Relax ONNX frontend should preserve ONNX integer
Divsemantics. ONNX defines integerDivas truncating division, rounding toward zero.This behavior should hold both for constant tensors and for shape-derived scalar values represented as Relax/TIR primitive expressions.
Actual behavior
When an ONNX
Divhas integer inputs and one input is a shape-derivedPrimExpr, the importer can fold it through NumPy floating-point division. This produces a floating-point TIR value such asT.float64(128.67676767)instead of an integer value such asT.int64(128).If that result is then used as a slice bound or another index value, Relax import can fail because the downstream operator expects an integer primitive expression.
One failing pattern is:
where the
Divresult is used as theendargument ofSlice.Environment
python/tvm/relax/frontend/onnx/onnx_frontend.pySteps to reproduce
Create a graph where
Shape(x)[0]is divided by anint64constant and used as aSlicebound:The importer may fail with an error similar to: