viiccwen opened a new pull request, #19975: URL: https://github.com/apache/tvm/pull/19975
ONNX integer Div uses truncating division, rounding toward zero. The Relax ONNX frontend already special-cased integer Div to detect zero divisors, but its PrimExpr folding path could still use NumPy floating-point division when one of the inputs was a shape-derived PrimExpr. That behavior can produce floating-point TIR values for integer shape/index computations. For example, a `Shape -> Gather -> Div -> Slice` subgraph can produce `T.float64(128.666...)` as a Slice bound, which Relax rejects because strided_slice expects integer PrimExpr bounds. This patch handles scalar integer Div inputs that contain a PrimExpr using TIR `truncdiv`, preserving ONNX semantics while keeping shape computations in TIR instead of routing them through NumPy. Constant tensor Div continues to use the existing generic binary constant-folding path. The regression tests cover: - integer constant folding with negative values to distinguish truncation from floor division - a shape-derived PrimExpr Div used as a Slice bound - integer zero-divisor error handling Verification: - `python -m pytest tests/python/relax/test_frontend_onnx.py::test_div_integer_constant_zero_divisor_raises_valueerror tests/python/relax/test_frontend_onnx.py::test_div_integer_constant_folding_truncates_toward_zero tests/python/relax/test_frontend_onnx.py::test_div_integer_primexpr_folding_truncates_toward_zero -q` Fixes #19974 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
