Skip to content

[MLA] [Test] Check the gfx950 FP8 QH16 qseqlen2 MLA decode for LDS races - #7621

Open
AndreasKaratzas wants to merge 5 commits into
mainfrom
akaratza_mla_qh16_qseqlen2_qlayout
Open

AndreasKaratzas wants to merge 5 commits into
mainfrom
akaratza_mla_qh16_qseqlen2_qlayout

Conversation

@AndreasKaratzas

@AndreasKaratzas AndreasKaratzas commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds a regression check for the gfx950 FP8 QH16 qseqlen2 MLA decode kernels (hsa/gfx950/mla/mla_a8w8_qh16_qseqlen2_gqaratio16.co and mla_a8w8_qh16_qseqlen2_gqaratio16_ps.co) to op_tests/test_mla_persistent.py. The check fails on the kernels that were on main before #6277 and passes on the kernels that #6277 rebuilt.

The PR first shipped binary patches of these two .co files. #6277 rebuilt both files from SP3, and the rebuilt kernels already fix the two LDS races that the patches fixed. The PR now uses main's .co files unchanged and keeps only the test.

Motivation

These kernels run fp8 MLA decode with 16 heads and 2 query tokens per row, for example MTP speculative decode with 1 draft token. Before #6277, the output of query 1 was wrong for some heads under load, and the error was silent. Two cross-wave LDS races caused it:

  1. Q prologue (write-write race). Each wave DMAs 8 Q rows into LDS slots of 0x300 bytes. Group 1 of wave 3 ended at 0x3060 and overlapped the first 96 bytes of group 2 of wave 0.
  2. P read and K write in the same barrier interval (write-after-read race). Each wave read the query-1 P values from LDS 0..0x478 and then wrote the next K tile over the same bytes with no barrier between the two.

The disassembly of the rebuilt kernels (llvm-objdump --mcpu=gfx950, both .co files) shows that #6277 removes both races:

  1. Q group 2 now starts 0x80 higher (s_add_u32 m0, m0, 0x2480, group-2 ds_read_b128 offsets 12416..12928). It no longer overlaps group 1.
  2. The P values now go to their own LDS region (ds_write_b32 ... offset:34304, ds_read_b64 ... offset:34304/34336). The K tile writes keep their old offsets (0..12960 from the per-wave base), so the P read and the K write no longer use the same LDS bytes. The GPU runs below confirm this: 0 bad calls where the old kernels fail in every run.

The existing checks did not catch the races: the existing calls of check_fp8_gqa16_multi_tile_batch cover qlen 1 only, and the existing sweeps use small batches and no concurrent work. The new calls fail on every run with the old kernels. They keep a later rebuild of these two .co files from bringing the races back.

Related: #7007 reports wrong, nondeterministic output of qseqlen2_gqaratio16_ps and qseqlen4_gqaratio16_v3_ps. #7617 and #7622 cover the qseqlen1 kernels, and #7623 the qseqlen4 v3 kernel. #7622 added the shared check_fp8_gqa16_multi_tile_batch helper; this PR and #7623 only add calls to it.

Changes

Performance (if applicable)

Not applicable. The PR does not change a kernel.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

The kernels are gfx950 only, so MI250X and MI300X do not apply.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The PR adds a test only.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

PR Self-Review

Reviewed revision

d62112f

Behavior and intent

The PR adds two calls of an existing check to main() of op_tests/test_mla_persistent.py. The check runs the gfx950 fp8 gqa16 qlen 2 decode kernels (persistent and non-persistent) on 128 rows with 3 KV tiles each, next to a copy on a side stream, and compares every (row, query, head) output with an fp32 reference. Kernel behavior does not change.

Validation and unverified scope

MI350X (gfx950), one GPU, PyTorch 2.13.0+rocm10.0.0, aiter main c2d0220 (#6277) merged into this branch. "Old" is the pair of .co files from main before #6277 (c2d0220^), loaded through an AITER_ASM_DIR overlay. "Main" is #6277's files, which this branch now ships.

Check old .co main .co (this branch)
check_fp8_gqa16_multi_tile_batch(2) (ps) 3/3 runs fail (497-646 wrong outputs) 0/10 + 0/10 runs fail (main, merged branch)
check_fp8_gqa16_multi_tile_batch(2, persistent=False) 3/3 runs fail (1009-1802 wrong) 0/10 + 0/10 runs fail
1 row per call, kv_len 257..399, 2400 calls, ps / non-ps, idle 154 / 367 bad calls 0 / 0
same, 256 MiB read before each call 152 / 366 0 / 0
same, copies on a side stream 174 / 371 0 / 0
128 rows, 400 calls, idle / cold / side stream, ps and non-ps 400/400 bad calls in every mode 0/400 in every mode
32 rows, kv_len 1000..2100, 400 calls, ps / non-ps 377-397 bad calls 0

In the old runs, every wrong output is in query 1. The table's main column is from main; the same 1-row and 128-row runs on this branch also gave 0 bad calls (16,800 calls). On main, 84,000 more calls (5 more seeds, same shapes, 3 modes, both kernels) gave 0 bad calls.

  • python op_tests/test_mla_persistent.py -n 16,2 -d fp8 -kvd fp8, with and without -nps: 10 of 10 runs each exit 0, and the new check passes in every run. The sweep's checkAllclose tallies have the same failure count per run as main (about 16 "golden vs aiter_asm" failures per run, the same on the old kernels).
  • python op_tests/test_mla_ltx.py --preset qh16_fp8_q2 --ps ps nps --lse off --suites boundary over4g page16m mega ([ASM] [HIP] [CI] [MLA] [Bugfix] Fix and optimize the gfx942 MLA decode/prefill kernels #6277's 64-bit KV test): 24 of 24 cases pass, including KV byte offsets above 4 GiB (up to 10.9 GB) and the 7.4M-token sequential case. With the old .co files, 10 of the 22 non-mega cases give a warning (max abs delta 0.033 against atol 0.03), all of them above 4 GiB.

Not verified, and not changed by this PR:

PR-specific question

Only gfx950 fp8 MLA decode with fp8 Q, fp8 KV, 16 heads per KV head, max_seqlen_q 2, causal, and no LSE or context parallel reaches the kernels that the new check runs. mla_asm_decode_remap in csrc/py_itfs_cu/asm_mla.cu maps gqa 16 fp8 with max_seqlen_q == 2 to qSeqLen=2. hsa/gfx950/mla/mla_asm.csv has two qh16_qseqlen2_gqaratio16 rows: ps=1 loads _ps.co and ps=0 loads the non-persistent .co. The check is gated on get_gfx() == "gfx950", so it does not run on other archs. The PR does not change a kernel, the CSV or the dispatch.

Changed op tests

op_tests/test_mla_persistent.py: main() now also calls the existing check_fp8_gqa16_multi_tile_batch (from #7622) with qlen 2, persistent and non-persistent. The helper runs 64 calls of 128 rows with 3 KV tiles each, next to a 256 MiB device-to-device copy on a side stream, and compares every (row, query, head) output with an fp32 reference. It fails on every run with the pre-#6277 kernels and passes on main. It takes less than 2 s per kernel.

AI assistance (Claude Code) was used for the analysis and the verification runs. A human reviewed the change.

mla_a8w8_qh16_qseqlen2_gqaratio16.co and its _ps variant have two
cross-wave LDS races:

- Q prologue: each wave DMAs 8 Q rows into 0x300-byte slots, but a row
  is 576 bytes. Group 1 of wave 3 ends at 0x3060 and overlaps the first
  96 bytes of group 2 of wave 0 (query 1, head 0). Two waves write the
  same LDS bytes with no order. Move group 2 up by 0x60 (the m0 step
  and the 9 group-2 ds_read_b128 offsets).
- Main loop: the query-1 P read (ds_read_b64 v[86:89], v6, LDS
  0..0x478) and the next K-tile write (ds_write_b32 v22, LDS
  0..0x4000) are in the same barrier interval. A fast wave overwrites P
  before a slow wave reads it. In each of the 4 loop halves,
  "s_waitcnt lgkmcnt(0); s_waitcnt vmcnt(37)" becomes
  "s_waitcnt vmcnt(37) lgkmcnt(0); s_barrier".

The file size, the ELF layout and the branch targets do not change.
There is no code motion.

Add check_fp8_gqa16_multi_tile_batch to test_mla_persistent.py. It runs
128 rows of 3 KV tiles next to a copy on a side stream, for the
persistent and the non-persistent qseqlen2 kernels. On main it fails
in every run. With these .co files it passes.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
@AndreasKaratzas AndreasKaratzas added bug Something isn't working ASM labels Nov 8, 2026
@AndreasKaratzas AndreasKaratzas self-assigned this Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 7621 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Nov 9, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision d62112fd7abf · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

The PR adds two calls of an existing check to `main()` of `op_tests/test_mla_persistent.py`. The check runs the gfx950 fp8 gqa16 qlen 2 decode kernels (persistent and non-persistent) on 128 rows with 3 KV tiles each, next to a copy on a side stream, and compares every (row, query, head) output with an fp32 reference. Kernel behavior does not change.

Validation and unverified scope

MI350X (gfx950), one GPU, PyTorch 2.13.0+rocm10.0.0, aiter main c2d0220a7 (#6277) merged into this branch. "Old" is the pair of `.co` files from main before #6277 (c2d0220a7^), loaded through an `AITER_ASM_DIR` overlay. "Main" is #6277's files, which this branch now ships.

| Check | old `.co` | main `.co` (this branch) |
|---|---|---|
| `check_fp8_gqa16_multi_tile_batch(2)` (ps) | 3/3 runs fail (497-646 wrong outputs) | 0/10 + 0/10 runs fail (main, merged branch) |
| `check_fp8_gqa16_multi_tile_batch(2, persistent=False)` | 3/3 runs fail (1009-1802 wrong) | 0/10 + 0/10 runs fail |
| 1 row per call, `kv_len` 257..399, 2400 calls, ps / non-ps, idle | 154 / 367 bad calls | 0 / 0 |
| same, 256 MiB read before each call | 152 / 366 | 0 / 0 |
| same, copies on a side stream | 174 / 371 | 0 / 0 |
| 128 rows, 400 calls, idle / cold / side stream, ps and non-ps | 400/400 bad calls in every mode | 0/400 in every mode |
| 32 rows, `kv_len` 1000..2100, 400 calls, ps / non-ps | 377-397 bad calls | 0 |

In the old runs, every wrong output is in query 1. The table's main column is from main; the same 1-row and 128-row runs on this branch also gave 0 bad calls (16,800 calls). On main, 84,000 more calls (5 more seeds, same shapes, 3 modes, both kernels) gave 0 bad calls.

- `python op_tests/test_mla_persistent.py -n 16,2 -d fp8 -kvd fp8`, with and without `-nps`: 10 of 10 runs each exit 0, and the new check passes in every run. The sweep's `checkAllclose` tallies have the same failure count per run as main (about 16 "golden vs aiter_asm" failures per run, the same on the old kernels).
- `python op_tests/test_mla_ltx.py --preset qh16_fp8_q2 --ps ps nps --lse off --suites boundary over4g page16m mega` (#6277's 64-bit KV test): 24 of 24 cases pass, including KV byte offsets above 4 GiB (up to 10.9 GB) and the 7.4M-token sequential case. With the old `.co` files, 10 of the 22 non-mega cases give a warning (max abs delta 0.033 against atol 0.03), all of them above 4 GiB.

Not verified, and not changed by this PR:

- Both qseqlen2 kernels still read KV slot 0 out of bounds, on the old and the rebuilt kernels alike. With NaN in an unreferenced slot 0, 27 of 27 shapes (batch 1/8/32, `kv_len` 5/300/1100, 3 index orders) give NaN rows, for ps and non-ps. With NaN in a different unreferenced slot, 0 of 27 do. #7872 fixed this for other PS kernels. It needs a separate fix.
- `mla_a8w8_qh16_qseqlen2_gqaratio16_ps_page.co` is not in `mla_asm.csv`, so no path loads it. Not tested.
- With more than one KV split per row, the earlier runs saw a few wrong rows in both kernels (possibly the split-merge bug class of #7613). Not re-tested on the rebuilt kernels.
- gfx942 kernels: not tested. No end-to-end model accuracy run.

PR-specific question

Only gfx950 fp8 MLA decode with fp8 Q, fp8 KV, 16 heads per KV head, `max_seqlen_q` 2, causal, and no LSE or context parallel reaches the kernels that the new check runs. `mla_asm_decode_remap` in `csrc/py_itfs_cu/asm_mla.cu` maps gqa 16 fp8 with `max_seqlen_q == 2` to `qSeqLen=2`. `hsa/gfx950/mla/mla_asm.csv` has two `qh16_qseqlen2_gqaratio16` rows: `ps=1` loads `_ps.co` and `ps=0` loads the non-persistent `.co`. The check is gated on `get_gfx() == "gfx950"`, so it does not run on other archs. The PR does not change a kernel, the CSV or the dispatch.

Changed op tests

`op_tests/test_mla_persistent.py`: `main()` now also calls the existing `check_fp8_gqa16_multi_tile_batch` (from #7622) with qlen 2, persistent and non-persistent. The helper runs 64 calls of 128 rows with 3 KV tiles each, next to a 256 MiB device-to-device copy on a side stream, and compares every (row, query, head) output with an fp32 reference. It fails on every run with the pre-#6277 kernels and passes on main. It takes less than 2 s per kernel.

AI assistance (Claude Code) was used for the analysis and the verification runs. A human reviewed the change.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting human review.

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@ChuanLi1101

Copy link
Copy Markdown
Contributor

Blocker beyond rebase:

This overwrites the same gfx950 objects as #6277 (mla_a8w8_qh16_qseqlen2_gqaratio16.co and _ps.co). #6277 rebuilds them for 64-bit KV addressing; this PR patches LDS races on current main. Whichever merges second clobbers the other. Please rebase this onto #6277 (or fold the LDS fix into that rebuild) so the shipped binary has both.

Nit: side-stream buffers are CPU (see #7623). Helper is duplicated with #7623.

Stack order: #6277 first, then this.

@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

MI355X (gfx950) verification, after updating with main

I merged main (95d2112, including #7872) into this branch. The only conflict was the main() call block in op_tests/test_mla_persistent.py. It now runs both the qlen 1 checks from #7622 and this PR's qlen 2 checks, which share the same check_fp8_gqa16_multi_tile_batch helper. #7872 did not touch either qseqlen2 kernel. Main's mla_a8w8_qh16_qseqlen2_gqaratio16{,_ps}.co are unchanged since this PR's base, so the merged branch ships exactly this PR's binaries. Against main, the PR still changes only those two .co files plus 3 test lines.

Setup: MI355X, installed aiter 0.1.28.post1. Kernels were swapped through an AITER_ASM_DIR overlay: "before" uses main's qseqlen2 .co (95d2112) and "after" uses this branch's (merge of f379b99 with main). Single GPU.

Check before (main .co) after (this PR)
repro: h16 qlen2 ps, bs32 kv2048, 100 runs 100/100 distinct outputs 1/100
repro: h16 qlen2 ps, bs1 kv64, 100 runs 6-7/100 distinct 1/100
repro worst error vs fp32 ref (bs32) 0.020-0.024 0.0014
check_fp8_gqa16_multi_tile_batch(2) (ps), 3 reps 3/3 fail (717-1234 wrong) 0/3 fail
check_fp8_gqa16_multi_tile_batch(2, persistent=False), 3 reps 3/3 fail (1156-2589 wrong) 0/3 fail

The repro results are the same with and without a different MLA decode run between calls (--perturb).

Not fixed here, for awareness: both qseqlen2 kernels still have the KV slot 0 OOB read that #7872 fixed for other PS kernels. With NaN written into an unreferenced slot 0, they return NaN rows (ps: 26/27 shapes, non-ps: 24/27) on main and on this branch alike. As a control, qseqlen1_ps gives 27/27 before #7872 and 0/27 on main. This needs a separate clamp fix.

AI assistance (Claude) was used for the merge and the verification runs.

The rebuilt mla_a8w8_qh16_qseqlen2_gqaratio16{,_ps}.co objects were
committed as 100644, while main tracks them as 100755. Restore the
mode so this PR only changes the binary contents.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

Blocker: agreed on the order. #6277 should merge first. Once it does, I will rebase this PR onto its rebuilt mla_a8w8_qh16_qseqlen2_gqaratio16{,_ps}.co and re-apply the LDS fix on top, so the shipped binaries carry both changes. Until then this PR should not merge.

CPU-buffer nit: the side-stream buffers are on the GPU. op_tests/test_mla_persistent.py calls torch.set_default_device("cuda") at module level (line 19), so torch.zeros(64 << 20) / torch.empty(64 << 20) in check_fp8_gqa16_multi_tile_batch (line 2004) allocate on the device, and the side-stream copy is device-to-device. That helper is already on main (from #7622); this PR only adds the two qlen 2 calls in main().

I also pushed 84ee885, which restores the 100755 mode on the two .co files to match main. Their contents are unchanged.

AndreasKaratzas and others added 2 commits November 24, 2026 17:33
…qlen2_qlayout

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
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]>
@github-actions github-actions Bot changed the title [ASM] Fix LDS races in gfx950 FP8 QH16 qseqlen2 MLA decode Fix LDS races in gfx950 FP8 QH16 qseqlen2 MLA decode Dec 3, 2026
@github-actions github-actions Bot removed the ASM label Dec 3, 2026
@AndreasKaratzas AndreasKaratzas changed the title Fix LDS races in gfx950 FP8 QH16 qseqlen2 MLA decode [MLA] [Test] Check the gfx950 FP8 QH16 qseqlen2 MLA decode for LDS races Dec 3, 2026
@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

thanks, merged main with #6277 in. turns out its rebuilt qseqlen2 .co files already fix both LDS races (Q group 2 moved up 0x80, and P now lives in its own LDS region instead of under the K tile), so there was nothing left to patch. the branch now ships main's binaries byte for byte, with the 64-bit KV change, and the PR is just the 3-line qlen 2 test.

on MI350X the new check fails 3/3 with the pre-#6277 .co files (497-1802 wrong outputs) and passes 10/10 on main for ps and non-ps. the stress repro goes from 150-370 bad calls in 2400 to 0, and test_mla_ltx.py --preset qh16_fp8_q2 passes all 24 cases, including the ones above 4 GiB. the KV slot 0 OOB read is still there on the rebuilt kernels (27/27 shapes give NaN rows with NaN in slot 0), so that stays a separate fix. could you take another look?

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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants