Repository navigation
[HIP] fix(mla): fold fp8 qlen 2 onto the qseqlen-4 kernel on gfx950 - #4872
JohnQin-llm wants to merge 1 commit into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags: |
There was a problem hiding this comment.
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 == 16to includemax_seqlen_q == 2when!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.
643f0c4 to
d5fbf0f
Compare
|
No activity for 15 days, so this is now labelled |
|
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. |
|
No activity for 15 days, so this is now labelled |
Motivation
On gfx950, an fp8 MLA decode with
gqa_ratio == 16and a 2-token query block hasno non-causal kernel:
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=2exists only ascausal=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 == 32branch already folds that length, andgqa * qlenstays inside the 64-lane tile (16x2 pads to 16x4, as 16x3 does).Padding is selection-only:
q_seq_lens_kernelis computed from the realmax_seqlen_q, not fromconfig_max_seqlen_q, so no extra query rows areprocessed.
Both masks fold, which retires
mla_a8w8_qh16_qseqlen2_gqaratio16*for thisshape. #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_fwddriven directly with the persistent schedulefrom
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:
causal=Trueerrorcausal=Falseerrorqseqlen2_gqaratio16_ps(causal only)qseqlen4_gqaratio16[_msk0]_v3_psAgainst 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:
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.