Skip to content

[HIP] fix(mla): fold fp8 qlen 2 onto the qseqlen-4 kernel on gfx950 - #4872

Open
JohnQin-llm wants to merge 1 commit into
mainfrom
mla-fp8-noncausal-qlen2
Open

JohnQin-llm wants to merge 1 commit into
mainfrom
mla-fp8-noncausal-qlen2

Conversation

@JohnQin-llm

@JohnQin-llm JohnQin-llm commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On gfx950, an fp8 MLA decode with gqa_ratio == 16 and a 2-token query block has
no non-causal kernel:

get_heuristic_kernel_mla: cannot get heuristic kernel!
  q_type:fp8 kv_type:fp8 gqa:16 ps:1 prefill:0 causal:0 qseqlen:2 lse:0 cprr:0

A missing kernel aborts the process rather than raising, so this takes the server
down. Every other block length works: the dispatch folds (gqa 16, qlen 3 or 4)
onto the qseqlen-4 kernel, but the list skips 2, so the lookup falls through to
the exact-match table where Gqa=16 qSeqLen=2 exists only as causal=1.

vLLM hits this with a Kimi-K3 DSpark draft at num_speculative_tokens=1.

Technical Details

Widen the gqa-16 fold from {3, 4} to {2, 3, 4}.

The neighbouring gqa_ratio == 32 branch already folds that length, and
gqa * qlen stays inside the 64-lane tile (16x2 pads to 16x4, as 16x3 does).
Padding is selection-only: q_seq_lens_kernel is computed from the real
max_seqlen_q, not from config_max_seqlen_q, so no extra query rows are
processed.

Both masks fold, which retires mla_a8w8_qh16_qseqlen2_gqaratio16* for this
shape. #3013 proposed the same widening in May, to work around a precision issue
reported in that kernel. Those binaries were replaced in 1304014 (2026-06-29)
and I do not see the issue on the current ones, so this is not a bug fix for the
causal path -- it is one fold rule instead of two, at equal cost.

Test Plan

gfx950 (MI355X). mla_decode_fwd driven directly with the persistent schedule
from get_mla_metadata_v1; B=2, 16 heads, kv_lora 512, rope 64, page_size 1.
Reference is fp32 over the same dequantized fp8 values, so it isolates the kernel
from input quantization. Each output is compared against both a causal and a
non-causal reference, at ctx [16, 24] so the two actually differ.

Test Result

fp8, gqa 16, qlen 2:

before after
causal=True error 1.46e-02 1.46e-02
causal=False error no kernel 1.39e-02
kernel selected qseqlen2_gqaratio16_ps (causal only) qseqlen4_gqaratio16[_msk0]_v3_ps

Against the opposite reference both land at 1.41e-01, so each runs the mask it
was asked for. The causal error is unchanged to three digits despite moving to a
different kernel.

Timing, causal qlen 2, direct qseqlen-2 kernel against the folded path:

B / ctx 512 4096
1 72.4 -> 75.1 us 72.8 -> 74.2 us
8 72.5 -> 85.0 us 72.1 -> 73.2 us
32 72.8 -> 73.3 us 72.5 -> 73.3 us
128 72.5 -> 73.6 us 80.1 -> 78.2 us

Flat either way; the 85.0 is a single outlier in an otherwise 72-75 us band.

Block lengths 1, 3, 4 and 8 are unaffected, and bf16 takes a different fold
branch entirely.

@JohnQin-llm
JohnQin-llm requested review from a team and a lite review from Copilot August 20, 2026 02:36
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 4872 --add-label <label>

PR title tags:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf] and op tags like [MLA] are left untouched. Add the no-auto-title label to opt this PR out of title tagging.

@github-actions github-actions Bot changed the title fix(mla): fold fp8 non-causal qlen 2 onto the qseqlen-4 kernel on gfx950 [HIP] fix(mla): fold fp8 non-causal qlen 2 onto the qseqlen-4 kernel on gfx950 Aug 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes kernel dispatch for fp8 MLA decode on gfx950 in the non-causal path when gqa_ratio == 16 and max_seqlen_q == 2, by folding that case onto the existing qseqlen-4 kernel so the heuristic lookup no longer falls through and fails.

Changes:

  • Extend the gfx950 fp8/fp8 persistent folding rule for gqa_ratio == 16 to include max_seqlen_q == 2 when !config_causal.
  • Keep the causal (config_causal == 1) qlen=2 path unchanged, preserving existing kernel selection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

On gfx950 an fp8 decode with gqa_ratio 16 and a 2-token query block has no
non-causal kernel, so mla_decode_fwd(..., causal=False) aborts the process in
get_heuristic_kernel_mla. Every other block length works: the dispatch folds
(gqa 16, qlen 3 or 4) onto the qseqlen-4 kernel, but the list skips 2, so the
lookup falls through to the exact-match table where Gqa=16 qSeqLen=2 exists
only as causal=1.

Widen that fold from {3, 4} to {2, 3, 4}. The neighbouring gqa_ratio == 32
branch already folds the length, gqa * qlen stays inside the 64-lane tile, and
padding is selection-only -- q_seq_lens_kernel comes from the real max_seqlen_q,
so no extra query rows are processed.

Both masks fold, which retires mla_a8w8_qh16_qseqlen2_gqaratio16* for this
shape. Verified on MI355X: non-causal qlen 2 goes from no kernel to 1.39e-02
against a non-causal reference and 1.41e-01 against a causal one, while causal
qlen 2 keeps its 1.46e-02 on the new kernel and its timing stays in the same
72-75 us band across batch 1/8/32/128 and ctx 512/4096.
@JohnQin-llm JohnQin-llm changed the title [HIP] fix(mla): fold fp8 non-causal qlen 2 onto the qseqlen-4 kernel on gfx950 fix(mla): fold fp8 qlen 2 onto the qseqlen-4 kernel on gfx950 Aug 20, 2026
@JohnQin-llm
JohnQin-llm force-pushed the mla-fp8-noncausal-qlen2 branch from 643f0c4 to d5fbf0f Compare August 20, 2026 02:52
Copilot AI review requested due to automatic review settings August 20, 2026 02:52
@github-actions github-actions Bot changed the title fix(mla): fold fp8 qlen 2 onto the qseqlen-4 kernel on gfx950 [HIP] fix(mla): fold fp8 qlen 2 onto the qseqlen-4 kernel on gfx950 Aug 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Oct 7, 2026
@zufayu
zufayu requested review from shengnxu and removed request for amd-ruitang3 October 9, 2026 05:51
@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Oct 10, 2026
@shengnxu

Copy link
Copy Markdown
Collaborator

Thanks for the causal/non-causal accuracy comparison and the before/after timing table. Please add the missing reproducibility details: exact container image tag/digest, GPU/ROCm/PyTorch versions, baseline/head SHAs, and copy-paste build/accuracy/benchmark commands with the scripts used.

Since causal qlen=2 also switches kernels, please include a reproducible regression matrix covering both masks, representative batch/context/page/tail/split cases, and neighboring qlens. Define the error metric and tolerance, and attach the full results.

Please also repeat the timing measurements with warmup/repetition counts and median/dispersion. In particular, B=8, ctx=512 changes from 72.5 to 85.0 us (about +17.2%); a repeated comparison is needed to distinguish an outlier from a regression. Include current non-causal latency and mark its old no-kernel baseline as N/A.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants