Skip to content

[ROCm] Fix LayerNorm backward kernel for AMD Strix Halo GPUs - #183864

Closed
bozhou2021 wants to merge 1 commit into
pytorch:mainfrom
bozhou2021:bozhou-fix-layer-norm-issue
Closed

bozhou2021 wants to merge 1 commit into
pytorch:mainfrom
bozhou2021:bozhou-fix-layer-norm-issue

Conversation

@bozhou2021

@bozhou2021 bozhou2021 commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

FIXES #183861

LayerNorm/RMSNorm's gamma beta backward kernel produced wrong results for
AMD Strix Halo and other RDNA GPUs.

It was caused by a hardcoded warp size (incorrect for RDNA/Strix Halo),
and mixed usage of thread block and warp coordinates. This caused half of the
values (along the x-axis/features) being dropped when saving the gradients
after partial sum reduction.

The fix is to query and use correct warp size instead of the hardcoded values.

  • No semantic change to the existing AMD and CUDA code paths.
  • This will bring Strix Halo/RNDA to the proven/performant CUDA code path.

Issue reproduced and tested on local Strix Halo hardware using:
$python test/test_nn.py TestNN.test_layer_norm_backwards_eps -v

See issue #183861

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

@pytorch-bot pytorch-bot Bot added the release notes: cuda release notes category label May 15, 2026
@pytorch-bot

pytorch-bot Bot commented May 15, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (3 Unrelated Failures)

As of commit 1f9d9d4 with merge base c04643e (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

@linux-foundation-easycla

linux-foundation-easycla Bot commented May 15, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: bozhou2021 / name: Bo Zhou (de7691a)

int nshared = (num_threads() / warp_size) * sizeof(T_ACC);

bool bVectorSizeMultiple = (N % vec_size == 0);
bool bTargetDataTypes = (std::is_same_v<T, float> || std::is_same_v<T, at::Half> ||

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should be constexpr probably

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep. I'm happy to make another PR to tidy up (this PR is for the bug fix).

@cyyever

cyyever commented May 17, 2026

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased bozhou-fix-layer-norm-issue onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout bozhou-fix-layer-norm-issue && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the bozhou-fix-layer-norm-issue branch from de7691a to 46784d4 Compare May 17, 2026 03:43
@cyyever

cyyever commented May 17, 2026

Copy link
Copy Markdown
Collaborator

@pytorchmergebot merge -i

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

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 0 checks:

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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@jeffdaily jeffdaily changed the title Fix LayerNorm backward kernel for AMD Strix Halo GPUs [ROCm] Fix LayerNorm backward kernel for AMD Strix Halo GPUs May 18, 2026
@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label May 18, 2026
@jeffdaily jeffdaily added release notes: rocm mandatorylabel ciflow/rocm-navi31 Trigger "default" config CI on ROCm Navi31 and removed module: rocm AMD GPU support for Pytorch release notes: cuda release notes category labels May 18, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

@bozhou2021 the rocm build failure is legit, please fix.

@bozhou2021

Copy link
Copy Markdown
Contributor Author

@jeffdaily any insight how to make these 3 checks pass? Is there any way to rerun them?

@jeffdaily

Copy link
Copy Markdown
Collaborator

We're working on an infra issue with our navi runners at the moment. At least the build was successful this time. Checking with our infra team.

@bozhou2021

bozhou2021 commented May 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@jeffdaily in the meantime, what's the recommended way to merge this change to pytorch2.12? It got the same issue and breaks RDNA GPUs

@bozhou2021

Copy link
Copy Markdown
Contributor Author

@jeffdaily @ROCmSupport any luck with the infra/navi runners?

@bozhou2021

Copy link
Copy Markdown
Contributor Author

@jeffdaily @janeyx99 any ideas who can help getting the CI fixed/running properly so this PR can be merged?

PyTorch 2.12 (the current stable version) is broken too, so I'm quite keen to get this one merged and then I can merge the fix to 2.12 branch.

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -f "confirmed outside of CI that all tests are passing on navi; working on fixing navi infra separately"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

@bozhou2021

Copy link
Copy Markdown
Contributor Author

@pytorchbot cherry-pick --onto release/2.12 -c regression --fixes #183861

@pytorchbot

Copy link
Copy Markdown
Collaborator

Cherry picking #183864

The cherry pick PR is at #185415 and it is linked with issue #183861.

Details for Dev Infra team Raised by workflow job

tinglvv pushed a commit that referenced this pull request May 28, 2026
FIXES #183861

LayerNorm/RMSNorm's gamma beta backward kernel produced wrong results for
AMD Strix Halo and other RDNA GPUs.

It was caused by a hardcoded warp size (incorrect for RDNA/Strix Halo),
and mixed usage of thread block and warp coordinates. This caused half of the
values (along the x-axis/features) being dropped when saving the gradients
after partial sum reduction.

The fix is to query and use correct warp size instead of the hardcoded values.

- No semantic change to the existing AMD and CUDA code paths.
- This will bring Strix Halo/RNDA to the proven/performant CUDA code path.

Issue reproduced and tested on local Strix Halo hardware using:
$python test/test_nn.py TestNN.test_layer_norm_backwards_eps -v

See issue #183861

Pull Request resolved: #183864
Approved by: https://github.com/Skylion007, https://github.com/cyyever, https://github.com/jeffdaily
khushi-411 pushed a commit to khushi-411/pytorch that referenced this pull request Jun 1, 2026
…#183864)

FIXES pytorch#183861

LayerNorm/RMSNorm's gamma beta backward kernel produced wrong results for
AMD Strix Halo and other RDNA GPUs.

It was caused by a hardcoded warp size (incorrect for RDNA/Strix Halo),
and mixed usage of thread block and warp coordinates. This caused half of the
values (along the x-axis/features) being dropped when saving the gradients
after partial sum reduction.

The fix is to query and use correct warp size instead of the hardcoded values.

- No semantic change to the existing AMD and CUDA code paths.
- This will bring Strix Halo/RNDA to the proven/performant CUDA code path.

Issue reproduced and tested on local Strix Halo hardware using:
$python test/test_nn.py TestNN.test_layer_norm_backwards_eps -v

See issue pytorch#183861

Pull Request resolved: pytorch#183864
Approved by: https://github.com/Skylion007, https://github.com/cyyever, https://github.com/jeffdaily
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…#183864)

FIXES pytorch#183861

LayerNorm/RMSNorm's gamma beta backward kernel produced wrong results for
AMD Strix Halo and other RDNA GPUs.

It was caused by a hardcoded warp size (incorrect for RDNA/Strix Halo),
and mixed usage of thread block and warp coordinates. This caused half of the
values (along the x-axis/features) being dropped when saving the gradients
after partial sum reduction.

The fix is to query and use correct warp size instead of the hardcoded values.

- No semantic change to the existing AMD and CUDA code paths.
- This will bring Strix Halo/RNDA to the proven/performant CUDA code path.

Issue reproduced and tested on local Strix Halo hardware using:
$python test/test_nn.py TestNN.test_layer_norm_backwards_eps -v

See issue pytorch#183861

Pull Request resolved: pytorch#183864
Approved by: https://github.com/Skylion007, https://github.com/cyyever, https://github.com/jeffdaily
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…#183864)

FIXES pytorch#183861

LayerNorm/RMSNorm's gamma beta backward kernel produced wrong results for
AMD Strix Halo and other RDNA GPUs.

It was caused by a hardcoded warp size (incorrect for RDNA/Strix Halo),
and mixed usage of thread block and warp coordinates. This caused half of the
values (along the x-axis/features) being dropped when saving the gradients
after partial sum reduction.

The fix is to query and use correct warp size instead of the hardcoded values.

- No semantic change to the existing AMD and CUDA code paths.
- This will bring Strix Halo/RNDA to the proven/performant CUDA code path.

Issue reproduced and tested on local Strix Halo hardware using:
$python test/test_nn.py TestNN.test_layer_norm_backwards_eps -v

See issue pytorch#183861

Pull Request resolved: pytorch#183864
Approved by: https://github.com/Skylion007, https://github.com/cyyever, https://github.com/jeffdaily
jerrymannil pushed a commit to ROCm/pytorch that referenced this pull request Aug 14, 2026
…#183864)

FIXES pytorch#183861

LayerNorm/RMSNorm's gamma beta backward kernel produced wrong results for
AMD Strix Halo and other RDNA GPUs.

It was caused by a hardcoded warp size (incorrect for RDNA/Strix Halo),
and mixed usage of thread block and warp coordinates. This caused half of the
values (along the x-axis/features) being dropped when saving the gradients
after partial sum reduction.

The fix is to query and use correct warp size instead of the hardcoded values.

- No semantic change to the existing AMD and CUDA code paths.
- This will bring Strix Halo/RNDA to the proven/performant CUDA code path.

Issue reproduced and tested on local Strix Halo hardware using:
$python test/test_nn.py TestNN.test_layer_norm_backwards_eps -v

See issue pytorch#183861

Pull Request resolved: pytorch#183864
Approved by: https://github.com/Skylion007, https://github.com/cyyever, https://github.com/jeffdaily

(cherry picked from commit c3534e4)
aswin-dot-R added a commit to aswin-dot-R/feral that referenced this pull request Oct 5, 2026
…e32)

The LayerNorm backward bug was already fixed upstream by
pytorch/pytorch#183864 (runtime wave-size dispatch), released in torch
2.13.0; re-checked on RX 9070 XT: 2.12.1+rocm7.2 fails, 2.14.1+rocm7.2
passes for M = 64..70000 and for RMSNorm.

So the workaround now patches only when all hold: HIP build, torch
< 2.13, and a visible GPU with 32-wide waves (RDNA). CUDA, CPU, MPS,
CDNA (wave64) and torch >= 2.13 are untouched. apply() moves from module
import into FeralModel.__init__ so importing feral never queries the GPU,
logs a warning when active, and FERAL_ROCM_LN_FIX=1 forces it on
(=0 still disables it).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/rocm-navi31 Trigger "default" config CI on ROCm Navi31 ciflow/trunk Trigger trunk jobs on your pull request Merged module: rocm AMD GPU support for Pytorch open source release notes: rocm mandatorylabel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LayerNorm/RMSNorm's gamma beta backward kernel produced wrong results on AMD RDNA GPUs

6 participants