The GitHub Actions job "Lint" on tvm.git/main has succeeded.
Run started by GitHub user tlopex (triggered by tlopex).

Head commit for run:
c7a5f4f388b3680da7a9289847e2e269e16a1235 / Jeremy Schoemaker 
<[email protected]>
[Fix][Relax][ONNX] Correct fmod mapping in Mod constant folding (#20170)

The Mod converter
(python/tvm/relax/frontend/onnx/onnx_frontend.py:730-736 on main)
assigns `numpy_op` with the two conventions swapped: `fmod=0` (integer
mod, sign follows divisor per the ONNX spec) folds with `np.fmod`, and
`fmod=1` (C fmod, sign follows dividend) folds with `np.mod`. The
runtime path is correct (`floor_mod` for `fmod=0`, `mod` for `fmod=1`),
so the bug fires exactly when both operands are constants or
initializers and `BinaryBase.base_impl` folds the result at import time,
e.g. shape-arithmetic subgraphs. `Mod(-5, 3)` with `fmod=0` bakes
`R.const(-2)` into the graph where onnxruntime returns 1; `Mod(-5.5,
3.0)` with `fmod=1` folds to 0.5 where onnxruntime returns -2.5.

The suite could not catch this: the numpy reference in
`verify_binary_scalar` (tests/python/relax/test_frontend_onnx.py:365 on
main) encoded the identical swap, and the only folded value exercised
was 4 mod 8, where both conventions agree.

This is a reintroduction of a fixed bug: #6160 corrected this exact
fmod=0/fmod=1 mapping in the old Relay ONNX frontend (issue #6106); the
Relax frontend brought it back in the numpy constant-fold path.

Changes:
- Swap the assignments so `fmod=0` pairs `np.mod` with
`relax.op.floor_mod` and `fmod=1` pairs `np.fmod` with `relax.op.mod`.
- Correct the inverted test reference in `verify_binary_scalar`.
- Add `test_mod_constant_fold_negative_operands`: Mod over two constant
tensors with negative operands (int32 fmod=0, int32 fmod=1, float32
fmod=1), folded at import and checked against onnxruntime. All three
cases fail before the fix and pass after; the full ONNX frontend test
file shows no other delta.

Not changed: the dead class-level defaults on `Mod` (`numpy_op =
_np.mod` / `relax_op = relax.op.mod`), which `_impl_v10` always
overwrites since ONNX Mod only exists from opset 10.

Report URL: https://github.com/apache/tvm/actions/runs/33149613413

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to