Repository navigation
[Triton/Gluon] Gluon PA decode: ragged (varlen) query support - #6445
andrei-kochin wants to merge 2 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
🟡 Changes recommended
The current diff mixes two backends and places the new test outside the required mirrored folder.
2 open findings
What changed in this PR
Adds ragged-query support to Gluon paged-attention decode, including packed-row reduction and validation coverage.
Changes:
- Threads
query_start_locthrough Gluon attention and HIP/Triton reducers. - Corrects temporary-output dtype selection for FP8 compute.
- Adds ragged decode tests and CI timing metadata.
| File | Description |
|---|---|
aiter/ops/triton/gluon/pa_decode_gluon.py |
Implements ragged query dispatch and packed output handling. |
csrc/cpp_itfs/pa/pa_ps.py |
Exposes varlen HIP reduction and updates its cache key. |
csrc/cpp_itfs/pa/pa_ps.cuh |
Adds packed-row addressing to the HIP reducer. |
csrc/cpp_itfs/pa/pa_ps.cpp.jinja |
Threads the offsets pointer into the HIP kernel. |
op_tests/triton_tests/test_pa_decode_gluon_varlen.py |
Tests ragged correctness, backends, and edge cases. |
.github/split-test-times/triton.tsv |
Registers the new test’s expected duration. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| logits_dtype: str, | ||
| sink_dtype: str, | ||
| use_sinks: bool, | ||
| is_varlen: bool = False, |
| import triton | ||
|
|
||
| import aiter | ||
| import aiter.ops.triton.gluon.pa_decode_gluon as pa_mod |
| @@ -0,0 +1,376 @@ | |||
| # SPDX-License-Identifier: MIT | |||
There was a problem hiding this comment.
Please reuse the existing unit test for pa decode instead of creating a new file.
fefbfac to
37b567b
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The stacked HIP changes must be removed after #6444, and the new tests must follow the mirrored Gluon test layout.
4 open findings
🧠 Review effort: Balanced
| auto reduce = [&](auto out_tag, auto parts) { | ||
| using D_OUT = decltype(out_tag); | ||
| aiter::pa_decode_ps_reduce_hip_kernel<D_OUT, float, float, false, 512, 1, decltype(parts)::value> | ||
| aiter::pa_decode_ps_reduce_hip_kernel<D_OUT, float, float, false, false, 512, 1, decltype(parts)::value> |
| _varlen_cases(), | ||
| indirect=["reduce_backend"], | ||
| ) | ||
| def test_varlen_matches_uniform( |
37b567b to
9d07f2f
Compare
9d07f2f to
ab4cc05
Compare
ab4cc05 to
22907b0
Compare
| x = 16 // 2 | ||
| key_cache = torch.empty( | ||
| num_blocks, | ||
| num_kv_heads, | ||
| VARLEN_HEAD_SIZE // x, | ||
| block_size, | ||
| x, | ||
| dtype=torch.bfloat16, | ||
| device=device, | ||
| ).uniform_(-1, 1) | ||
| value_cache = torch.empty( | ||
| num_blocks, | ||
| num_kv_heads, | ||
| VARLEN_HEAD_SIZE, | ||
| block_size, | ||
| dtype=torch.bfloat16, | ||
| device=device, | ||
| ).uniform_(-1, 1) |
22907b0 to
d696e58
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The rebased GPU kernel changes lack confirmed runtime validation and need human review before approval.
6 open issues
Remove HIP changes and keep this PR limited to one backend Reuse create_kv_cache instead of duplicating cache allocation · New Reuse create_kv_cache instead of duplicating cache allocations Place Gluon varlen tests under the mirrored Triton test path Place Gluon test under the mirrored op_tests directory Remove HIP backend changes from the Gluon-only PR
Review effort: Balanced
| x = 16 // 2 | ||
| key_cache = torch.empty( | ||
| num_blocks, | ||
| num_kv_heads, | ||
| VARLEN_HEAD_SIZE // x, | ||
| block_size, | ||
| x, | ||
| dtype=torch.bfloat16, | ||
| device=device, | ||
| ).uniform_(-1, 1) | ||
| value_cache = torch.empty( | ||
| num_blocks, | ||
| num_kv_heads, | ||
| VARLEN_HEAD_SIZE, | ||
| block_size, | ||
| dtype=torch.bfloat16, | ||
| device=device, | ||
| ).uniform_(-1, 1) |
d696e58 to
9f1dca3
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The rebased GPU paths lack confirmed validation results, so final human review is needed.
8 open issues
Remove HIP changes and keep this PR limited to one backend Fix reproduce command to reference the actual test location · New Reuse create_kv_cache instead of duplicating cache setup · New Reuse create_kv_cache instead of duplicating cache allocation Reuse create_kv_cache instead of duplicating cache allocations Place Gluon varlen tests under the mirrored Triton test path Place Gluon test under the mirrored op_tests directory Remove HIP backend changes from the Gluon-only PR
Review effort: Balanced
| sliding_window_performance_test() | ||
|
|
||
|
|
||
| # ==================== RAGGED (query_start_loc) PS PATH ==================== |
| x = 16 // 2 | ||
| key_cache = torch.empty( | ||
| num_blocks, | ||
| num_kv_heads, | ||
| VARLEN_HEAD_SIZE // x, | ||
| block_size, | ||
| x, | ||
| dtype=torch.bfloat16, | ||
| device=device, | ||
| ).uniform_(-1, 1) | ||
| value_cache = torch.empty( | ||
| num_blocks, | ||
| num_kv_heads, | ||
| VARLEN_HEAD_SIZE, | ||
| block_size, | ||
| dtype=torch.bfloat16, | ||
| device=device, | ||
| ).uniform_(-1, 1) |
|
No activity for 15 days, so this is now labelled |
New optional query_start_loc ([num_seqs + 1], int32) for pa_decode_gluon, PS path only. Sequence i owns packed query/output rows [query_start_loc[i], query_start_loc[i + 1]); query_length must be >= every per-sequence length; rows not owned by any sequence are left untouched. Non-PS paths assert on it. - Supported in the gluon head_1 and multi-KV attention kernels and in the Triton PS reduce, each behind a compile-time IS_VARLEN flag; the HIP PS reduce is used through its query_start_loc argument. - Causal masks use the per-sequence query length, on top of the per-split causal mask from ROCm#5915. - Fix the default temporary_output dtype: the attention kernels store bf16 for fp8 compute (otherwise compute_type), not query.dtype. An fp8 query with fp8 compute and no temporary_output failed to compile before. - New test op_tests/triton_tests/test_pa_decode_gluon_varlen.py: each sequence of a ragged call must match a batch-1 uniform call, and unowned rows must keep a sentinel. Covers bf16, fp8 KV, fp8 Q+KV, sinks, sliding window, block 16/64/128 with shuffled V, head_1 and multi-KV, one-shot and split runs through the HIP and Triton reduces, and zero-length sequences. Split out of ROCm#6099, rebased onto main. The FlyDSL reduce part of ROCm#6099 is dropped: since ROCm#5809 the Gluon path no longer dispatches to the FlyDSL PS reduce, and the no-work-plan mode it extended no longer exists. Signed-off-by: Sergei Shliapnikov <[email protected]> Signed-off-by: Andrei Kochin <[email protected]> Co-authored-by: Cursor <[email protected]>
…_pa_decode_gluon.py. Add test_varlen_output_gate: with query_start_loc, a strided output_gate is packed like output and gates only owned rows. Signed-off-by: Sergei Shliapnikov <[email protected]>
9f1dca3 to
0286c5f
Compare
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
The ragged tests violate the required mirrored gluon/ directory layout, and the unrelated workspace-dtype fix exceeds the repository’s one-problem-per-PR scope rule.
10 open issues
Remove HIP changes and keep this PR limited to one backend Separate the workspace-dtype fix from ragged-query support · New Reuse create_kv_cache for test cache allocation · New Reuse create_kv_cache instead of duplicating cache setup Fix reproduce command to reference the actual test location Reuse create_kv_cache instead of duplicating cache allocation Reuse create_kv_cache instead of duplicating cache allocations Place Gluon varlen tests under the mirrored Triton test path Place Gluon test under the mirrored op_tests directory Remove HIP backend changes from the Gluon-only PR
Review effort: Balanced
| dtype=( | ||
| aiter.dtypes.bf16 if compute_type == aiter.dtypes.fp8 else compute_type | ||
| ), |
| x = 16 // 2 | ||
| key_cache = torch.empty( | ||
| num_blocks, | ||
| num_kv_heads, | ||
| VARLEN_HEAD_SIZE // x, | ||
| block_size, | ||
| x, | ||
| dtype=torch.bfloat16, | ||
| device=device, | ||
| ).uniform_(-1, 1) | ||
| value_cache = torch.empty( | ||
| num_blocks, | ||
| num_kv_heads, | ||
| VARLEN_HEAD_SIZE, | ||
| block_size, | ||
| dtype=torch.bfloat16, | ||
| device=device, | ||
| ).uniform_(-1, 1) |



Motivation
Part 2 of 2 split out of #6099 (author: @sshlyapn), so each PR changes one backend.
Important
Stacked on #6444. The Gluon reduce wrapper passes
query_start_locto the HIP PS reduce, which only accepts it after #6444. Because the branches live on a fork, this PR targetsmainand carries that commit; review only the last commit ("[Triton/Gluon] Gluon PA decode: ragged (varlen) query support"). Once #6444 merges, the diff shrinks to just that commit.pa_decode_gluonneeds the samequery_lengthfor every sequence, so it can't take a decode batch with mixed lengths, e.g. speculative decodes next to plain decodes. vLLM'sROCM_AITER_FAbackend sends such batches tounified_attention, which doesn't support the shuffled KV layout. With shuffled KV it asserts instead.Example: MiniMax-M3-MXFP8 on MI355X (TP4, ROCM_AITER_FA, shuffled fp8 KV, EAGLE3 with 3 draft tokens). The server dies during warmup on the mixed spec/non-spec decode step:
AssertionError: Shuffle KV cache layout is not supported with sliding window, sinks, or speculative decoding (multi-token decode).This PR adds ragged (varlen) input, so each sequence uses only its own rows.
Changes
query_start_loc([num_seqs + 1], int32) forpa_decode_gluon, PS path only. Sequenceiowns packed query/output rows[query_start_loc[i], query_start_loc[i + 1]).query_lengthmust be >= every per-sequence length. Rows not owned by any sequence are left untouched. Non-PS paths assert on it.IS_VARLENflag, so uniform kernels don't contain it. The HIP PS reduce gets it through [HIP] PA decode PS reduce: optional query_start_loc for ragged (varlen) output #6444.temporary_outputdtype. It wasquery.dtype, but the attention kernels store bf16 for fp8 compute (otherwisecompute_type). Before this fix, an fp8 query with fp8 compute and notemporary_outputfailed to compile (amdg.buffer_storeelement type mismatch). Configs that compiled before are unaffected.op_tests/triton_tests/test_pa_decode_gluon_varlen.py(and its entry in.github/split-test-times/triton.tsv). Each sequence of a ragged call must match a batch-1 uniform call, and unowned rows must keep a sentinel value. Coverage:Differences from #6099
#6099 conflicted with
main; this is rebased and resolved:flydslrun is replaced by a 4-split HIP run, which keeps the pairwise kernel-config x head-config coverage.sequence_position_extensionusing the per-sequence query length, as [Triton/Gluon] [HIP] [FlyDSL] Gluon PA decode: ragged (varlen) query support #6099 did.split_tests.shto.github/split-test-times/triton.tsv, followingmain.Uniform path impact
Gluon attention and the Triton reduce: the varlen code is gated at compile time. HIP reduce: see #6444.
Reproduce
The resolved Gluon code has not been re-run on GPU after the rebase; CI on gfx942/gfx950 validates it.
PR Self-Review
Reviewed revision
0286c5f
Behavior and intent
pa_decode_gluongains an optionalquery_start_loc(int32,[num_seqs + 1]) on the PS path, so one call can process a decode batch where sequences have different query lengths (speculative decodes mixed with plain decodes), with packed[num_tokens, heads, D]query/output. Before this PR every sequence had to have exactlyquery_lengthrows, so vLLM could not use this kernel for mixed spec/non-spec batches with the shuffled KV layout and asserted at warmup (MiniMax-M3-MXFP8 + EAGLE3 example above). Withoutquery_start_locbehavior is unchanged: the varlen code is compile-time gated byIS_VARLEN. Non-PS paths rejectquery_start_locwith an assertion instead of silently computing wrong rows. The PR also fixes the defaulttemporary_outputdtype for fp8 compute (previously a compile failure) and makesoutput_gate(#6842) address packed rows whenquery_start_locis given.Validation and unverified scope
Current head
0286c5f309e0:ruff checkandblack --checkpassed locally on both changed files; the Triton Test workflow for this head (https://github.com/ROCm/aiter/actions/runs/45411567836) is the GPU validation and was still pending when this was written. Earlier revisions (before the test move and before the rebase onto #6842/#6244) passed the varlen tests on MI355X locally and in the PR's Triton CI shard; those runs are not evidence for the rebased code.Unverified, as of writing: no local GPU run of the rebased head, including the new
test_varlen_output_gateand the conflict resolution with #6842 (gate row addressing) and #6244 (long-query split). Varlen combined withquery_length > 4on the single-KV-head PS path (newly allowed by #6244) has no test case; the existing varlen cases usequery_length <= 4. No end-to-end vLLM run on this revision and no performance measurement (uniform path is compile-time unchanged by design, not measured).PR-specific question
Every varlen test calls
pa_decode_gluon(..., query_start_loc=...), so before this PR they fail withTypeError(no such argument). Beyond that, each checks a behavior no canonical test covers:test_varlen_matches_uniformrequires every sequence of a ragged call to equal a batch-1 uniform call with that sequence's length, rows not owned by any sequence to keep a sentinel, and (bf16, no window) a match withtorch_mha_extend; it would catch wrong packed offsets, masks or stores that use the paddedquery_lengthinstead of the per-sequence length (one such bug, a one-shot head_1 output mask, was found by Copilot review on an earlier revision), and the HIP reduce not receivingquery_start_loc(a spy asserts it). Its fp8 Q+KV split cases withouttemporary_outputfail to compile before the dtype fix.test_varlen_rejects_dot_kernel_pathfails if a non-PS configuration silently ignoresquery_start_loc.test_varlen_output_gatefails if the gated PS reduce reads gate rows with batch strides instead ofquery_start_loc(using a strided gate, as in Qwen3-Next). The existingtest_multi_case_setandtest_pa_decode_output_gateonly use uniform batches, where packed and batched offsets coincide, so they cannot detect any of these.Changed op tests
op_tests/triton_tests/test_pa_decode_gluon.py: addstest_varlen_matches_uniform(40 pairwise cases: bf16, fp8 KV, fp8 Q+KV, sinks, sliding window incl. vLLM's window+1 with 128-token partitions, block 16/64/128 with shuffled V, head_1 and multi-KV, one-shot and 4/8-split runs through both the HIP and Triton PS reduces, zero-length sequences),test_varlen_rejects_dot_kernel_pathandtest_varlen_output_gate(head_1 and multi-KV). They are not redundant because all existing cases in this file use uniform per-sequence query lengths; ragged packing, per-sequence masks, untouched unowned rows and gate addressing for packed rows are only exercised here. The cases are in this existing file rather than a new one, as requested in review, and reuse its quantization and reference helpers.