Repository navigation
[ROCm] route fp16 backward GEMMs to rocBLAS to preserve subnormals - #183766
naromero77amd wants to merge 4 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/183766
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: ❌ 1 New Failure, 7 Unrelated Failures, 12 Unclassified FailuresAs of commit 35811a1 with merge base b4ce724 ( NEW FAILURE - The following job has failed:
UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
The hipBLASLt path for at::Half has no equivalent of rocBLAS's rocblas_gemm_flags_fp16_alt_impl, so once blasPreferredBackend defaults to Cublaslt on gfx90a (PyTorch 2.7+), backward fp16 GEMMs lose the ROCmBackwardPassGuard wiring and silently flush subnormal gradients to zero, corrupting training. In gemm_internal<at::Half> and bgemm_internal<at::Half>, downgrade the preferred backend from Cublaslt to Cublas when ROCmBackwardPassGuard::is_backward_pass() is true. Forward fp16 still uses hipBLASLt; only backward fp16 reroutes, restoring the documented fp16 numerical-stability behavior on ROCm. Fixes pytorch#182952. Authored with Claude Code.
Only gfx90a needs the hipBLASLt backward fp16 subnormal workaround, so keep the backend reroute scoped to that architecture.
The regression is specific to MI250/gfx90a, so skip the ROCm fp16 backward subnormal test on other architectures.
|
Successfully rebased |
6309716 to
2b13217
Compare
|
CI artifact check for the new ROCm fp16 subnormal backward matmul test: MI200 (
MI300 ( |
|
@pytorchbot merge |
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 |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
Apply the same gfx90a backward reroute that gemm_internal<at::Half> and bgemm_internal<at::Half> use to the at::Half-input / float-output specializations so cublaslt-routed reduced-precision GEMMs on gfx90a also bypass hipBLASLt during backward and retain subnormal preservation. Reorder the guard to test is_backward_pass() before isGPUArch() so forward calls short-circuit on the cheaper thread_local read rather than the string find over gcnArchName. Authored with Claude Code.
|
@claude Analyze CI failures |
|
Claude finished @jeffdaily's task in 1m 22s —— View job CI Failure Analysis
SummaryNone of the CI failures appear related to this PR's changes. This PR only modifies Merge-Blocking Failure
Dr. CI already identified this as flaky with a similar failure on trunk. This is an ONNX opcheck test — completely unrelated to ROCm BLAS routing. A retry or rebase should clear this. NEW FAILURE
This is a macOS MPS (Apple Silicon) segfault. This PR touches zero MPS code — only CUDA/ROCm BLAS paths gated behind Unclassified ROCm Failures (MI200 & MI300)
DrCI couldn't classify these because the workflow didn't run on the merge base. However, the PR author's manual verification confirms:
The MI200 shard failures (if any) are likely pre-existing infrastructure issues unrelated to this PR. Other Unrelated Failures
RecommendationThe merge was blocked solely by the flaky ONNX
|
|
@pytorchbot merge -f "claude says failures are unrelated" |
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 |
## Summary This addresses the UT regression exposed after #183766 routed MI200 FP16 backward GEMMs through rocBLAS to preserve subnormals. - Add an MI200-only tolerance override for Inductor `addmm` FP16 OpInfo coverage. - Keep the existing FP32 eager reference while allowing FP16-scale absolute/relative differences. ## Test plan - `python test/inductor/test_torchinductor_opinfo.py -k test_comprehensive_addmm_cuda_float16` Pull Request resolved: #186407 Approved by: https://github.com/jeffdaily Co-authored-by: Cursor <[email protected]> Co-authored-by: PyTorch MergeBot <[email protected]> Co-authored-by: Jeff Daily <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
) ## Summary This addresses the UT regression exposed after pytorch#183766 routed MI200 FP16 backward GEMMs through rocBLAS to preserve subnormals. - Add an MI200-only tolerance override for Inductor `addmm` FP16 OpInfo coverage. - Keep the existing FP32 eager reference while allowing FP16-scale absolute/relative differences. ## Test plan - `python test/inductor/test_torchinductor_opinfo.py -k test_comprehensive_addmm_cuda_float16` Pull Request resolved: pytorch#186407 Approved by: https://github.com/jeffdaily Co-authored-by: Cursor <[email protected]> Co-authored-by: PyTorch MergeBot <[email protected]> Co-authored-by: Jeff Daily <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…ytorch#183766) Fixes pytorch#182952. This PR changes the preferred backend for the fp16 backward GEMMs for ROCm only: - Routes ROCm fp16 backward GEMMs from hipBLASLt to rocBLAS so backward subnormals are preserved. - Keeps forward fp16 GEMMs on hipBLASLt while restoring `ROCmBackwardPassGuard` behavior for backward fp16 GEMMs. - Adds matmul coverage for the ROCm fp16 subnormal gradient behavior. Made with [Cursor](https://cursor.com) Pull Request resolved: pytorch#183766 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
) ## Summary This addresses the UT regression exposed after pytorch#183766 routed MI200 FP16 backward GEMMs through rocBLAS to preserve subnormals. - Add an MI200-only tolerance override for Inductor `addmm` FP16 OpInfo coverage. - Keep the existing FP32 eager reference while allowing FP16-scale absolute/relative differences. ## Test plan - `python test/inductor/test_torchinductor_opinfo.py -k test_comprehensive_addmm_cuda_float16` Pull Request resolved: pytorch#186407 Approved by: https://github.com/jeffdaily Co-authored-by: Cursor <[email protected]> Co-authored-by: PyTorch MergeBot <[email protected]> Co-authored-by: Jeff Daily <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…ytorch#183766) Fixes pytorch#182952. This PR changes the preferred backend for the fp16 backward GEMMs for ROCm only: - Routes ROCm fp16 backward GEMMs from hipBLASLt to rocBLAS so backward subnormals are preserved. - Keeps forward fp16 GEMMs on hipBLASLt while restoring `ROCmBackwardPassGuard` behavior for backward fp16 GEMMs. - Adds matmul coverage for the ROCm fp16 subnormal gradient behavior. Made with [Cursor](https://cursor.com) Pull Request resolved: pytorch#183766 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
) ## Summary This addresses the UT regression exposed after pytorch#183766 routed MI200 FP16 backward GEMMs through rocBLAS to preserve subnormals. - Add an MI200-only tolerance override for Inductor `addmm` FP16 OpInfo coverage. - Keep the existing FP32 eager reference while allowing FP16-scale absolute/relative differences. ## Test plan - `python test/inductor/test_torchinductor_opinfo.py -k test_comprehensive_addmm_cuda_float16` Pull Request resolved: pytorch#186407 Approved by: https://github.com/jeffdaily Co-authored-by: Cursor <[email protected]> Co-authored-by: PyTorch MergeBot <[email protected]> Co-authored-by: Jeff Daily <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
## Summary `test_tf32_tunableop` and `test_tf32_offline_tunableop` were enabled for all ROCm architectures in #183474, which removed both `@runOnRocmArch(MI300_ARCH)` decorators along with the now-unused import. #183586 re-added them while extracting CUDA-only tests into `TestLinalgCUDA`. `git blame` attributes both current decorators to that refactor rather than to any deliberate re-restriction, so this appears to be an accidental regression. This PR restores the state #183474 landed. While in the same area, this also widens `@runOnRocmArch(MI200_ARCH)` on `test_fp16_backward_preserves_subnormals_rocm`, added for MI200 in #183766. RDNA is excluded there only by omission from the allowlist, and the test passes on RDNA. Part of #196583. ## Validation Repeated runs on gfx1100 (Radeon PRO W7900), gfx1151 and gfx1200, HIP `7.16.26320`, with identical results every time. ``` test/test_linalg.py::TestLinalgCudaOnlyCUDA::test_tf32_tunableop_cuda_float32 PASSED test/test_linalg.py::TestLinalgCudaOnlyCUDA::test_tf32_offline_tunableop_cuda_float32 PASSED test/test_matmul_cuda.py::TestMatmulCudaCUDA::test_fp16_backward_preserves_subnormals_rocm_batched_False_backend_cublas_cuda PASSED test/test_matmul_cuda.py::TestMatmulCudaCUDA::test_fp16_backward_preserves_subnormals_rocm_batched_False_backend_cublaslt_cuda PASSED test/test_matmul_cuda.py::TestMatmulCudaCUDA::test_fp16_backward_preserves_subnormals_rocm_batched_True_backend_cublas_cuda PASSED test/test_matmul_cuda.py::TestMatmulCudaCUDA::test_fp16_backward_preserves_subnormals_rocm_batched_True_backend_cublaslt_cuda PASSED ``` Pull Request resolved: #197361 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
…203673) ## Linked issue or supporting maintainer Supported by @jeffdaily ## BC-breaking? No ## Summary (human written only) Fix nine fp16 TestGroupedMMCUDA failures on MI200 that started when #200640 relanded: rocBLAS fp16_alt_impl rounds only one side of the comparison, so loosen the fp16 gradient tolerance on MI200 only. ## Agent details (if applicable) My agent came up with this analysis, but I've read and approved it. Problem: since #200640 relanded, unaligned fp16 TestGroupedMM cases run on ROCm, and nine fp16 `test_grouped_gemm` 2d_3d cases with column-major `a` fail on MI200 (gfx90a) on `a.grad` or `b.grad` by up to ~0.19. MI300X and MI350X pass. Cause: on gfx90a, fp16 backward GEMMs go to rocBLAS with `rocblas_gemm_flags_fp16_alt_impl` (#183766), which truncates fp16 inputs to bf16 (see the MI200 section of the numerical accuracy notes). rocBLAS applies that only in its bf16 MFMA kernels; for other shapes it picks `rocblas_gemvn_kernel` or a non-MFMA Tensile kernel that computes fp16 exactly. The grouped backward and the per-group `torch.mm` reference hand rocBLAS different transposes for column-major `a`, so one side gets alt_impl rounding and the other does not. Each side is bit-exact to its own mode (correctly rounded fp16 of the fp64 result, or bf16-truncated inputs with fp32 accumulate), and running the same two GEMMs outside backward makes them agree, so this is not a wrong result. Change: compare the gradients with atol=0.15, rtol=1e-2 for fp16 CUDA tensors on MI200 only. The forward check, CPU, CUDA, and MI300/MI350 (including the ck_tile fp16 checks) keep their tolerances. Across every fp16 `test_grouped_gemm` case and layout with 100 seeds each on MI250X, the worst observed requirement at rtol=1e-2 was atol=0.0975 (`a.grad`) and 0.0373 (`b.grad`). Test plan, on MI250X (gfx90a), ROCm 10.1: ~~~ PYTORCH_TEST_WITH_ROCM=1 python test/test_linalg.py -v -k TestGroupedMMCUDA PYTORCH_TEST_WITH_ROCM=1 python test/test_linalg.py -v -k TestGroupedMMCPU ~~~ CUDA: 847 tests, OK (skipped=482, all ck_tile gfx942/gfx950-only); the nine previously failing tests passed 20 of 20 repeated runs. CPU: identical per-test outcomes with and without the change. Pull Request resolved: #203673 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
Fixes #182952.
This PR changes the preferred backend for the fp16 backward GEMMs for ROCm only:
ROCmBackwardPassGuardbehavior for backward fp16 GEMMs.Made with Cursor
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @pragupta @jerrymannil @xinyazhang