[Bug Skip] XPU index_add_ numerical accuracy: 3 test_index_add_correctness_2d_* cases (bf16, fp32+alpha)
- Dominant language
- Python
- Stars
- 113
- Forks
- 128
- Avg merge
- 5d 13h
- Merged PRs (30d)
- 107
Description
## Bug Description
`torch.Tensor.index_add_` (and the out-of-place equivalent) on XPU produces
numerically inaccurate results when used with `bfloat16` and with `float32 +
non-default alpha`, exceeding the tolerances upstream's `test_indexing.py`
applies. Three cases under `TestIndexingXPU` fail:
## Affected Tests
Cases:
op_ut,third_party.torch-xpu-ops.test.xpu.test_indexing_xpu.TestIndexingXPU,test_index_add_correctness_2d_alpha_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_indexing_xpu.TestIndexingXPU,test_index_add_correctness_2d_large_xpu_bfloat16
op_ut,third_party.torch-xpu-ops.test.xpu.test_indexing_xpu.TestIndexingXPU,test_index_add_correctness_2d_out_of_place_xpu_bfloat16
## Error Messages
### `test_index_add_correctness_2d_alpha_xpu` (float32 + alpha)
```
AssertionError: Tensor-likes are not close!
Mismatched elements: 37 / 3200 (1.2%)
Greatest absolute difference: 9.012222290039062e-05 at index (58, 13)
Greatest relative difference: 0.0005161699373275042 at index (58, 13)
File ".../test/test_indexing.py:2218"
self.assertEqual(dst.cpu(), dst_ref, atol=1e-5, rtol=1e-5)
```
### `test_index_add_correctness_2d_large_xpu_bfloat16`
```
AssertionError: 0.016779609101716046 not less than 0.01 :
index_add_ torch.bfloat16 L2 rel err too high: 0.016779609101716046
File ".../test/test_indexing.py:2158"
```
### `test_index_add_correctness_2d_out_of_place_xpu_bfloat16`
```
AssertionError: Tensor-likes are not close!
Mismatched elements: 52 / 6400 (0.8%)
Greatest absolute difference: 0.28363037109375 at index (38, 10)
Greatest relative difference: 0.4216286838054657 at index (177, 27)
File ".../test/test_indexing.py:2198"
self.assertEqual(out_func.cpu().float(), ref, atol=atol, rtol=rtol)
```
## Reproduction
```bash
cd $HOME/daisy_pytorch/third_party/torch-xpu-ops/test/xpu
pytest -v test_indexing_xpu.py::TestIndexingXPU::test_index_add_correctness_2d_alpha_xpu
pytest -v test_indexing_xpu.py::TestIndexingXPU::test_index_add_correctness_2d_large_xpu_bfloat16
pytest -v test_indexing_xpu.py::TestIndexingXPU::test_index_add_correctness_2d_out_of_place_xpu_bfloat16
```
## Root Cause Analysis
All three failures point at the XPU `index_add_` kernel:
- The `_alpha` variant uses fp32 inputs and a non-trivial `alpha` scalar; the
observed error (~9e-5 abs, ~5e-4 rel) exceeds upstream's tight
`atol=rtol=1e-5`. Likely a non-deterministic-or-different-order
reduction in the XPU kernel.
- Both `_bfloat16` variants are large 2-D tests where bf16 precision combined
with kernel reduction order produces L2 relative error of ~0.017–0.42,
well above the bf16-specific tolerances upstream has tuned for CUDA
(`L2_rel < 0.01`, and per-element `atol/rtol` tighter than 0.05).
This is consistent with XPU `index_add_` using a different parallel
reduction layout than CUDA, accumulating in lower precision than CUDA's
fp32 accumulator path.
## Context
This issue tracks an XPU numerical-accuracy gap surfaced (but not introduced)
by PR [#3475](https://github.com/intel/torch-xpu-ops/pull/3475). PR #3475
enables broader test coverage on XPU; `test_indexing_xpu.py` already exists
on `main`, and these three `test_index_add_correctness_2d_*` cases were
already failing prior to PR #3475 — they appear unfiltered in the PR's
`linux-ut (op_ut) / summary` artifact because no existing tracking issue
covers them.
For PR #3475 to land green, this issue must be `skipped`-labeled with the
`Cases:` lines above so the `ut_result_check.sh` filter stops flagging them
as new failures.
PR: https://github.com/intel/torch-xpu-ops/pull/3475
## Versions
PyTorch: 2.13.0.dev (April 2026 nightly)
Hardware: Intel Data Center GPU Max 1100/1550
## Labels
- `skipped`
- `module: ut`
- `module: nn`
Contributor guide
Assessment
This issue has not been assessed yet.