Skip to content

[ROCm] Drop CK GEMM instances with K1 >= 32 on pre-gfx950 targets - #203869

Closed
pablo-garay wants to merge 3 commits into
pytorch:mainfrom
pablo-garay:rocm-ck-filter-k1-32-pre-gfx950
Closed

pablo-garay wants to merge 3 commits into
pytorch:mainfrom
pablo-garay:rocm-ck-filter-k1-32-pre-gfx950

Conversation

@pablo-garay

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

Copy link
Copy Markdown
Contributor
  • Passes lint (spin fixlint)
  • Added/updated tests
  • Updated documentation (if applicable)
  • Included benchmark results (for PRs impacting perf)

Linked issue or supporting maintainer

Supported by @jeffdaily

Tracking issues: https://github.com/jithunnair-amd/sandbox/issues/11439, https://github.com/jithunnair-amd/sandbox/issues/11440, https://github.com/jithunnair-amd/sandbox/issues/11441, https://github.com/jithunnair-amd/sandbox/issues/11442

BC-breaking?

No

Summary (human written only)

Fix TestCKRowwiseScaleCUDA.test_singleton_column_scale on MI300: CK compiles GEMM instances with AK1/BK1 >= 32 to an empty kernel body on anything but gfx950, but its IsSupportedArgument still accepts them, so on gfx942 they launch without writing the output, benchmark as fastest and win autotuning. Filter them out in CKGemmTemplate.filter_op with the same condition CK uses.

Agent details (if applicable)

The root-cause analysis (CI logs plus CK source at the pinned commit e2daf44), the code change and this description were drafted with an AI agent. The evidence is that on MI300 the mismatch is bit-identical across reruns that selected different CK instances (max abs diff 388694540288.0 at (359, 2099) under JIT, and an all-zero output under AOTI). That points to an output that is never written, not to a numerical error. GridwiseGemmMultiD_xdl_cshuffle_v3::IsValidCompilationParameter returns false for K1 >= 32 when __gfx950__ is not defined, and the pinned fp8 RCR library has 57 K1=32 and 43 K1=16 instances, so gfx942 keeps 43 candidates. Only ruff check and ruff format were run on the changed file. This was not run on a GPU.

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

CK's GridwiseGemmMultiD_xdl_cshuffle_v3::IsValidCompilationParameter returns
false for AK1 >= 32 or BK1 >= 32 unless the device pass is gfx950, so on
gfx942 those instances compile to an empty kernel body. The host-side
IsSupportedArgument does not check this, so the instance launches, returns
success, and never writes the output. Being empty, it also benchmarks as the
fastest choice and wins autotuning.

The CK fp8 library offers 57 such instances for the RCR layout (and 43 with
K1 = 16), so on MI300 TestCKRowwiseScaleCUDA.test_singleton_column_scale
selects one and returns whatever was in the output buffer: zeros under AOTI,
stale data (up to ~4e11) under JIT. The mismatch is bit-identical across
reruns that picked different instances, which is what an unwritten output
looks like. MI350 (gfx950) builds the kernel body and passes.

Filter these instances in CKGemmTemplate.filter_op using the same condition
CK uses, so autotuning only sees instances that do work on the device.

Test Plan:

```
ruff check torch/_inductor/codegen/rocm/ck_universal_gemm_template.py
ruff format --diff torch/_inductor/codegen/rocm/ck_universal_gemm_template.py
```

Not run on a GPU; the MI300 regression is
PYTORCH_TEST_WITH_ROCM=1 python test/inductor/test_ck_backend.py TestCKRowwiseScaleCUDA

Signed-off-by: Pablo Garay <[email protected]>
@pytorch-bot

pytorch-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

🔗 Helpful Links

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

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

❌ 2 Cancelled Jobs, 1 Unrelated Failure

As of commit 8be9e24 with merge base 557419b (image):

NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following job failed, but the AI CI Advisor judged the failure not to be evidence against this change:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

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 Nov 6, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 6, 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 Nov 6, 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.

@jithunnair-amd jithunnair-amd added ciflow/trunk Trigger trunk jobs on your pull request ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/inductor-rocm-mi300 Trigger "inductor" config CI on ROCm MI300/MI325 labels Nov 6, 2026
The K1 >= 32 filter compared only the current device's arch. Inductor compiles CK kernels for config.rocm.arch when it is set (AOTI packaging, cross-compiling for gfx942 on a gfx950 host, or a multi-arch list), so the empty-body instances could still be selected for a non-gfx950 target. Derive the targets the same way compile_command.py does and keep K1 >= 32 instances only when every target is gfx950.

Authored with Claude.
@jeffdaily

Copy link
Copy Markdown
Collaborator

I pushed a small follow-up commit (91e6671) on top of yours so the filter also covers cross-compiles.

My agent came up with this analysis, but I've read and approved it.

The filter compared only the current device (rocm_gfx_arch()), but inductor compiles CK kernels for config.rocm.arch when it is set (AOTI packaging, cross-compiling for gfx942 on a gfx950 host, or a multi-arch list). In those cases the K1 >= 32 instances, which compile to an empty kernel on non-gfx950 targets, could still be selected. The commit keeps them only when every target is gfx950, falling back to the current device when config.rocm.arch is empty.

Validated on MI300X: all 4 test_singleton_column_scale variants pass with CK kernels winning autotuning, and test_ck_backend.py has no new failures. Calling filter_op on all 5176 library ops with config.rocm.arch set to ["gfx950"], ["gfx942"], ["gfx942", "gfx950"] and [] keeps the 516 K1 >= 32 instances only for ["gfx950"]; the K1 < 32 set is unchanged in every case.

@jeffdaily
jeffdaily marked this pull request as ready for review November 9, 2026 20:08
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Nov 9, 2026
inductor's set linter rejects builtin sets. Same logic: drop K1 >= 32 instances when any compile target is not gfx950.

Authored with Claude.
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team

Raised by workflow job

@jeffdaily jeffdaily added the release notes: rocm mandatorylabel label Nov 10, 2026
@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 3 checks: Lint / Test collect_env (older_python_version, linux.24_04.4x), Lint / Test collect_env (without_torch, linux.24_04.4x), Lint / Test collect_env (with_torch, linux.24_04.4x)

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

bot-triaged This is a label only to be used by the auto triage bot ciflow/inductor ciflow/inductor-rocm-mi300 Trigger "inductor" config CI on ROCm MI300/MI325 ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 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 release notes: rocm mandatorylabel triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants