Repository navigation
[Triton/Gluon] Sparse MLA Improvements and Hardened Invalid index Handling - #5833
Conversation
With has_invalid, the UNI_TILE path sent the lanes past a segment's end to slot 0 along with the -1 sentinels, and gathered them unmasked. Their score is masked, but their V still enters the PV dot with p = 0, so a NaN in slot 0 reached the output (0 * NaN = NaN) in every row whose segment ends mid-tile. vLLM's null block sits at slot 0 and can hold NaN: DeepSeek-V4.1 served on this kernel (VLLM_ROCM_USE_AITER_TRITON_SPARSE_MLA=1) answered garbage from the first token. Only the sentinels go to slot 0 now. The lanes past the end keep the duplicate of the segment's last key that the clamped index read gives them, as they already did without has_invalid. The same goes for the prefetched slot ids of the prefill config. Signed-off-by: Mehmet Cagri Kaymak <[email protected]>
With has_invalid, -1 entries still read slot 0 unmasked, so a NaN in vLLM's null block reached the output through 0 * NaN in the PV dot. The gathers are now masked on valid. On buffer loads the zero comes from the out-of-range read, without a select that would stall the prefetch. Signed-off-by: Mehmet Kaymak <[email protected]>
With has_invalid, -1 entries and lanes past a row's end now gather the first valid slot of the program's range, so no load needs a mask and the score mask drops them. A range with no valid slot is skipped. The masked global loads compiled to a branch per load, which cost GLM fp8 up to 22% against main. The last tile can also run in the loop body (UNPEEL) instead of a peeled copy that spills at 256 VGPRs. The launchers use it on global loads, and on buffer loads for paged prefill. Signed-off-by: Mehmet Kaymak <[email protected]>
Signed-off-by: Mehmet Kaymak <[email protected]>
The reduce walked the splits one at a time with a single wave, a dependent load chain per split that cost about 0.35 us each (#5829). Each head's partials are now one tile with the splits across lanes, loaded in one round trip and summed across lanes, with 4 warps. Signed-off-by: Mehmet Kaymak <[email protected]>
Splitting them saves less than the reduce launch costs: the 128-row SWA-only layer ran 4-18% slower at C <= 128 with two splits than with one. Signed-off-by: Mehmet Kaymak <[email protected]>
Signed-off-by: Mehmet Kaymak <[email protected]>
Signed-off-by: Mehmet Kaymak <[email protected]>
Signed-off-by: Mehmet Kaymak <[email protected]>
Signed-off-by: Mehmet Kaymak <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical reduction-layout/warp coverage issues remain, and the regression test does not poison cache slot 0.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 3
Open (5)
What changed in this PR
This PR hardens gfx950 sparse MLA/decode handling for invalid cache indices and adds launch and reduction tuning.
Changes:
- Redirects invalid lanes to valid request-local cache entries.
- Tunes split counts, prefetching, unpeeling, warp counts, and reduction layout.
- Adds large-cache invalid-index regression coverage.
| File | Summary |
|---|---|
op_tests/triton_tests/attention/test_pa_decode_sparse.py |
Adds invalid-index regression coverage for large cache pools. |
aiter/ops/triton/attention/sparse_mla.py |
Adjusts reduction launch configuration. |
aiter/ops/triton/attention/pa_decode_sparse.py |
Tunes split selection, prefetching, unpeeling, and reduction launches. |
aiter/ops/triton/_gluon_kernels/gfx950/attention/sparse_mla.py |
Implements fallback gathers and a revised reduction layout. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
… and tile budget
_decode_num_splits_occ bounds the split count by cta_cap = 2 * num_sms // base_wg,
which lets base_wg * splits exceed num_sms. Capping that alone is not enough: past
a point, cutting splits stops removing overhead and starts removing parallelism.
A bare one-wave cap, swept over queries 6..252 x top-k {512, 1024, 2048}, wins 6 of
24 shapes and loses 15, worst -43 %.
Bounding from both sides -- one wave above, tiles // 4 below -- gives 10 wins and
0 losses. tiles // 4 is not a new constant: it is the split floor the
base_wg >= num_sms branch of this same function already uses.
Layers under the tiles <= 2 early return from ROCm#5833, which is the same economics at
the other end -- there the reduce launch outweighs the split, here the per-split
partial write and Q re-read do. These bounds apply from tiles >= 3 up.
Composes with _MAX_SPLITS and _launch_splits from ROCm#5797, and helps their purpose:
wave_cap is a power of two, so where it binds the count needs no padding, and it
introduces padding in no cell where main did not already pad. Over queries 1..256 x
top-k {512, 1024, 2048, 8192} it cuts the distinct launched split counts from 16 to
10, so the reduce compiles for fewer counts, not more.
Adds test_decode_num_splits_occ_bounds, asserting the bounds the split count is
built from over 165 shapes. num_sms is patched rather than read from the device, so
the body allocates nothing and the bounds are checked at partitioned CU counts
(256/128/64/32) as well.
Co-Authored-By: Claude Opus 5 <[email protected]>
NOTE: the percentages above were measured before ROCm#5797 and ROCm#5833, both of which
changed the decode launch. A re-measurement against the current base is running;
this note comes out when it lands.



Motivation
VLLM can sometimes have poisoned kv cache where page index 0 contains NaNs. This PR addresses this by using an index valid for a request and using that as placeholder.
Besides that some tuning for models using triton 3.8.0+gitc0a142ff from vllm/vllm-openai-rocm:nightly-rocm100
Sparse MLA per forward step: branch vs aiter main
aiter main
a75ba53devscagri/gluon_sparse_mla_invalid_tail_lanesat14ab4a706· Triton 3.8.0 (gitc0a142ff) · MI355X (gfx950) · 16 heads per GPU (TP4)Each cell is the attention kernel time for one forward step, summed over the model's sparse-attention layers:
main → branch (speedup), where speedup = main time ÷ branch time, so above 1.00× the branch is faster. C is the number of query rows in the step; C ≤ 1,024 is decode, C = 4,096 and 16,384 are prefill.Headline
64-bit loads (cache pool over 2 GiB, as in vLLM) with has_invalid on:
NaN-filled cache test (every cache row no valid index points at holds NaN): branch 40 / 40 correct, aiter main 20 / 40 (every has_invalid-on case fails: 16 return NaN, 4 return wrong values).
DeepSeek-V4.1-Flash
128K context · 40 layers: 2 SWA-only, 18 c2, 20 c1
DeepSeek-V4-Flash
128K context · 43 layers: 2 SWA-only, 21 c4, 20 c128
1M context · 43 layers: 2 SWA-only, 21 c4, 20 c128
GLM-5.2 · fp8 KV
Context ≥ 2K · 78 layers, 2048-token rows
512-token context · 78 layers, compact rows
GLM-5.3-Flash · fp8 KV
Speedup only: the step time depends on the checkpoint's number of sparse-attention layers.
Context ≥ 2K · 2048-token rows
512-token context · padded to 2048 with -1
What is compared
a75ba53de, top of tree when measured.cagri/gluon_sparse_mla_invalid_tail_lanesat14ab4a706.