Repository navigation
[xpu][fix]Relax fp16 grad tolerance for combinations on XPU - #195403
Closed
ZhaoqiongZ wants to merge 1 commit into
Closed
ZhaoqiongZ wants to merge 1 commit into
ZhaoqiongZ wants to merge 1 commit into
Conversation
## 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._
🔗 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 ( 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
marked this pull request as ready for review
August 31, 2026 02:55
etaf
approved these changes
Aug 31, 2026
jansel
approved these changes
Aug 31, 2026
Collaborator
Author
|
@pytorchbot merge |
Collaborator
Merge startedYour 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 |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
#189102 bumped the gradient tolerances for
test_comprehensive_combinations_cuda_float16after #186595 / #189305reimplemented
torch.combinationson top ofindex_put, whose fp16 backwardInductor accumulates in fp16. That PR only added the override to
inductor_override_kwargs["cuda"];inductor_override_kwargs["xpu"]is aseparate 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 thefp16 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 fp16atomic scatter (
triton_poi_fused_index_put_new_zeros_1):out_ptr0is*fp16, so the 35 additions per slot round to fp16 on every step,in hardware-scheduling order. The XPU aten
index_putaccumulates in higherprecision and rounds once:
Against an fp64 reference on the failing sample:
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 toinductor_override_kwargs["xpu"]. Observed max abs diff is 1.22e-03 against anallowance 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 ArcB390. Run from the pytorch checkout root:
All samples, three consecutive runs:
All dtypes, cpu and xpu:
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