Skip to content

[ROCm] Fix wrong CK addmm results on gfx950 and unskip the tests - #200195

Closed
pablo-garay wants to merge 8 commits into
pytorch:mainfrom
ROCm:jeffdaily/gfx950-ck-addmm-no-assoc-math
Closed

pablo-garay wants to merge 8 commits into
pytorch:mainfrom
ROCm:jeffdaily/gfx950-ck-addmm-no-assoc-math

Conversation

@pablo-garay

@pablo-garay pablo-garay commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue or supporting maintainer

Supported by @jeffdaily
Fixes #198909
Fixes #198910

BC-breaking?

No

Summary (human written only)

On gfx950, inductor's CK addmm kernels intermittently return wrong results, which made test_max_autotune_addmm flaky on MI350 (#198909, #198910) and led the ROCm 10.1 bump (#196753) to skip the whole family. This adds -fno-associative-math to the CK compile flags for gfx950 only (scoped with -Xarch_), with no measurable performance change, and removes the 10.1 skip. On MI355X (ROCm 10.0) with a fresh inductor cache per run, pytest test/inductor/test_ck_backend.py -k test_max_autotune_addmm went from 4/4 runs failing to 20/20 passing.

Agent details (if applicable)

Claude helped investigate the failures, write the change, and draft this description; I reviewed all of it.

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben

On gfx950, inductor's CK addmm kernels can intermittently return wrong results. This made test_max_autotune_addmm flaky on MI350: two variants were disabled (pytorch#198909, pytorch#198910), and the ROCm 10.1 bump (pytorch#196753) skipped the whole family after the remaining bf16 variants failed on the MI350 shard.

This adds -fno-associative-math to the CK compile flags for gfx950 only, which avoids the problem with no measurable performance change. It is scoped with -Xarch_ so other offload archs are unaffected. It also removes the 10.1 skip.

Fixes pytorch#198909
Fixes pytorch#198910

## Test Plan

On MI355X (gfx950, ROCm 10.0), each run with a fresh inductor cache:

```
TORCHINDUCTOR_CACHE_DIR=$(mktemp -d) python -m pytest test/inductor/test_ck_backend.py -k test_max_autotune_addmm
```

Before: 4 of 4 runs failed (7 of 48 tests). After: 20 of 20 runs passed (240 tests). Not run on ROCm 10.1 or gfx942; PR CI with ciflow/trunk covers both.

This PR was authored with the help of Claude (AI assistant).
@pytorch-bot

pytorch-bot Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 35ec2da with merge base a1f5fd0 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: inductor module: rocm AMD GPU support for Pytorch labels Oct 7, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@pytorch-bot

pytorch-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/inductor
  • ciflow/torchtitan

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@jeffdaily jeffdaily added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 7, 2026
…smatch

Diagnostic for the mi350 amd-dpx failure of this test on this PR; to be reverted before landing. On a mismatch the assertion message adds: compiled and eager results each checked against an fp32 reference, whether a repeat call gives identical results, which 128x128 tiles the mismatches fall in, device PCI address and memory size, sysfs compute/memory partition and mtype_local, host boot time, and a 100-iteration cross-XCC coherence probe on the same partition.

Test Plan:
Injected two mismatching elements and called the report directly; it blamed the compiled side and listed both tiles. The addmm family passes with the merged test file on a DPX+NPS2 MI350X with the PR's CI wheel:
```
PYTORCH_TEST_WITH_ROCM=1 python -bb inductor/test_ck_backend.py -v -p no:xdist --use-pytest -x --reruns=2 -k test_max_autotune_addmm
```
12 passed.

Authored with Claude.
More diagnostics for the mi350 amd-dpx failure on this PR; to be reverted before landing. The mismatch report now also gives the driver, kernel and firmware versions, compiler path and version, the inductor ROCm config and effective compiler options, compiler-related environment, the mismatch pattern (column residues, diff range), how many of 50 further calls are wrong, and for the newest CK kernels in the inductor cache their compile flags plus a fingerprint of the compiled gfx950 code. A new gfx950-only test, test_triage_addmm_ck_flag, always prints (never fails) an A/B of the two CK candidates built with and without the gfx950 -fno-associative-math option, so the CI log shows how this host behaves with each build even when the addmm tests pass.

Test Plan:
On a DPX+NPS2 MI350X with this PR's CI wheel (torch 2.16.0a0+git1d1c6fa) both tests pass and the triage test reports 0/100 wrong calls with the option and 99/100 without it:
```
PYTORCH_TEST_WITH_ROCM=1 python -bb inductor/test_ck_backend.py -v -p no:xdist --use-pytest -k "test_triage_addmm_ck_flag or test_max_autotune_addmm_standalone_x_shape_2048_bfloat16"
```
The failure-path report was exercised by running the same tests with the option removed from the compiler options.

Authored with Claude.
The gfx950 workaround was passed as `-Xarch_gfx950 -fno-associative-math`. Clang applies an `-Xarch_<id>` option only when `<id>` equals the device target id exactly. On the mi350 CI runners, `--offload-arch=native` resolves to `gfx950:sramecc+:xnack-`, so the option was silently dropped and test_max_autotune_addmm still failed there. On hosts where native resolves to bare `gfx950` it applied.

The fix emits the option for all nine gfx950 spellings (sramecc and xnack each absent, + or -). Clang puts reordered features back into standard order before matching. The spellings that do not match give only "argument unused" warnings. The alternative was to replace `native` with the device's gcnArchName and key the flag on it. That would change the offload target for every ROCm arch and need a device query in the compile workers, so I did not take it.

Test Plan:
With `--offload-arch=native` replaced by `--offload-arch=gfx950:sramecc+:xnack-`, the CI failure reproduces on a gfx950 host before this change (49/50 calls wrong, and the ISA is identical to the CI runner's). After this change it gives 0/50 wrong and the fixed instruction forms. `clang -###` shows `-mreassociate` dropped from the device compile for every gfx950 spelling and kept for gfx942.
```
PYTORCH_TEST_WITH_ROCM=1 python -bb inductor/test_ck_backend.py -v -p no:xdist --use-pytest -k "test_max_autotune_addmm or test_triage_addmm_ck_flag"
```
13 passed.

Authored with Claude.
Reverts the diagnostics added in 1d1c6fa, bfea63d and 67538c2. They found the root cause fixed by the previous commit, and the CI run on 627a549 confirmed the fix on the mi350 runners. test_ck_backend.py is back to its state before those commits.

Test Plan:
```
PYTORCH_TEST_WITH_ROCM=1 python -bb inductor/test_ck_backend.py -v -p no:xdist --use-pytest -k test_max_autotune_addmm
```
12 passed with a fresh inductor cache on a gfx950 host.

Authored with Claude.
@jeffdaily
jeffdaily marked this pull request as ready for review October 30, 2026 15:33
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@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

dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…orch#200195)

## Linked issue or supporting maintainer

Supported by @jeffdaily
Fixes pytorch#198909
Fixes pytorch#198910

## BC-breaking?

No

## Summary (human written only)

On gfx950, inductor's CK addmm kernels intermittently return wrong results, which made `test_max_autotune_addmm` flaky on MI350 (pytorch#198909, pytorch#198910) and led the ROCm 10.1 bump (pytorch#196753) to skip the whole family. This adds `-fno-associative-math` to the CK compile flags for gfx950 only (scoped with `-Xarch_`), with no measurable performance change, and removes the 10.1 skip. On MI355X (ROCm 10.0) with a fresh inductor cache per run, `pytest test/inductor/test_ck_backend.py -k test_max_autotune_addmm` went from 4/4 runs failing to 20/20 passing.

## Agent details (if applicable)

Claude helped investigate the failures, write the change, and draft this description; I reviewed all of it.

Pull Request resolved: pytorch#200195
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…orch#200195)

## Linked issue or supporting maintainer

Supported by @jeffdaily
Fixes pytorch#198909
Fixes pytorch#198910

## BC-breaking?

No

## Summary (human written only)

On gfx950, inductor's CK addmm kernels intermittently return wrong results, which made `test_max_autotune_addmm` flaky on MI350 (pytorch#198909, pytorch#198910) and led the ROCm 10.1 bump (pytorch#196753) to skip the whole family. This adds `-fno-associative-math` to the CK compile flags for gfx950 only (scoped with `-Xarch_`), with no measurable performance change, and removes the 10.1 skip. On MI355X (ROCm 10.0) with a fresh inductor cache per run, `pytest test/inductor/test_ck_backend.py -k test_max_autotune_addmm` went from 4/4 runs failing to 20/20 passing.

## Agent details (if applicable)

Claude helped investigate the failures, write the change, and draft this description; I reviewed all of it.

Pull Request resolved: pytorch#200195
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>

This branch was previously deployed

1 inactive deployment
bedrock — 35ec2da4 Deployed Oct 30, 2026 by jeffdaily via analyze #19278
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triage-error ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor module: rocm AMD GPU support for Pytorch open source topic: not user facing topic category

Projects

None yet

4 participants