Repository navigation
[ROCm] Relax MI200 fp16 grouped_mm gradient tolerance for alt_impl - #203673
pablo-garay wants to merge 1 commit into
Conversation
Since pytorch#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. On gfx90a, fp16 backward GEMMs go to rocBLAS with rocblas_gemm_flags_fp16_alt_impl, 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), so this is not a wrong result. Compare the gradients with atol=0.15, rtol=1e-2 for fp16 on MI200 only; alt_impl does not exist on other archs, so the ck_tile fp16 checks on MI300/MI350 and all CUDA tolerances stay unchanged, as does the forward output check. 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 ``` 847 tests, OK (skipped=482, all ck_tile gfx942/gfx950-only). The nine previously failing tests passed 20 of 20 repeated runs. ``` PYTORCH_TEST_WITH_ROCM=1 python test/test_linalg.py -v -k TestGroupedMMCPU ``` Identical per-test outcomes with and without the change (363 passed, 484 skipped), so CPU fp16 keeps the default tolerance. Authored with Claude.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/203673
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Unclassified FailureAs of commit dbf878e with merge base 787f500 ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot merge |
|
Pull workflow has not been scheduled for the PR yet. It could be because author doesn't have permissions to run those or skip-checks keywords were added to PR/commits, aborting merge. Please get/give approval for the workflows and/or remove skip ci decorators before next merge attempt. If you think this is a mistake, please contact PyTorch Dev Infra. |
|
@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 jobs have failed, first few of them are: .github/workflows/tsan.yml Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: .github/workflows/tsan.yml Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
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_gemm2d_3d cases with column-majorafail on MI200 (gfx90a) ona.gradorb.gradby 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 picksrocblas_gemvn_kernelor a non-MFMA Tensile kernel that computes fp16 exactly. The grouped backward and the per-grouptorch.mmreference hand rocBLAS different transposes for column-majora, 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_gemmcase 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:
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.
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang