Skip to content

[ROCm] Relax MI200 fp16 grouped_mm gradient tolerance for alt_impl - #203673

Closed
pablo-garay wants to merge 1 commit into
pytorch:mainfrom
ROCm:jeffdaily/rocm-grouped-mm-fp16-alt-impl-tol
Closed

pablo-garay wants to merge 1 commit into
pytorch:mainfrom
ROCm:jeffdaily/rocm-grouped-mm-fp16-alt-impl-tol

Conversation

@pablo-garay

@pablo-garay pablo-garay commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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.

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

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.
@pytorch-bot pytorch-bot Bot added module: rocm AMD GPU support for Pytorch topic: not user facing topic category labels Nov 5, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🔗 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 Failure

As of commit dbf878e with merge base 787f500 (image):

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:

  • TSan (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    AI verdict: AI verdict: pending

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

@jithunnair-amd jithunnair-amd added the ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 label Nov 5, 2026
@jeffdaily
jeffdaily marked this pull request as ready for review November 9, 2026 18:18
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot

pytorch-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

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.

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 9, 2026
@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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: .github/workflows/tsan.yml

Details for Dev Infra team

Raised by workflow job

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

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

Labels

ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 ciflow/trunk Trigger trunk jobs on your pull request Merged module: rocm AMD GPU support for Pytorch open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants