Skip to content

[MLA] Return a valid LSE from single-split BF16 QH64/QH128 decode - #6971

Draft
maeehart wants to merge 1 commit into
ROCm:mainfrom
maeehart:mla-lse-single-split
Draft

maeehart wants to merge 1 commit into
ROCm:mainfrom
maeehart:mla-lse-single-split

Conversation

@maeehart

Copy link
Copy Markdown
Contributor

Motivation

mla_decode_fwd(..., return_lse=True) returns uninitialized memory as the LSE when the non-persistent decode runs with one KV split, BF16 Q and KV, and 64 or 128 heads. The output is correct, but the LSE is not. Decode context parallelism in vLLM merges partial attention across ranks by this LSE, so the merged output is wrong. get_meta_param picks one split once the batch fills the GPU, and callers can also pass num_kv_splits=1.

Measured on MI355X (gfx950) with AITER 0.1.26, kv_lora_rank 512, rope 64, BF16, against a torch reference:

nhead num_kv_splits=1, max |lse - ref| num_kv_splits=2
16 9.5e-07 9.5e-07
32 9.5e-07 9.5e-07
64 7.78 9.5e-07
128 7.79 9.5e-07

Technical Details

With one split, the BF16 QH64 and QH128 stage-1 kernels write the final output into the FP32 partial buffer and leave the per-split LSE unset, so the stage-2 merge has no LSE to reduce. When return_lse is set and the shape is BF16 with 64 or 128 heads, mla_decode_fwd now uses two splits. Stage 2 then merges the two partials into the same output and writes the natural-log LSE. Without return_lse, and for every other shape, nothing changes.

The existing fp32_single_split_lse path for gfx1250 FP8 QH64 does not help here. Requesting FP32 partials with one split still leaves the stage-1 LSE unset for these kernels on gfx950.

Test Plan

  • New op_tests/test_mla_decode_lse_single_split.py: BF16, nhead 16, 32, 64, 128, batch 1, 4, 64, KV length 100 and 2,048, num_kv_splits 1, 2, 8, against a torch reference for both the output and the LSE.
  • The same test with batch 128 and 256 and KV length 4,096, which makes get_meta_param itself pick one split.
  • vLLM decode context parallelism on GLM-5.3 (TP8, DCP8, BF16 KV) on MI355X with this change applied.

Test Result

  • New test on gfx950: 12 of the cases fail before this change (every nhead 64 and 128 case with one split) and all pass after it.
  • vLLM, GLM-5.3, TP8 with DCP8 and BF16 KV, CUDA graphs: GSM8K 5-shot strict-match 0.9280 ± 0.0071 with this change, against 0.9212 ± 0.0074 for TP8 without DCP. Passkey retrieval 9 of 9 at 3.5K, 34K and 114K tokens.

The test skips nhead 32 with more than one split when a split gets a short ragged KV tail. That case returns a wrong output and LSE before and after this change, so it is a separate defect.

Submission Checklist

This change was prepared with AI assistance (Claude). I reviewed every line and ran the tests above.

With one KV split, the BF16 QH64 and QH128 stage-1 kernels write the
output but not the per-split LSE, so mla_decode_fwd(return_lse=True)
returned uninitialized memory as the LSE. Use two splits in that case so
that stage 2 merges the partials and writes the natural-log LSE.

Add op_tests/test_mla_decode_lse_single_split.py, which checks the output
and the LSE against a torch reference for 1, 2 and 8 splits.

Co-authored-by: Claude
Signed-off-by: Markus Hartikainen <[email protected]>
@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 (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 6971 --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 added a commit to AndreasKaratzas/vllm that referenced this pull request Nov 11, 2026
…E guard, DCP merge profiling

- Reject DCP with sinks on direct impl construction.
- Route DCP ragged (no-LSE) calls through AITER head buckets; on gfx950
  FP8 pads 32 heads to 64 and runs 64 natively.
- Force at least 2 KV splits for BF16 64/128-head LSE decode
  (ROCm/aiter#6971).
- Run the DCP top-k merge in the indexer profiling branch so the memory
  profile covers its temporaries.
- Tighten the GLM-5.2-MXFP4 PCP GSM8K configs to 0.92 / 0.02.
- Add DCP merge, sharded attention and mixed PCP+DCP tests.

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

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant