Skip to content

[Triton/Gluon] Gluon PA decode: fix causal mask across splits - #5915

Merged
azaidy merged 1 commit into
ROCm:mainfrom
sshlyapn:sshliapn/features/gluon-pa-causal-fix
Oct 7, 2026
Merged

azaidy merged 1 commit into
ROCm:mainfrom
sshlyapn:sshliapn/features/gluon-pa-causal-fix

Conversation

@sshlyapn

Copy link
Copy Markdown
Contributor

Problem

In the PS decode kernels (paged_attention_decode_sliding_window_head_1 and paged_attention_decode_sliding_window), non-sliding causal decode with query_length > 1 and multiple splits drops valid keys at internal split boundaries. The mask shifted each split's key range by the causal offset ext = query_length - 1 - j (start <= ext + col < end), so keys [start, start + ext) belong to no split whenever start % 256 < ext. This hits spec-decode verification, e.g. vLLM ROCM_AITER_FA with EAGLE k=3 (query_length=4).

Power-of-2 contexts are the worst case, because their split starts are 256-aligned. Not affected: the last query token, query_length=1, a single split, sliding window.

Fix

Mask by the split's own range and apply the causal cut once, against context_length:

causal_mask = (
    (qk_column_offsets[None, :] >= sequence_start_idx)
    & (qk_column_offsets[None, :] < sequence_end_idx)
    & (sequence_position_extension + qk_column_offsets[None, :] < context_length)
)

Applied to all 3 non-sliding causal branches (head_1 single-token, head_1 multi-token, multi-KV-head). The sliding-window branch is unchanged.

Also adds a ps_accuracy case set to CASE_SET_NAME_OPTIONS (12 cases, ~4 s): PS, non-sliding, bf16 unquantized, fixed contexts 2048/8192, query_length 1/4, heads (8,1)/(16,1)/(64,8), which covers all 3 fixed branches. The existing CI sets miss the bug: normal_accuracy runs ps=False, sliding_window_accuracy uses random varlen contexts and quantized KV (the 5e-3 tolerance hides a few missing keys), and sliding_window_performance runs query_length=1.

Accuracy

MI355X, Triton 3.8.0:

Test main kernel this PR
-k ps_accuracy (12 cases) 6 failed (all query_length=4) passed
Wider set: ctx 2048/8192/8193, batch 16/64, query_length=4 (18 cases) 14 failed passed

Reproduce

# This PR
pytest -v -s op_tests/triton_tests/test_pa_decode_gluon.py

# Reproduce on main: new test + main's kernel
git checkout origin/main -- aiter/ops/triton/gluon/pa_decode_gluon.py
pytest -v -s op_tests/triton_tests/test_pa_decode_gluon.py -k ps_accuracy
git checkout HEAD -- aiter/ops/triton/gluon/pa_decode_gluon.py

With main's kernel, ps_accuracy fails with 6 test case(s) exceeded the error threshold.

For non-sliding decode with query_length > 1 and multiple splits, the causal
offset shifted each split's key range, dropping keys at split boundaries
aligned to the 256-key partition. Mask by the split's own range and apply
the causal cut against context_length.
@sshlyapn
sshlyapn requested review from a team and a lite review from Copilot September 28, 2026 14:26
@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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5915 --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.

@github-actions github-actions Bot changed the title [Triton] Gluon PA decode: fix causal mask across splits [Triton/Gluon] Gluon PA decode: fix causal mask across splits Sep 28, 2026

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@farlukas farlukas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@azaidy azaidy 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!

@azaidy
azaidy merged commit d0fb8d5 into ROCm:main Oct 7, 2026
64 of 66 checks passed
sshlyapn added a commit to andrei-kochin/aiter that referenced this pull request Oct 14, 2026
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]>
sshlyapn added a commit to andrei-kochin/aiter that referenced this pull request Oct 15, 2026
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]>
sshlyapn added a commit to andrei-kochin/aiter that referenced this pull request Oct 15, 2026
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]>
sshlyapn added a commit to andrei-kochin/aiter that referenced this pull request Oct 16, 2026
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]>
sshlyapn added a commit to andrei-kochin/aiter that referenced this pull request Oct 19, 2026
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]>
sshlyapn added a commit to andrei-kochin/aiter that referenced this pull request Oct 19, 2026
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]>
sshlyapn added a commit to andrei-kochin/aiter that referenced this pull request Nov 24, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants