Repository navigation
[ASM] [HIP] [CI] [MLA] [Bugfix] Fix and optimize the gfx942 MLA decode/prefill kernels - #6277
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
d292fe2 to
55c7b69
Compare
jamesETsmith
left a comment
There was a problem hiding this comment.
Huge thanks for this @jonahbernard! Two nits:
- First, I think we should add some tests to AITER to ensure that we don't regress here and run into this wrapping bug again in the future if the kernels change.
- Second, about the description itself, in the speedup section you refer to the new/old times as the speedup. Maybe it's me, but I usually think of speedup as old/new (i.e. we want the number > 1.0). I think it might be easier on reviews if you showed the % faster (old/new - 1.0)
55c7b69 to
32ceb1c
Compare
Thank you @jamesETsmith for the review. I fixed both of those. |
Regarding testing, please check my PR which is now merged in #6223, I've added test cases for this particular issue there. CC: @jamesETsmith |
yes thank you for those tests. I added more tests to them. |
There was a problem hiding this comment.
LGTM, thanks for adding the tests @jonahbernard! I don't have perms to really approve the PR, but marking it as approved by me to show all my requests were addressed.
|
@aiter-bot review |
ROCm/aiter PR #6277 — [ASM] [HIP] [MLA] [Bugfix] Fix and optimize the gfx942 MLA decode/prefill kernelsReplaces 20 of the 26 gfx942 MLA asm decode/prefill kernels with rebuilt binaries that address KV through 64-bit global addresses (fixing silent wrong-KV reads once a KV pool passes 4 GiB) plus wait/race/overflow/NaN fixes, adds a dedicated qlen-1 kernel for 32-head bf16 decode with its mla_asm.csv row and an asm_mla.cu dispatch tweak that selects it, and grows op_tests/test_mla_ltx.py from 16 to 96 gfx942 cases. Review (advisory): 🔴 HIGH RISK 🔴 [verified] csrc/py_itfs_cu/asm_mla.cu:932 picks the new qSeqLen=1 routing for gqa_ratio==32 bf16 non-persistent decode whenever max_seqlen_q==1, with no gfx942 gate, but the qSeqLen=1 row was added only to hsa/gfx942/mla/mla_asm.csv — hsa/gfx950/mla/mla_asm.csv has only the qSeqLen=0 row for that combo and get_heuristic_kernel_mla exact-matches qSeqLen, so on gfx950 every 32-head bf16 non-persistent qlen-1 mla_decode_fwd (DeepSeek TP4; the very path test_mla.py -n 32,1 drives) now dies in the "cannot get heuristic kernel" check where it previously dispatched to MLA_A16W16_1TG_4W_16mx4_32nx1_Coex0_Msk1_QH16.co. Author must gate the new selection on gfx942 (or add a qSeqLen=1 row and kernel for gfx950) and run test_mla.py -n 32,1 on gfx950. |
|
Where that review came from — I ran the bot on your PR to show what it does. It is not an automatic hook; nothing reviews your PR unless somebody asks. Any reviewer on the aiter allowlist can ask for one, on any PR including their own. The trigger is a comment containing the words below — shown quoted here, because quoted lines deliberately do not trigger it:
Feedback on the review itself is welcome; it is how the rules get better. |
|
This is big work on fixing 64git addr, btw, i think you can also fix some gfx950 co files at the same time, because some of the memory bound gfx950 mla kernel is sharing the same source asm file, while just re-compiled for gfx950, you can find the recompiled list by names or by searching gfx942 wmma instruction under gfx950 directory, then compile them with gfx950 compiler, any issue please connect with @minmengdie |
…refill kernel too mla_asm_decode_remap only forced ps=0 (and thus the masked-prefill-kernel selection for causal qlen>1) on gfx942, so gfx950 kept running the plain persistent decode kernel for this case, which has no per-query causal mask. Meanwhile mla.py's masked_qh128_bf16 (which drives CAUSAL_PER_QUERY for the stage-2 reduction) was already set for both gfx942 and gfx950, so stage 2 believed splits past each query's causal horizon were skipped on gfx950 too, even though stage 1 never skipped them there. gfx950 already ships and dispatches mla_pfl_bf16_a16w16_causal_subQ128_mqa128.co (hsa/gfx950/mla/mla_asm.csv) with the 64-bit KV addressing fix from this PR, so extending the gate just routes to an existing, already-tested kernel.
Item 1: That will be done in a follow-up Thanks! |
|
Thanks Jonah. Item 2 is in. gfx950 now uses the same 128-head bf16 path as Item 1 as a follow-up is OK for this PR. It is not a nit: Item 5: the Self-Review text is there, but aiter-bot still I can approve the host/HIP/test side. Not the .co files. |
Hi @ChuanLi1101 thank you for the comment.
Thanks! |
|
ci failed |
…masked prefill kernel too" This reverts commit 2cd4f38. Forcing ps=0 for gfx950 128-head bf16 decode breaks every persistent 128-head bf16 decode on gfx950. The gfx950 block at the end of mla_asm_decode_remap still tests `persistent`, not `ps`, and remaps the shape to gqa 32 / qSeqLen 4. The lookup then asks for (gqa 32, ps 0, qSeqLen 4), which hsa/gfx950/mla/mla_asm.csv does not have, so test_mla_persistent.py, test_mla_persistent_round_robin.py and test_mla_sparse.py fail on MI35X with "cannot get heuristic kernel! ... gqa:32 ps:0 ... qseqlen:4". The CAUSAL_PER_QUERY concern does not need this change. masked_qh128_bf16 only feeds the stage-2 reduction in the non-persistent branch of mla_decode_fwd. That branch passes num_kv_splits_indptr, so persistent is false and ps is already 0 on gfx950: causal qlen > 1 already selects mla_pfl_bf16_a16w16_causal_subQ128_mqa128 there. Persistent decode reduces with mla_reduce_v1 and runs the qh32_qseqlen4 *_ps kernels, which have causal and msk0 variants.
|
I pushed 2fb0a3a. This commit reverts 2cd4f38. 2cd4f38 caused the MI35X failures in runs 45291840508 and 45646607177. These three tests fail:
Each test stops with this error:
Cause
Why Item 2 does not need 2cd4f38Item 2 asks if stage 1 and stage 2 skip the same KV splits on gfx950.
Test resultsI ran the tests on MI355X with 128 heads, bf16 Q and KV, and qlen 2. Another job used the same GPU. These runs check only correctness.
The counts include only the checks for 128 heads. The new CI run 45723741241 tests the full files. |
get_gfx() returns the last GPU_ARCHS entry. With GPU_ARCHS="gfx950;gfx942" the gate read gfx942 on a gfx950 GPU and skipped the test; with "gfx942;gfx950" it would run the gfx950-only kernel on gfx942. get_gfx_runtime() reads the arch from rocminfo and ignores GPU_ARCHS.
|
@fangche123 @zufayu Can this be merged now? Thanks! |
Take main's rebuilt qseqlen2 .co files from #6277. They already fix both LDS races, so this branch keeps only the qlen 2 regression check. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
Replace 20 (out of 26) gfx942 MLA kernels with fixed and optimized builds and add one new kernel (32 heads, qlen 1).
Motivation
The main motivation for this PR is a 4 GiB addressing bug in the gfx942 ASM MLA kernels. They compute the KV byte offset in 32 bits, so when a KV row is more than 4 GiB past the start of the KV tensor (about 3.7 M token slots for bf16 KV, 7.5 M for fp8), the offset wraps. The kernel then silently reads another token's KV and the output is wrong. In SGLang this shows up with unified KV memory, where all layers share one tensor. It also happens with per-layer KV buffers once a layer's pool is larger than 4 GiB and the cache fills past that point. This PR fixes it in 20 of the 26 gfx942 ASM MLA kernels by loading KV through 64-bit global addresses.
Related issues and PRs:
#5826
#6223
#5893
#5765
This PR overlaps with #6223 on 3 kernels. I recommend merging #6223 and then this PR second. Both PRs fix the 4 GB bug, but this PR speeds up the kernels and fixes some other bugs as well:
mla_a16w16_qh16_m16x4_n16x1_coex0_mask1_ps: bf16, 16 heads, persistentpage_id × row_stridecomputed in 32 bits; pools > 4 GiB read other tokens' KV. Now 64-bit global addresseskv_start≥ 2^30mla_dec_stage1_bf16_a16w16_subQ128_mqa128: bf16 decode, 128 rowsmla_dec_stage1_bf16_a16w16_subQ16_mqa16: bf16 decode, 16 rowsv_mul_u32_u24(24 bits, wraps even earlier). Now 64-bit global addresseskv_indptr≥ 2^30Technical Details
I fixed the 4 GB addressing bug each of these 20 kernels, fix other bugs discovered in each of them while working on the 4 GB fix, and optimized them when optimizations were discovered while fixing the 4 GB bug.
New kernel MLA_A16W16_1TG_4W_32mx1_16nx1_Coex0_Msk1_QH16_Q1 (bf16, 32 heads, qlen 1). The fix for the existing 32mx1 kernel makes it handle 2 causal query tokens per workgroup, which is needed for correct qlen ≥ 2 (spec-decode verify). Plain decode (qlen 1) doesn't need that path, so it gets its own kernel without the multi-token causal handling. That kernel takes 0.79–0.85× the old time. It has the same grid and kernel arguments as the 32mx1 kernel. The new mla_asm.csv row is qSeqLen = 1, and asm_mla.cu now passes qSeqLen = 1 when max_seqlen_q == 1. Every other qlen still goes to the fixed 32mx1 kernel.
Bugs fixed in each original kernel:
MLA_A16W16_1TG_4W_32mx1_16nx1_Coex0_Msk1_QH16(+ new_Q1): bf16, 32 headskv_indptr≥ 2^30; LSE base carry; split buffernum_recordswraps at S = 32768MLA_A16W16_1TG_4W_64mx1_16nx1_Coex0_Msk1_QH16: bf16, 64 headskv_indptr≥ 2^30;num_records; split-data offset at S ≥ 32768; LSE base carryvmcntwaitmla_a16w16_qh16_m16x4_n16x1_coex0_mask1: bf16, 16 headskv_indptr≥ 2^30; LSE base carrymla_a16w16_qh16_m16x4_n16x1_coex0_mask1_ps: bf16, 16 heads, persistentkv_start≥ 2^30mla_a16w16_qh16_m32x4_n16x1_coex0_mask1: bf16, 16 heads, qlen ≥ 5num_recordswraps from row 233,017mla_pfl_bf16_a16w16_causal_subQ16_mqa16: bf16 causal prefill, 16 rowsmla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps: bf16 Q, fp8 KV, persistentlgkmcntwait (latent on MI300X, but the ISA requires the wait)kv_start≥ 2^30 (both reachable through aiter); partial offset ≥ 2^17 rowsmla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps_page64_ds32: bf16 Q, fp8 KV + block scales, page 64lgkmcntwaitkv_startoffsetsmla_a8w8_qh128_m32x4_n16x2_msk0_ps: fp8, 128 heads, persistentkv_end < kv_start(CUDA-graph padding) faulted: the unsigned "no KV" check saw a huge page countkv_indptr≥ 2^30; output offset (rows ≥ 32768 wrote row − 32768); partial offsetmla_a8w8_qh128_m32x4_n16x2_msk1: fp8, 128 heads, causalkv_indptr≥ 2^30mla_a8w8_qh16_qseqlen1_gqaratio16: fp8, 16 heads, qlen 1mla_a8w8_qh16_qseqlen1_gqaratio16_ps: fp8, 16 heads, qlen 1, persistentmla_a8w8_qh16_qseqlen2_gqaratio16: fp8, 16 heads, qlen 2mla_a8w8_qh16_qseqlen2_gqaratio16_ps: fp8, 16 heads, qlen 2, persistentmla_a8w8_qh64_qseqlen4_gqaratio16: fp8, qlen 3–4mla_a8w8_qh64_qseqlen4_gqaratio16_ps: fp8, qlen 3–4, persistent, pagedkv_scalemissing from the final normalization, so outputs were scaled wrong whenever the KV scale is not 1mla_dec_stage1_bf16_a16w16_subQ128_mqa128: bf16 decode, 128 rowsmla_dec_stage1_bf16_a16w16_subQ16_mqa16: bf16 decode, 16 rowskv_indptr≥ 2^30mla_dec_stage1_bf16_a16w16_subQ16_mqa16_ps: bf16 decode, 16 rows, persistentkv_start≥ 2^30mla_pfl_bf16_a16w16_causal_subQ128_mqa128: bf16 causal prefill, 128 rowsnum_records: Q wrapped from row 29,128 and the bf16 output from row 32,768Test Plan
Comprehensive testing was done on MI300:
More details on the new AITER tests:
Extends op_tests/test_mla_ltx.py on gfx942 from #6223's 16 BF16 cases (16/128 heads, qlen 1) to 96 cases (about 11 s in the default CI run) that launch all 21 changed kernels: 8/32/64 heads, qlen 1–8 against a causal reference, fp8 and bf16-Q/fp8-KV, ds32 page-64 KV, and a prefill mode through mla_prefill_fwd, all placing KV rows below, across and above the 4 GiB boundary, plus a split-KV case.
Speed benchmarking:
MI300X:
MLA_A16W16_1TG_4W_32mx1_16nx1_Coex0_Msk1_QH16_Q1: bf16, 32 heads, qlen 1MLA_A16W16_1TG_4W_32mx1_16nx1_Coex0_Msk1_QH16: bf16, 32 heads, qlen ≥ 2 (now causal)MLA_A16W16_1TG_4W_64mx1_16nx1_Coex0_Msk1_QH16: bf16, 64 headsmla_a16w16_qh16_m16x4_n16x1_coex0_mask1: bf16, 16 headsmla_a16w16_qh16_m16x4_n16x1_coex0_mask1_ps: bf16, 16 heads, persistentmla_a16w16_qh16_m32x4_n16x1_coex0_mask1: bf16, 16 heads, qlen ≥ 5mla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps: bf16 Q, fp8 KV, persistentmla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps_page64_ds32: bf16 Q, fp8 KV + block scales, page 64mla_a8w8_qh128_m32x4_n16x2_msk0_ps: fp8, 128 heads, persistentmla_a8w8_qh128_m32x4_n16x2_msk1: fp8, 128 heads, causalmla_a8w8_qh16_qseqlen1_gqaratio16: fp8, 16 heads, qlen 1mla_a8w8_qh16_qseqlen1_gqaratio16_ps: fp8, 16 heads, qlen 1, persistentmla_a8w8_qh16_qseqlen2_gqaratio16: fp8, 16 heads, qlen 2mla_a8w8_qh16_qseqlen2_gqaratio16_ps: fp8, 16 heads, qlen 2, persistentmla_a8w8_qh64_qseqlen4_gqaratio16: fp8, qlen 3–4mla_a8w8_qh64_qseqlen4_gqaratio16_ps: fp8, qlen 3–4, persistent, pagedmla_dec_stage1_bf16_a16w16_subQ128_mqa128: bf16 decode, 128 rowsmla_dec_stage1_bf16_a16w16_subQ16_mqa16: bf16 decode, 16 rowsmla_dec_stage1_bf16_a16w16_subQ16_mqa16_ps: bf16 decode, 16 rows, persistentmla_pfl_bf16_a16w16_causal_subQ128_mqa128: bf16 causal prefill, 128 rowsmla_pfl_bf16_a16w16_causal_subQ16_mqa16: bf16 causal prefill, 16 rows¹ The original was not causal and wrote less split data per workgroup (~16 KiB of distinct data vs 128 KiB for the correct causal output). On small shapes with many splits that write dominates.
² The 64-bit KV addressing needed for KV pools over 4 GiB costs ~0.5–1.5 % on these memory-bound shapes.
MI355X:
MLA_A16W16_1TG_4W_64mx1_16nx1_Coex0_Msk1_QH16: bf16, 64 heads, qlen ≥ 2mla_a16w16_qh16_m16x4_n16x1_coex0_mask1: bf16, 16 heads, qlen 2–4mla_a16w16_qh16_m32x4_n16x1_coex0_mask1: bf16, 16 heads, qlen ≥ 5mla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps: bf16 Q, fp8 KV, persistentmla_a8w8_qh128_m32x4_n16x2_msk0: fp8, 128 heads, non-causal (new on gfx950)mla_a8w8_qh128_m32x4_n16x2_msk1: fp8, 128 heads, causalmla_a8w8_qh16_qseqlen2_gqaratio16: fp8, 16 heads, qlen 2mla_a8w8_qh16_qseqlen2_gqaratio16_ps: fp8, 16 heads, qlen 2, persistentmla_dec_stage1_bf16_a16w16_subQ128_mqa128: bf16 decode, 128 rowsmla_dec_stage1_bf16_a16w16_subQ16_mqa16: bf16 decode, 16 rowsmla_pfl_bf16_a16w16_causal_subQ128_mqa128: bf16 causal prefill, 128 rowsmla_pfl_bf16_a16w16_causal_subQ16_mqa16: bf16 causal prefill, 16 rowsAITER test results:
1. 4 GiB regression test:
op_tests/test_mla_ltx.py(extended)MI300X:
qh16_bf16_q1qh128_bf16_q1qh16_bf16_q4qh16_bf16_q8qh128_bf16_q8qh32_bf16_q1qh32_bf16_q2qh64_bf16_q2qh8_bf16_q2qh16_a16w8_q1qh16_fp8_q1qh16_fp8_q2qh16_fp8_q4qh128_fp8_q1qh16_ds32_q1/q2/q4qh32_bf16_q1)MI355X:
ltx_bf16_fp8kv_ps(bf16 Q, fp8 KV, PS)a16w8 mask1_ps)ltx_bf16_h32_h64_nps(32 heads qlen 1, 64 heads qlen 2)64mx1at qlen 2qh8_fp8_q1_ps,qh16_fp8_q2_ps,qh32_fp8_q{1,2,4}_nps,qh8_fp8_q4_nps,qh8_bf16_q{1,2}_ps,bf16_fp8kv_nps)mla_asm.csvrow, mostly the LSE-on half of a run) or "nhead=8 and max_seqlen_q=1 not supported". Inqh16_fp8_q2_psthe PR'sqseqlen2_psruns and passes the LSE-off half firstPR kernels launched by ltx:
subQ16,subQ128,coex0_mask1,m32x4,64mx1,qseqlen2,qseqlen2_ps,msk1anda16w8 mask1_ps(9).2. CI-equivalent run: the MLA op_tests aiter CI runs on MI300X
MI300X:
test_mla.py(default)test_mla.pyCI extra 1test_mla.pyCI extra 2test_mla.pyCI extra 3test_mla.pyCI extra 4test_mla.pyCI extra 5test_mla.pyCI extra 6test_mla_persistent.pytest_mla_persistent_round_robin.pytest_mla_decode_pagesize64.pytest_mla_prefill_ps.pytest_mla_reduce.pytest_flydsl_mla_reduce.pytest_mla_decode_gate.pytest_mla_sparse.pytest_mla_stage2_merge.pytest_mla_flydsl.pytest_mla_ltx.pytest_mla_v4_nm.pytest_mla_v4_kargpreld.pytest_mla_v40_persistent.pyMI355X:
test_mla.py(default)coex0_mask1,subQ128,subQ16,pfl subQ128,pfl subQ16test_mla.py× 6 CI extra invocationssubQ16,pfl subQ16test_mla.pygfx950 extra (new in this PR):-c 21 8192 -b 1 4 -n 128,2 128,4 -d fp8 -kvd fp8 --no-causalmsk0test_mla_persistent.pya16w8 mask1_ps,qseqlen2_pstest_mla_sparse.pya16w8 mask1_pstest_mla_v4_nm.pytest_mla_persistent_round_robin,test_mla_decode_pagesize64,test_mla_prefill_ps,test_mla_reduce,test_flydsl_mla_reduce,test_mla_decode_gate,test_mla_stage2_merge,test_mla_flydsl,test_mla_v4_kargpreld,test_mla_v40_persistent)3. Extra runs (not in CI)
These are aiter's op_tests with non-default arguments, to reach the other kernels and KV pools above 4 GiB.
MI300X:
mla_h32_h64test_mla.py -n 32,1 32,2 32,4 64,164,1: "cannot get heuristic kernel", because aiter has no 64-head qlen-1 kernel on gfx942 (the same on old)mla_fp8test_mla.py -d fp8 -kvd fp8mla_bf16_fp8kvtest_mla.py -d bf16 -kvd fp8mla_4g_bf16_h16test_mla.py -c 65536 -b 64 --sequential-page-indices(KV > 4 GiB)mla_4g_bf16_h128mla_4g_bf16_h32_h6464,1no-kernel gap, on bothmla_4g_fp8pers_npstest_mla_persistent.py -npscos_diff < 3e-2assertion fails on old and newpers_h8test_mla_persistent.py -n 8,1 8,2 8,4pers_ds32test_mla_persistent.py -pl DS32_OPUS -blk 64pers_3buffertest_mla_persistent.py -pl 3BUFFER -blk 64cos_diff < 3e-2assertion fails on old and newpers_varlentest_mla_persistent.py --varlenMI355X:
mla_h32_h64test_mla.py -n 32,1 32,2 32,4 64,1mla_fp8test_mla.py -d fp8 -kvd fp8qh64_qseqlen4_gqaratio16at fp8 qlen 4 (~82 % of elements wrong). Not a PR file. The PR'sqseqlen2passes before thatmla_bf16_fp8kvtest_mla.py -d bf16 -kvd fp8mla_4g_bf16_h16-c 65536 -b 64 --sequential-page-indices(KV > 4 GiB)subQ16(qlen 1) andcoex0_mask1(qlen 2, 4) but passes the loose cos check. New is 0 %mla_4g_bf16_h128subQ128, 0 % on bothmla_4g_bf16_h32_h64MLA_A16W16_1TG_4W_16mx4_32nx1(32 heads, not a PR file, no sp3 source)mla_4g_fp8qh64_qseqlen4(82.8 %). Old is also 3.0 % wrong inqseqlen2; new 0 %pers_npstest_mla_persistent.py -npsqh64_qseqlen1_gqaratio64_v3_ps(not a PR file). Reproduced alone on bothpers_h8test_mla_persistent.py -n 8,1 8,2 8,4pers_ds32-pl DS32_OPUS -blk 64pers_3buffer-pl 3BUFFER -blk 64pers_varlentest_mla_persistent.py --varlena16w8 mask1_ps,qseqlen2_ps1000s of AI-generated adversarial tests
Every kernel was checked against an fp32/fp64 PyTorch reference and, below 4 GiB, bit-for-bit against the old build with only the wait and race fixes, in a per-kernel suite of several hundred to ~1,800 cases (shapes, qlen, split counts, page sizes, empty and padded work items, inf/NaN/denormal inputs, NaN guard bands around every output), on real KV pools above 4 GiB (up to ~110 GB) with rows placed exactly at the wrap points, through static checks for unwaited loads and MFMA hazards, and with a branch-coverage build that reached every edge; every kernel also passed a 1-hour soak (0.2–2.2 M launches on CU-masked streams with injected stalls and memory-aggressor kernels running alongside, 0 failures), and most also got barrier-stall sweeps and negative-control builds with a fix removed.
SGLang gsm8k accuracy results:
MI300X:
MLA_A16W16_1TG_4W_32mx1_16nx1_Coex0_Msk1_QH16: bf16, 32 heads, qlen ≥ 2MLA_A16W16_1TG_4W_32mx1_16nx1_Coex0_Msk1_QH16_Q1(new): bf16, 32 heads, qlen 1…_QH16, the only 32-head kernel before this PR)MLA_A16W16_1TG_4W_64mx1_16nx1_Coex0_Msk1_QH16: bf16, 64 headsmla_a16w16_qh16_m16x4_n16x1_coex0_mask1: bf16, 16 headsmla_a16w16_qh16_m16x4_n16x1_coex0_mask1_ps: bf16, 16 heads, persistentmla_a16w16_qh16_m32x4_n16x1_coex0_mask1: bf16, 16 heads, qlen ≥ 5mla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps: bf16 Q, fp8 KV, persistentmla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps_page64_ds32mla_a8w8_qh128_m32x4_n16x2_msk0_ps: fp8, 128 heads, persistentmla_a8w8_qh128_m32x4_n16x2_msk1: fp8, 128 heads, causalmla_a8w8_qh16_qseqlen1_gqaratio16: fp8, 16 heads, qlen 1mla_a8w8_qh16_qseqlen1_gqaratio16_ps: fp8, 16 heads, qlen 1, persistentmla_a8w8_qh16_qseqlen2_gqaratio16: fp8, 16 heads, qlen 2mla_a8w8_qh16_qseqlen2_gqaratio16_ps: fp8, 16 heads, qlen 2, persistentmla_a8w8_qh64_qseqlen4_gqaratio16: fp8, qlen 3–4mla_a8w8_qh64_qseqlen4_gqaratio16_ps: fp8, qlen 3–4, persistent, pagedmla_dec_stage1_bf16_a16w16_subQ128_mqa128+ #25mla_pfl_bf16_a16w16_causal_subQ128_mqa128: bf16, 128 heads, decode + causal prefillmla_dec_stage1_bf16_a16w16_subQ16_mqa16+ #26mla_pfl_bf16_a16w16_causal_subQ16_mqa16: bf16, 16 heads, decode + causal prefillmla_dec_stage1_bf16_a16w16_subQ16_mqa16_ps: bf16, 16 rows, persistent† On gfx942 sglang always passes bf16 Q to
mla_decode_fwd, so the a8w8 kernels are never launched in stock serving. A test-only shim quantized Q to per-tensor fp8 before the call, as sglang's DCP-ASM path does.‡ This is an sglang bug, not a kernel bug: with CUDA graphs, padded Kimi KDA verify rows are allocated with
new_empty, which puts NaN K/V in KV slot 0. The "slot-0 fix" zero-fills those rows. It is a local workaround and was not submitted to sglang.§ Stock sglang sends non-speculative extend batches of MLA models to MHA, so
mla_prefill_fwdis never called. A test-only shim routed extend batches with a cached prefix to MLA. These rows show the kernels compute correct attention on real traffic; they are not a stock sglang configuration.¶ By default sglang pads 8 heads to 16 and turns persistent mode off. A test-only shim kept 8 heads and persistent mode, so that this kernel is launched.
MI355X:
mla_dec_stage1_bf16_a16w16_subQ16_mqa16: bf16, 16 heads, qlen 1mla_pfl_bf16_a16w16_causal_subQ16_mqa16: decode + causal prefillmla_a16w16_qh16_m16x4_n16x1_coex0_mask1: bf16, 16 heads, qlen 2–4mla_a16w16_qh16_m32x4_n16x1_coex0_mask1: bf16, 16 heads, qlen ≥ 5mla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps: bf16 Q, fp8 KV, PSmla_a8w8_qh16_qseqlen2_gqaratio16: fp8, 16 heads, qlen 2mla_a8w8_qh16_qseqlen2_gqaratio16_ps: fp8, 16 heads, qlen 2, PSmla_dec_stage1_bf16_a16w16_subQ128_mqa128+ #25mla_pfl_bf16_a16w16_causal_subQ128_mqa128: 128 heads, decode + causal prefillmla_a8w8_qh128_m32x4_n16x2_msk1: fp8, 128 heads, causalMLA_A16W16_1TG_4W_64mx1_16nx1_Coex0_Msk1_QH16: bf16, 64 headsNot run in sglang:
msk0: no sglang config here asks for non-causal decode. It is covered by the new gfx950 CI line and the A/B.Not run in sglang:
msk0: no sglang config here asks for non-causal decode. It is covered by the new gfx950 CI line and the A/B.Note: I additionally fixed the bug mentioned in #6731. The bug was a race condition in
mla_reduce_v1. I added a barrier.No measurable cost. Every shape is within the ±1–2% run-to-run noise, except one shape that is 2.5% faster with the barrier. The geomean over 15 shapes is +0.2% warm / +0.6% cold on GPU 4, and −0.3% / −0.1% on GPU 5.
Added a test_mla_reduce.py case (16 heads, dv 512, 32 tiles × 64 splits × 32 rows) that fails on every run on MI300X without the new mla_reduce_v1 row-loop barrier and passes with it.
Another note:
Non-persistent bf16 128-head causal decode with qlen > 1 always ran the unmasked decode kernel, so queries attended to future tokens; the fix sends that case to the masked build of the same kernel (mla_pfl_..._causal_subQ128_mqa128) and makes stage 2 merge only the splits each query actually wrote.
The default test_mla.py run already covers this bug through its 128-head qlen 2 causal case, but checkAllclose only logs failed! without raising, so CI passes even when that case fails.
PR Self-Review
Reviewed revision
2cd4f38
Behavior and intent
Answered above.
Validation and unverified scope
Answered above.
PR-specific question
This PR's only CI change is four added lines in .github/scripts/aiter_test.sh, inside the existing standard job's Tests step (aiter-test.yaml). It adds no new workflow, trigger, or permissions grant.
Changed op tests
op_tests/test_mla_ltx.py — Compares torch golden vs. mla_decode_fwd specifically at large page IDs, large KV byte offsets, and >4 GiB KV pools (gfx942/gfx950 asm kernels) — i.e. it's the direct regression test for the 4 GiB KV-addressing bug this PR fixes. On main it only covered 2 presets (qh16_bf16_q1, qh128_bf16_q1), exercising 2 of the 26 gfx942 MLA kernels. This PR extends GFX942_PRESETS to 17 presets across non-persistent/persistent/prefill modes, with each preset's comment naming the exact .co kernel it targets — collectively covering every one of the 20 kernels this PR rebuilds, at the boundary condition the bug only manifests at. It's not redundant with any other op_test because no other existing test constructs a >4 GiB KV pool or large-byte-offset page layout for these kernels; ordinary op_tests use small KV pools that never cross the 32-bit offset wrap, so they structurally cannot catch this bug class.
op_tests/test_mla_reduce.py — Adds one new case to multi_row_cases[512]: (16, "32x64", 32, True) — 32 tiles, 64 splits each, 32 output rows, with the vectorized reference enabled (which requires uniform splits, satisfied here since all 32 tiles share split-count 64). This is the regression test for issue #6731: a missing __syncthreads() between per-row output passes in mla_reduce_v1_impl_massive, where warp 0 could start rewriting p_lds_lse_scale while warp 1 was still reading the previous row's value — intermittent, data-race-dependent corruption. It's not redundant with the existing 128:/512: cases because the race only manifests at this specific combination of many tiles × many splits × many rows; every existing case uses smaller tile/split/row counts that don't hit the warp-timing window where the race is observable.
Submission Checklist