Skip to content

[xpu][fix]Relax fp16 grad tolerance for native_group_norm on XPU - #191601

Closed
ZhaoqiongZ wants to merge 1 commit into
pytorch:mainfrom
ZhaoqiongZ:xpu-native-group-norm-fp16-grad-tol
Closed

ZhaoqiongZ wants to merge 1 commit into
pytorch:mainfrom
ZhaoqiongZ:xpu-native-group-norm-fp16-grad-tol

Conversation

@ZhaoqiongZ

@ZhaoqiongZ ZhaoqiongZ commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

#190245 fixed missed upcasts in the CUDA native_group_norm_backward kernel/decomposition and replaced the previous check_gradient: False overrides with looser tolerances (grad_atol=2e-3, grad_rtol=1e-3). That PR left the CUDA override in place but removed the corresponding XPU override without adding anything back, leaving XPU on the default fp16 tolerance (atol=1e-5, rtol=1e-3) which is too tight for the residual 1-ULP rounding differences between the XPU aten backward kernel and the Inductor decomposition. Result: #185367 (test_comprehensive_native_group_norm_xpu_float16) has been disabled since May 2026.

Root cause on the failing sample

Sample: input=(1,6,3), groups=2, eps=0.5, fp16

d_input:
  eager  vs ref-fp32: max_abs = 9.77e-04
  comp   vs ref-fp32: max_abs = 9.77e-04
  comp   vs eager   : max_abs = 9.77e-04    (>> default atol=1e-5)

Both eager and compiled backward stay within fp16 quantization of an fp32 reference, but they round to different fp16 values at some indices. The XPU aten kernel already accumulates in fp32 (T_ACC); the residual difference comes from the aten kernel executing as several TensorIterator launches vs Inductor materializing one fused fp32 graph. This is intrinsic fp16 rounding, not a correctness bug on either side, and matches the situation upstream addressed on CUDA in #190245.

Fix

Align XPU with the CUDA precedent from the same PR by adding the same (native_group_norm, f16) override to inductor_override_kwargs["xpu"].

Test plan

Against nightly wheel torch==2.14.0.dev20260728+xpu on Intel Data Center GPU Max 1100:

python -m pytest test/inductor/test_torchinductor_opinfo.py -v \
    -k test_comprehensive_native_group_norm_xpu --timeout=600
# native_group_norm_xpu_float16  PASSED
# native_group_norm_xpu_float32  PASSED
# native_group_norm_xpu_float64  PASSED
# 3 passed, 7450 deselected

Fixes #185367

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

Note: authored with AI assistance.

pytorch#190245 fixed missed upcasts in the CUDA
native_group_norm_backward kernel/decomposition and replaced the
previous `check_gradient: False` overrides with looser tolerances
(`grad_atol=2e-3, grad_rtol=1e-3`). That PR left the CUDA override
in place but removed the corresponding XPU override without adding
anything back, leaving XPU on the default fp16 tolerance
(`atol=1e-5, rtol=1e-3`) which is too tight for the residual 1-ULP
rounding differences between the XPU aten backward kernel and the
Inductor decomposition. Result: pytorch#185367
(`test_comprehensive_native_group_norm_xpu_float16`) has been
disabled since May 2026.

Root cause on the failing sample
(input=(1,6,3), groups=2, eps=0.5, fp16):

  d_input:
    eager  vs ref-fp32: max_abs=9.77e-04
    comp   vs ref-fp32: max_abs=9.77e-04
    comp   vs eager   : max_abs=9.77e-04  (>> default atol=1e-5)

Both eager and compiled backward stay within fp16 quantization of an
fp32 reference, but they round to different fp16 values at some
indices. The XPU aten kernel already accumulates in fp32 (`T_ACC`);
the residual difference comes from the aten kernel executing as
several TensorIterator launches vs Inductor materializing one fused
fp32 graph. This is intrinsic fp16 rounding, not a correctness bug
on either side, and matches the situation upstream addressed on CUDA
in pytorch#190245.

Align XPU with the CUDA precedent in the same PR by adding the same
`(native_group_norm, f16)` override to `inductor_override_kwargs['xpu']`.

## Test plan

Against nightly wheel `torch==2.14.0.dev20260728+xpu` on Intel Data
Center GPU Max 1100:

```
python -m pytest test/inductor/test_torchinductor_opinfo.py -v \
    -k test_comprehensive_native_group_norm_xpu --timeout=600
# native_group_norm_xpu_float16  PASSED
# native_group_norm_xpu_float32  PASSED
# native_group_norm_xpu_float64  PASSED
# 3 passed, 7450 deselected
```

Fixes pytorch#185367

Note: authored with AI assistance.
@pytorch-bot

pytorch-bot Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit bba7bce with merge base 2da8437 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR relaxes fp16 gradient-check tolerances for native_group_norm on XPU in Inductor OpInfo comprehensive tests, aligning XPU behavior with the existing CUDA precedent to avoid false failures from expected fp16 rounding differences between eager and Inductor decomposition paths.

Changes:

  • Add an XPU-specific ("native_group_norm", f16) override with grad_atol=2e-3 and grad_rtol=1e-3.
  • Document the rationale in-line, referencing the CUDA tolerance adjustment in #190245.

@ZhaoqiongZ
ZhaoqiongZ marked this pull request as ready for review July 30, 2026 08:29
@ZhaoqiongZ
ZhaoqiongZ requested review from etaf and guangyey July 30, 2026 08:45
@ZhaoqiongZ ZhaoqiongZ changed the title Relax fp16 grad tolerance for native_group_norm on XPU [xpu][fix]Relax fp16 grad tolerance for native_group_norm on XPU Jul 30, 2026
@etaf
etaf requested a review from jansel July 30, 2026 09:21
@guangyey guangyey added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 30, 2026
@guangyey

guangyey commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@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

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_native_group_norm_xpu_float16 (__main__.TestInductorOpInfoXPU)

7 participants