Irfanuet191 opened a new pull request, #20123: URL: https://github.com/apache/tvm/pull/20123
Fixes #20065. ## Problem `BinaryBase.base_impl` folds scalar operands with numpy, but when an operand is a symbolic PrimExpr (e.g. a dynamic dimension gathered out of a `Shape` result), the numpy ufunc dispatches through object dtype: - comparison ufuncs (`Less`/`LessOrEqual`/`Greater`/`GreaterOrEqual`) coerce the resulting PrimExpr through `bool()`, which PrimExpr forbids → `ValueError: Cannot use and / or / not operator to Expr` - logical `And`/`Or`/`Xor` evaluate `bool()` on the operands → same `ValueError` - `Pow` has no PrimExpr overload → `TypeError`; `Mod` fails the same way - older releases crashed in `Sub` with `AttributeError: 'Sub' object has no attribute 'item'` — the crash reported in the issue (current main only avoids this for plain arithmetic thanks to the `hasattr(output, "item")` guard) Minimal reproducer (any binary op on two shape-derived dims of a dynamic-shaped input): Shape(x) -> Gather(idx 0) -> d0 Shape(x) -> Gather(idx 1) -> d1 Less(d0, d1) # or And/Or/Xor/Pow/Mod, and Sub on released versions ## Fix Route symbolic scalar operands around numpy instead of relying on object-dtype dispatch: each `BinaryBase` subclass declares a `prim_op` that builds the scalar PrimExpr directly (`operator.sub`, `tirx.div`, `tirx.flr.lt`, ...), and `base_impl` wraps the result in `relax.prim_value`. Fully concrete operands keep the existing Additional changes required to make the whole binary family sy - promote `Div`'s private scalar-conversion helper to module-lnd reuse it - compute integer `Pow` in float64 and cast back, since `tirx.ct for dimension-sized integers) - map `Xor` to `tirx.bitwise_xor` (bitwise xor on bool operandn `i1` produces an invalid `fcmp` during LLVM codegen) - make `BitwiseBase` dtype validation accept PrimExpr operandsypes ## Testing - New regression tests in `tests/python/relax/test_frontend_onMul/Div/Mod/Less/LessOrEqual/Greater/GreaterOrEqual on two shape-derived symbolic dims (verified against onnxruntime), ched with scalar constants, And/Or/Xor over symbolic comparisons, and an import check for integer Pow. - Full `tests/python/relax/test_frontend_onnx.py`: 499 passed,ures. - `ruff check` and `ruff format --check` clean on both files. -- 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]
