Skip to content

[xpu][fix]Relax fp16 grad tolerance for combinations on XPU - #195403

Closed
ZhaoqiongZ wants to merge 1 commit into
pytorch:mainfrom
ZhaoqiongZ:xpu/fix-combinations-fp16-grad-tol
Closed

ZhaoqiongZ wants to merge 1 commit into
pytorch:mainfrom
ZhaoqiongZ:xpu/fix-combinations-fp16-grad-tol

Conversation

@ZhaoqiongZ

@ZhaoqiongZ ZhaoqiongZ commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

#189102 bumped the gradient tolerances for
test_comprehensive_combinations_cuda_float16 after #186595 / #189305
reimplemented torch.combinations on top of index_put, whose fp16 backward
Inductor accumulates in fp16. That PR only added the override to
inductor_override_kwargs["cuda"]; inductor_override_kwargs["xpu"] is a
separate dict and never got the equivalent entry, leaving XPU on the default
fp16 gradient tolerance (atol=1e-5, rtol=1e-3), which is too tight for the
fp16 accumulation rounding. Result: #195071
(test_comprehensive_combinations_xpu_float16) was disabled on 2026-08-27.

Root cause on the failing sample

Sample 17: input=(4,) fp16, r=4, with_replacement=True -> output (35, 4).
Each of the 4 inputs is copied into 35 output slots, so its gradient is the sum
of 35 fp16 contributions.

Forward is bit-identical between eager and Inductor; only the backward differs.
Inductor lowers the index_put(accumulate=True) backward to a single fp16
atomic scatter (triton_poi_fused_index_put_new_zeros_1):

tmp6 = tl.load(in_ptr1 + (x0), xmask).to(tl.float32)
tl.atomic_add(out_ptr0 + (tl.broadcast_to(tmp4, [XBLOCK])), tmp6, xmask, sem='relaxed')

out_ptr0 is *fp16, so the 35 additions per slot round to fp16 on every step,
in hardware-scheduling order. The XPU aten index_put accumulates in higher
precision and rounds once:

# accumulate 100 x 0.0002 into an fp16 slot initialised to 1.0 (exact = 1.02)
eager    index_put_(accumulate=True) -> 1.01953125
inductor same op                     -> 1.0          (== naive fp16 read-add-write)

Against an fp64 reference on the failing sample:

grad(input):
  eager    vs ref-fp64: max_rel = 3.65e-04
  inductor vs ref-fp64: max_rel = 3.99e-03
  inductor vs eager   : max_rel = 1.6e-03 .. 4.9e-03 across runs (>> default rtol=1e-3)

The run-to-run spread comes from the nondeterministic atomic order: the same
input produced 14 distinct fp16 results in 20 Inductor runs, vs 1 for eager.
This is intrinsic fp16 accumulation rounding, not a correctness bug on either
side, and matches the situation upstream addressed on CUDA in #189102.

Fix

Add the same (combinations, f16) override that #189102 added for CUDA to
inductor_override_kwargs["xpu"]. Observed max abs diff is 1.22e-03 against an
allowance of 2e-3 + 0.01 * 0.5 ~= 7e-3, i.e. about 5.7x headroom.

Test plan

Nightly wheel torch==2.15.0.dev20260830+xpu, triton-xpu 3.8.0, on Intel Arc
B390. Run from the pytorch checkout root:

PYTORCH_OPINFO_SAMPLE_INPUT_INDEX=17 TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    TestInductorOpInfoXPU.test_comprehensive_combinations_xpu_float16
# before: FAILED  Tensor-likes are not close! 1/4 mismatched,
#                 rel 1.066e-03 > 1e-03 allowed
# after:  OK

All samples, three consecutive runs:

TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    TestInductorOpInfoXPU.test_comprehensive_combinations_xpu_float16
# OK / OK / OK

All dtypes, cpu and xpu:

TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    -k test_comprehensive_combinations -v
# Ran 14 tests    OK (skipped=2)

Fixes #195071

Note: authored with AI assistance.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

## Motivation

pytorch#189102 bumped the gradient tolerances for
`test_comprehensive_combinations_cuda_float16` after pytorch#186595 / pytorch#189305
reimplemented `torch.combinations` on top of `index_put`, whose fp16 backward
Inductor accumulates in fp16. That PR only added the override to
`inductor_override_kwargs["cuda"]`; `inductor_override_kwargs["xpu"]` is a
separate dict and never got the equivalent entry, leaving XPU on the default
fp16 gradient tolerance (`atol=1e-5, rtol=1e-3`), which is too tight for the
fp16 accumulation rounding. Result: pytorch#195071
(`test_comprehensive_combinations_xpu_float16`) was disabled on 2026-08-27.

## Root cause on the failing sample

Sample 17: `input=(4,) fp16, r=4, with_replacement=True` -> output `(35, 4)`.
Each of the 4 inputs is copied into 35 output slots, so its gradient is the sum
of 35 fp16 contributions.

Forward is bit-identical between eager and Inductor; only the backward differs.
Inductor lowers the `index_put(accumulate=True)` backward to a single fp16
atomic scatter (`triton_poi_fused_index_put_new_zeros_1`):

```python
tmp6 = tl.load(in_ptr1 + (x0), xmask).to(tl.float32)
tl.atomic_add(out_ptr0 + (tl.broadcast_to(tmp4, [XBLOCK])), tmp6, xmask, sem='relaxed')
```

`out_ptr0` is `*fp16`, so the 35 additions per slot round to fp16 on every step,
in hardware-scheduling order. The XPU aten `index_put` accumulates in higher
precision and rounds once:

```
# accumulate 100 x 0.0002 into an fp16 slot initialised to 1.0 (exact = 1.02)
eager    index_put_(accumulate=True) -> 1.01953125
inductor same op                     -> 1.0          (== naive fp16 read-add-write)
```

Against an fp64 reference on the failing sample:

```
grad(input):
  eager    vs ref-fp64: max_rel = 3.65e-04
  inductor vs ref-fp64: max_rel = 3.99e-03
  inductor vs eager   : max_rel = 1.6e-03 .. 4.9e-03 across runs (>> default rtol=1e-3)
```

The run-to-run spread comes from the nondeterministic atomic order: the same
input produced 14 distinct fp16 results in 20 Inductor runs, vs 1 for eager.
This is intrinsic fp16 accumulation rounding, not a correctness bug on either
side, and matches the situation upstream addressed on CUDA in pytorch#189102.

## Fix

Add the same `(combinations, f16)` override that pytorch#189102 added for CUDA to
`inductor_override_kwargs["xpu"]`. Observed max abs diff is 1.22e-03 against an
allowance of `2e-3 + 0.01 * 0.5 ~= 7e-3`, i.e. about 5.7x headroom.

## Test plan

Nightly wheel `torch==2.15.0.dev20260830+xpu`, triton-xpu 3.8.0, on Intel Arc
B390. Run from the pytorch checkout root:

```
PYTORCH_OPINFO_SAMPLE_INPUT_INDEX=17 TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    TestInductorOpInfoXPU.test_comprehensive_combinations_xpu_float16
```
```
# before: FAILED  Tensor-likes are not close! 1/4 mismatched,
#                 rel 1.066e-03 > 1e-03 allowed
# after:  OK
```

All samples, three consecutive runs:

```
TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    TestInductorOpInfoXPU.test_comprehensive_combinations_xpu_float16
```
```
# OK / OK / OK
```

All dtypes, cpu and xpu:

```
TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    -k test_comprehensive_combinations -v
```
```
# Ran 14 tests    OK (skipped=2)
```

Fixes pytorch#195071

_Note: authored with AI assistance._
@pytorch-bot

pytorch-bot Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195403

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (2 Unrelated Failures)

As of commit 5dd4a1b with merge base 8ac512d (image):

CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@ZhaoqiongZ
ZhaoqiongZ requested review from etaf and guangyey August 31, 2026 02:54
@ZhaoqiongZ
ZhaoqiongZ marked this pull request as ready for review August 31, 2026 02:55
@ZhaoqiongZ

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 1, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
…195403)

## Motivation

pytorch#189102 bumped the gradient tolerances for
`test_comprehensive_combinations_cuda_float16` after pytorch#186595 / pytorch#189305
reimplemented `torch.combinations` on top of `index_put`, whose fp16 backward
Inductor accumulates in fp16. That PR only added the override to
`inductor_override_kwargs["cuda"]`; `inductor_override_kwargs["xpu"]` is a
separate dict and never got the equivalent entry, leaving XPU on the default
fp16 gradient tolerance (`atol=1e-5, rtol=1e-3`), which is too tight for the
fp16 accumulation rounding. Result: pytorch#195071
(`test_comprehensive_combinations_xpu_float16`) was disabled on 2026-08-27.

## Root cause on the failing sample

Sample 17: `input=(4,) fp16, r=4, with_replacement=True` -> output `(35, 4)`.
Each of the 4 inputs is copied into 35 output slots, so its gradient is the sum
of 35 fp16 contributions.

Forward is bit-identical between eager and Inductor; only the backward differs.
Inductor lowers the `index_put(accumulate=True)` backward to a single fp16
atomic scatter (`triton_poi_fused_index_put_new_zeros_1`):

```python
tmp6 = tl.load(in_ptr1 + (x0), xmask).to(tl.float32)
tl.atomic_add(out_ptr0 + (tl.broadcast_to(tmp4, [XBLOCK])), tmp6, xmask, sem='relaxed')
```

`out_ptr0` is `*fp16`, so the 35 additions per slot round to fp16 on every step,
in hardware-scheduling order. The XPU aten `index_put` accumulates in higher
precision and rounds once:

```
# accumulate 100 x 0.0002 into an fp16 slot initialised to 1.0 (exact = 1.02)
eager    index_put_(accumulate=True) -> 1.01953125
inductor same op                     -> 1.0          (== naive fp16 read-add-write)
```

Against an fp64 reference on the failing sample:

```
grad(input):
  eager    vs ref-fp64: max_rel = 3.65e-04
  inductor vs ref-fp64: max_rel = 3.99e-03
  inductor vs eager   : max_rel = 1.6e-03 .. 4.9e-03 across runs (>> default rtol=1e-3)
```

The run-to-run spread comes from the nondeterministic atomic order: the same
input produced 14 distinct fp16 results in 20 Inductor runs, vs 1 for eager.
This is intrinsic fp16 accumulation rounding, not a correctness bug on either
side, and matches the situation upstream addressed on CUDA in pytorch#189102.

## Fix

Add the same `(combinations, f16)` override that pytorch#189102 added for CUDA to
`inductor_override_kwargs["xpu"]`. Observed max abs diff is 1.22e-03 against an
allowance of `2e-3 + 0.01 * 0.5 ~= 7e-3`, i.e. about 5.7x headroom.

## Test plan

Nightly wheel `torch==2.15.0.dev20260830+xpu`, triton-xpu 3.8.0, on Intel Arc
B390. Run from the pytorch checkout root:

```
PYTORCH_OPINFO_SAMPLE_INPUT_INDEX=17 TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    TestInductorOpInfoXPU.test_comprehensive_combinations_xpu_float16
```
```
# before: FAILED  Tensor-likes are not close! 1/4 mismatched,
#                 rel 1.066e-03 > 1e-03 allowed
# after:  OK
```

All samples, three consecutive runs:

```
TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    TestInductorOpInfoXPU.test_comprehensive_combinations_xpu_float16
```
```
# OK / OK / OK
```

All dtypes, cpu and xpu:

```
TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    -k test_comprehensive_combinations -v
```
```
# Ran 14 tests    OK (skipped=2)
```

Fixes pytorch#195071

_Note: authored with AI assistance._

Pull Request resolved: pytorch#195403
Approved by: https://github.com/etaf, https://github.com/jansel
Sanskaaar1 pushed a commit to Sanskaaar1/pytorch that referenced this pull request Sep 8, 2026
…195403)

## Motivation

pytorch#189102 bumped the gradient tolerances for
`test_comprehensive_combinations_cuda_float16` after pytorch#186595 / pytorch#189305
reimplemented `torch.combinations` on top of `index_put`, whose fp16 backward
Inductor accumulates in fp16. That PR only added the override to
`inductor_override_kwargs["cuda"]`; `inductor_override_kwargs["xpu"]` is a
separate dict and never got the equivalent entry, leaving XPU on the default
fp16 gradient tolerance (`atol=1e-5, rtol=1e-3`), which is too tight for the
fp16 accumulation rounding. Result: pytorch#195071
(`test_comprehensive_combinations_xpu_float16`) was disabled on 2026-08-27.

## Root cause on the failing sample

Sample 17: `input=(4,) fp16, r=4, with_replacement=True` -> output `(35, 4)`.
Each of the 4 inputs is copied into 35 output slots, so its gradient is the sum
of 35 fp16 contributions.

Forward is bit-identical between eager and Inductor; only the backward differs.
Inductor lowers the `index_put(accumulate=True)` backward to a single fp16
atomic scatter (`triton_poi_fused_index_put_new_zeros_1`):

```python
tmp6 = tl.load(in_ptr1 + (x0), xmask).to(tl.float32)
tl.atomic_add(out_ptr0 + (tl.broadcast_to(tmp4, [XBLOCK])), tmp6, xmask, sem='relaxed')
```

`out_ptr0` is `*fp16`, so the 35 additions per slot round to fp16 on every step,
in hardware-scheduling order. The XPU aten `index_put` accumulates in higher
precision and rounds once:

```
# accumulate 100 x 0.0002 into an fp16 slot initialised to 1.0 (exact = 1.02)
eager    index_put_(accumulate=True) -> 1.01953125
inductor same op                     -> 1.0          (== naive fp16 read-add-write)
```

Against an fp64 reference on the failing sample:

```
grad(input):
  eager    vs ref-fp64: max_rel = 3.65e-04
  inductor vs ref-fp64: max_rel = 3.99e-03
  inductor vs eager   : max_rel = 1.6e-03 .. 4.9e-03 across runs (>> default rtol=1e-3)
```

The run-to-run spread comes from the nondeterministic atomic order: the same
input produced 14 distinct fp16 results in 20 Inductor runs, vs 1 for eager.
This is intrinsic fp16 accumulation rounding, not a correctness bug on either
side, and matches the situation upstream addressed on CUDA in pytorch#189102.

## Fix

Add the same `(combinations, f16)` override that pytorch#189102 added for CUDA to
`inductor_override_kwargs["xpu"]`. Observed max abs diff is 1.22e-03 against an
allowance of `2e-3 + 0.01 * 0.5 ~= 7e-3`, i.e. about 5.7x headroom.

## Test plan

Nightly wheel `torch==2.15.0.dev20260830+xpu`, triton-xpu 3.8.0, on Intel Arc
B390. Run from the pytorch checkout root:

```
PYTORCH_OPINFO_SAMPLE_INPUT_INDEX=17 TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    TestInductorOpInfoXPU.test_comprehensive_combinations_xpu_float16
```
```
# before: FAILED  Tensor-likes are not close! 1/4 mismatched,
#                 rel 1.066e-03 > 1e-03 allowed
# after:  OK
```

All samples, three consecutive runs:

```
TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    TestInductorOpInfoXPU.test_comprehensive_combinations_xpu_float16
```
```
# OK / OK / OK
```

All dtypes, cpu and xpu:

```
TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 \
    python test/inductor/test_torchinductor_opinfo.py \
    -k test_comprehensive_combinations -v
```
```
# Ran 14 tests    OK (skipped=2)
```

Fixes pytorch#195071

_Note: authored with AI assistance._

Pull Request resolved: pytorch#195403
Approved by: https://github.com/etaf, https://github.com/jansel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DISABLED test_comprehensive_combinations_xpu_float16 (__main__.TestInductorOpInfoXPU)

5 participants