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

Head commit for run:
acfc4837389323f952feabe602f10e665f3dd59e / Soowon Jeong <[email protected]>
[BugFix][ONNX] Fix Round op to use ties-to-even (#19367)

## Problem

The ONNX `Round` operator specification requires **ties-to-even**
(banker's) rounding:

> "For cases where number is exactly halfway between two integers, it
rounds to the nearest even integer."
> — https://onnx.ai/onnx/operators/onnx__Round.html

However, the current TVM implementation produces **ties-away-from-zero**
results on midpoint values:

| Input | Expected (ties-to-even) | Actual (ties-away) |
|-------|------------------------|--------------------|
| 0.5   | 0.0                    | 1.0                |
| 1.5   | 2.0                    | 2.0                |
| 2.5   | 2.0                    | 3.0                |
| -0.5  | 0.0                    | -1.0               |
| -2.5  | -2.0                   | -3.0               |

This was reported in issue #18590.

## Root Cause

The lowering chain for `relax.op.round`:

```
relax.op.round -> (LegalizeOps) -> topi.round() -> te.round -> tir.round -> 
llvm::round
```

`llvm::round` is defined as ties-away-from-zero (C99 `round()`), while
`llvm::nearbyint` uses the IEEE 754 default rounding mode
(ties-to-even).

## Fix

**`python/tvm/topi/math.py`**: Switch `topi.round()` from `te.round` to
`te.nearbyint`. This lowers to `tir.nearbyint` -> `llvm::nearbyint`,
which respects IEEE 754 ties-to-even.

**`src/target/source/intrin_rule_webgpu.cc`**: Register `tir.nearbyint`
for the WebGPU backend. WGSL `round()` is already ties-to-even per the
WGSL spec, so `tir.nearbyint` -> `round` is the correct mapping.

**`tests/python/relax/test_frontend_onnx.py`**: Add
`test_round_ties_to_even()` with explicit midpoint inputs to prevent
regression.

## Testing

```
python -m pytest 
tests/python/relax/test_frontend_onnx.py::test_round_ties_to_even -xvs
python -m pytest "tests/python/relax/test_frontend_onnx.py::test_unary[Round]" 
-xvs
```

Both pass. The new test compares TVM output against onnxruntime (which
correctly implements ties-to-even) for inputs `[0.5, 1.5, 2.5, -0.5,
-1.5, -2.5]`.

Fixes #18590

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

With regards,
GitHub Actions via GitBox


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

Reply via email to