Skip to content

[AMD] Pad QSA MQA decode Q-heads to 16 for ROCm MFMA - #38875

Merged
HaiShaw merged 1 commit into
sgl-project:mainfrom
yichiche:amd/qsa-mqa-decode-head-align-rocm
Sep 22, 2026
Merged

HaiShaw merged 1 commit into
sgl-project:mainfrom
yichiche:amd/qsa-mqa-decode-head-align-rocm

Conversation

@yichiche

@yichiche yichiche commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Qwen3.8-Flash-Next cannot serve on ROCm: the TileLang QSA MQA decode kernel fails to compile on gfx950.

tilelang_qsa_mqa_decode pads the Q-head dimension up to a multiple of 8, which is the CUDA MMA requirement. ROCm MFMA requires 16. With indexer_n_heads=4 the kernel is asked for N=8 and TVM aborts during layout inference:

tvm.error.InternalError: Check failed: (N % kNPerWarp == 0) is false: N must be divisible by 16, but got 8

In a real server run this does not surface as the check above. TileLang catches the build failure and retries the outer function through its eager-style path, which re-generates the source without the closure parameters, so the user-visible error is a confusing signature mismatch:

TypeError: make_closure.<locals>._tilelang_qsa_mqa_decode_kernel.<locals>._tilelang_qsa_mqa_decode_kernel()
missing 2 required positional arguments: 'heads' and 'head_dim'

The server dies with SIGQUIT at the first decode step.

Modifications

python/sglang/srt/layers/attention/qsa/mqa.py — select the head-padding alignment per platform: 16 on HIP, 8 elsewhere. The padding is zero-fill and the indexer logit is a weight-free sum over heads, so the padded lanes contribute nothing and the result is unchanged on both platforms. The CUDA path keeps its existing alignment of 8 exactly as before.

This change is self-contained in one file and does not depend on any other PR.

Accuracy Tests

Isolated correctness check of tilelang_qsa_mqa_decode against torch_qsa_mqa_decode on gfx950 (heads=4, head_dim=128, page_size=8), comparing only the finite (unmasked) logits:

Platform Alignment Result
MI355X (gfx950) 16 (this PR) max abs diff vs torch reference 4.77e-07
MI355X (gfx950) 8 (before) fails to compile — N must be divisible by 16

End-to-end on 8x MI355X with the released BF16 Qwen3.8-Flash-Next checkpoint (--tp-size 8 --attention-backend aiter --page-size 32 --chunked-prefill-size 16384). This PR is one of the changes required to reach a serving state; the numbers below are for the full ROCm enablement set:

Config GSM8K (200 examples) Output throughput
BF16 baseline 0.980 936 tok/s
BF16 + EAGLE MTP (3 steps) 0.975 1603 tok/s, accept length 3.16

No CUDA behavior change, so no CUDA accuracy re-run is required.

Speed Tests and Profiling

Not a performance change — this is a compile-time correctness fix that makes the kernel buildable on ROCm. The zero-padded lanes add 8 extra columns of MFMA work per decode row, which is inside the same MFMA tile that the hardware would issue for N=16 anyway.

Checklist


CI States

Latest PR Test (Base): ❌ Run #34474932925
Latest PR Test (Extra): ❌ Run #34474951413
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.

@yichiche yichiche added the run-ci CI: run the baseline test suite on this PR label Sep 10, 2026

@1am9trash 1am9trash left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turn tilelang padding from 8 to 16 for rocm MFMA need.
Guard by is_hip(). No impact on nv code path.

@HaiShaw HaiShaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. HIP specific

@HaiShaw
HaiShaw merged commit 31b577b into sgl-project:main Sep 22, 2026
464 of 519 checks passed
detain added a commit to detain/sglang that referenced this pull request Sep 28, 2026
Brings in 113 upstream commits (7ad55e4..d34f7b2). Upstream now
contains three stack PRs as merged: sgl-project#40501, sgl-project#40175, sgl-project#33778; every line
their squashes add is already present in the stack.

Conflicts resolved:
- arg_groups/fields/memory.py, managers/cache_controller.py: union of the
  stack's fast_file backend (sgl-project#39880) and upstream's tensorcast backend.
- layers/attention/qsa/mqa.py: keep the stack's SM120 Triton imports and
  fp8 _scoring_dtype path; adopt upstream's ROCm 16-wide head alignment
  (sgl-project#38875) and its is_hip import.
- models/qwen4_exp.py: all six hunks are stack-only additions (PLE host
  staging, CUDA-graph prewarm, replay prepare) against upstream's final
  sgl-project#40501; kept ours. The merged file equals the pre-merge stack version.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
amd-cgilli added a commit to amd-cgilli/sglang that referenced this pull request Nov 10, 2026
…age tables

- threads=256 and groups_per_cta=4 were tuned on MI355X only; other GPUs keep the
  default launch (128 threads, fixed CTAs per row). The 16-wide head padding stays
  on all ROCm GPUs, as on main (MFMA width, sgl-project#38875).
- An empty page table gave the page-table-wide grid zero CTAs
  (hipErrorInvalidConfiguration); return the -inf logits early.
- Fix the stale grid comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants