Skip to content

[Bugfix] MLA decode: merge only the splits gfx950 fp8 gqa16 stage 1 writes - #7613

Merged
kaiyang-1 merged 2 commits into
mainfrom
akaratza_mla_lse_split
Nov 10, 2026
Merged

kaiyang-1 merged 2 commits into
mainfrom
akaratza_mla_lse_split

Conversation

@AndreasKaratzas

Copy link
Copy Markdown
Contributor

Summary

On gfx950, fp8 MLA decode with 16 heads and one query token can merge KV splits that stage 1 never wrote. Output and LSE then come from torch.empty memory. This PR sets mgc = 128 for this kernel, so stage 2 merges only the splits that stage 1 writes.

Motivation

The non-persistent kernel mla_a8w8_qh16_qseqlen1_gqaratio16 deals KV to the splits round-robin in 128-token tiles. A split that gets no tile is not written. It also does not write valid_split_count. Stage 2 (_fwd_kernel_stage2_asm) merges min(num_kv_splits, cdiv(kv_len, mgc)) splits, and mgc is 64 for 16 heads. So a row with kv_len in (64, 128] and 2 or more splits merges split 1, which has no data. A row with kv_len in (128, 192] and 3 or more splits merges split 2, and so on.

Evidence, one row, 16 heads, fp8 Q and KV, return_lse=True, aiter main 8e69f10:

  • Per-split LSE from stage 1 matches a round-robin 128-token tile split to 1e-4 (101 tokens with 2 and 4 splits, 200 tokens with 4 splits, 300 tokens with 2 splits, 400 tokens with 4 splits). The 64-token tile split is off by 3 to 17. A split with no 128-token tile keeps its old buffer contents.
  • Sweep of kv_len 1..400 with 4 splits, with the split buffers pre-filled with NaN: 24 of 400 rows are wrong. Example: 111 tokens, output relative error 1.0, LSE error 77.
  • vLLM reaches this path. Its ROCm MLA decode with LSE (used for DCP) asks for at least 2 splits. In a vLLM check script with 16 heads, a one-row call with 67 KV tokens gave output relative error 1.24 and LSE error 5.9. The same row in a 100-row batch was correct. We think the unwritten split memory held harmless values there, but we did not check it.

This is the same bug as #7182 (bf16 gqa32, 32-token tiles) for a different kernel.

Changes

  • aiter/mla.py: mgc = 128 for gfx950, fp8 Q, fp8 KV, 16 heads, max_seqlen_q == 1. Other cases do not change.
  • op_tests/test_mla.py: check_bf16_gqa32_merges_only_written_splits becomes check_merges_only_written_splits(dtype, nhead, tile). It now also asks for LSE and checks that LSE is finite and close to the reference. main() runs it for bf16 gqa32 (as before) and, on gfx950, for fp8 gqa16 with 128-token tiles.

Performance (if applicable)

Stage 1 does not change. Stage 2 merges fewer splits only for rows where the extra splits had no data.

mla_decode_fwd, fp8, 16 heads, qlen 1, return_lse=True, splits max(get_meta_param(...), 2), run_perftest 200 iterations, MI350X. Two runs with the fix, one on main:

Hardware Workload/configuration Before After (r1 / r2) Change
MI350X bs 1, ctx 100, 2 splits 12.99 us 12.96 / 12.85 us noise
MI350X bs 1, ctx 200, 2 splits 14.21 us 14.21 / 14.25 us noise
MI350X bs 1, ctx 1000, 8 splits 16.72 us 16.79 / 16.78 us noise
MI350X bs 64, ctx 100, 2 splits 15.66 us 15.24 / 15.41 us -2%
MI350X bs 64, ctx 300, 3 splits 18.70 us 18.72 / 18.83 us noise
MI350X bs 256, ctx 100, 2 splits 21.08 us 19.57 / 19.62 us -7% (merges 1 split, not 2)
MI350X bs 256, ctx 1000, 2 splits 53.93 us 55.30 / 53.85 us noise

Testing

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

Tested on MI350X (gfx950), ROCm 7.15 (TheRock SDK 10.0.0), PyTorch 2.13.0+rocm10.0.0, aiter main 8e69f10.

The branch is rebased onto main 581579a. The new commits on main do not change aiter/mla.py, op_tests/test_mla.py or the fp8 gqa16 kernel. After the rebase, the bf16 gqa32 and fp8 gqa16 checks passed 3 of 3 runs.

  • New fp8 gqa16 check: fails on main (lse not finite), passes with the fix. fp8 and bf16 checks together passed 10 of 10 runs in a row.
  • kv_len 1..400 sweep, one row, NaN-filled split buffers: 4 splits 24 wrong rows on main, 0 with the fix. vLLM split choice (max(get_meta_param(...), 2)) 0 wrong rows with the fix.
  • vLLM repro (lse_batch_check.py 16 100 400): the worst single-row error goes from 1.24 (67 tokens) to 0.0125, which is normal fp8 noise. The batched call also stays at about 0.015.
  • python3 op_tests/test_mla.py and the extra CI argument sets: exit code 0 with the fix for python3 op_tests/test_mla.py and for all 6 extra argument sets in aiter_test.sh.

Documentation

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

The API does not change. Results that were wrong are now correct.

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

TODO: paste the head SHA from the PR Self-Review comment.

Behavior and intent

Before: stage 2 used mgc = 64 for the gfx950 fp8 gqa16 qlen1 kernel, which uses 128-token tiles. Rows shorter than num_kv_splits * 128 could merge splits with no data. After: mgc = 128, so stage 2 merges the same splits that stage 1 writes.

Validation and unverified scope

Commands and results are in "Testing" above. Not verified: gfx942. The change is gated to gfx950 because we could only measure the gfx950 tile size. gfx942 keeps mgc = 64. Other fp8 gqa16 kernels (max_seqlen_q 2 and 4) are not changed and not checked here.

Separate issue, not fixed here: the same kernel sometimes writes a wrong partial output for a split with 256 to 383 tokens when the caches are cold (for example after a large memset). The split LSE stays correct. This happens on main and on v0.1.27, with and without this fix. It needs a kernel change; we will report it separately.

Separate issue, not fixed here: with num_kv_splits == 1, this kernel does not write LSE, so return_lse=True returns torch.empty memory (128 of 400 rows wrong in the auto-split sweep, on main and with this fix). #6971 fixes the same problem for bf16 QH64/QH128 by forcing 2 splits.

PR-specific question

TODO: answer the question from the PR Self-Review comment.

Changed op tests

  • op_tests/test_mla.py: the split-merge check now takes the dtype, head count and tile size, and checks LSE as well as output. The bf16 gqa32 case is the same as before plus the LSE check. The new fp8 gqa16 case is the only test that runs this kernel with more splits than a row has tiles.

AI assistance (Claude) was used to find the cause, write the fix and the test, and run the validation.

…rites

The gfx950 kernel mla_a8w8_qh16_qseqlen1_gqaratio16 deals KV to the splits
in 128-token tiles. A split with no tile is not written. Stage 2 used
mgc = 64, so it could merge unwritten splits. Set mgc = 128 for this kernel.

Extend the split-merge op test to fp8 gqa16 and check LSE too.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
@AndreasKaratzas AndreasKaratzas self-assigned this Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 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 7613 --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.

@AndreasKaratzas
AndreasKaratzas marked this pull request as ready for review November 7, 2026 21:44
@AndreasKaratzas
AndreasKaratzas requested a review from a team November 7, 2026 21:44
@aiter-bot

aiter-bot commented Nov 7, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 719494ff5a85 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — PR-specific question is too short to show concrete reasoning (9 units; need 14)
  • FAIL — validation answer must explicitly state what remains unverified (or say none with a reason)

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

LGTM. Same issue as bf16 gqa32: stage2 must not merge empty splits. Setting mgc=128 for fp8 qh16 qlen1 matches SUB_KV=128. Nice that the NaN-fill test was generalized.

@ChuanLi1101 ChuanLi1101 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.

LGTM. Same issue as bf16 gqa32: stage2 must not merge empty splits. Setting mgc=128 for fp8 qh16 qlen1 matches SUB_KV=128. Nice that the NaN-fill test was generalized.

ChuanLi1101
ChuanLi1101 previously approved these changes Nov 9, 2026

@ChuanLi1101 ChuanLi1101 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.

LGTM. Same issue as bf16 gqa32: stage2 must not merge empty splits. Setting mgc=128 for fp8 qh16 qlen1 matches SUB_KV=128. Nice that the NaN-fill test was generalized.

@zufayu
zufayu requested a review from kaiyang-1 November 10, 2026 01:18
kaiyang-1
kaiyang-1 previously approved these changes Nov 10, 2026
@kaiyang-1

Copy link
Copy Markdown
Contributor

@AndreasKaratzas Thanks for the PR! LGTM. Could you please resolve the merge conflicts in op_tests/test_mla.py so we can get this merged?

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

Copy link
Copy Markdown
Contributor Author

@kaiyang-1 Done :) Thanks for the review

@kaiyang-1
kaiyang-1 self-requested a review November 10, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants