Repository navigation
[ROCm] Fix LayerNorm backward kernel for AMD Strix Halo GPUs - #183864
bozhou2021 wants to merge 1 commit into
Conversation
🔗 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 SEVsThere 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 ( 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. |
|
|
f195358 to
de7691a
Compare
| 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> || |
There was a problem hiding this comment.
Should be constexpr probably
There was a problem hiding this comment.
Yep. I'm happy to make another PR to tidy up (this PR is for the bug fix).
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
de7691a to
46784d4
Compare
|
@pytorchmergebot merge -i |
Merge startedYour 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 |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
|
@bozhou2021 the rocm build failure is legit, please fix. |
|
@jeffdaily any insight how to make these 3 checks pass? Is there any way to rerun them? |
|
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. |
|
@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 |
|
@jeffdaily @ROCmSupport any luck with the infra/navi runners? |
|
@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. |
|
@pytorchbot merge -f "confirmed outside of CI that all tests are passing on navi; working on fixing navi infra separately" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
@pytorchbot cherry-pick --onto release/2.12 -c regression --fixes #183861 |
Cherry picking #183864The cherry pick PR is at #185415 and it is linked with issue #183861. Details for Dev Infra teamRaised by workflow job |
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
…#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
…#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
…#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
…#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)
…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]>
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.
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