Skip to content

[Triton/Gluon] Gluon PA decode: allow query_length > 4 on the single-KV-head PS path - #6244

Merged
k50112113 merged 4 commits into
mainfrom
zejun/pa-gluon-mtp-qlen
Nov 4, 2026
Merged

k50112113 merged 4 commits into
mainfrom
zejun/pa-gluon-mtp-qlen

Conversation

@zejunchen-zejun

@zejunchen-zejun zejunchen-zejun commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Let pa_decode_gluon take query_length > 4 on the single-KV-head PS path. This enables speculative decoding with more than 3 draft tokens, for example MTP-7 (query_length 8). The other kernels keep their limits.

Motivation

pa_decode_gluon rejected query_length > 4 and query_length * query_group_size > 64 before it selected a kernel. With PS and one KV head, the launch spreads the query tokens over the middle axis of the grid. One program has a query tile of max(16, next_pow2(group)) rows at any query_length. So the guard blocked speculative decoding with more than 3 draft tokens on a path whose tile does not grow.

Changes

  • Bound the query tile for each path. On the single-KV-head PS path, only the group bounds the tile: query_group_size <= 64 (64 rows is the largest tile that the QK layout has register bases for). The other kernels hold all query tokens of a sequence in one tile and keep both old limits.
  • _uses_ps_kernel is the one PS-dispatch check. The launch wrapper, the query guard and the asymmetric Q/K and V head check use it.
  • _ps_query_split packs min(next_pow2(query_length), 16 // group_pow2) tokens in each program. The old split used cdiv(next_pow2(query_length), splits) tokens. For some inputs that is not a power of two, for example 3 tokens (a 24-row tile) at query_length 5 and group 8, and the kernel does not compile. For each input that the old guard accepted, the grid and the constexprs do not change.
  • The single-KV-head PS path rejects sliding_window <= query_length. The PS sliding-window kernels give each query token sliding_window - query_length keys, so a shorter window masks all keys.
  • The pa_decode_gluon docstring and aiter/ops/triton/gluon/README.md give the limits of each path.

Testing

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

Documentation

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

Dependencies

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

Breaking Changes

None. Inputs that the old guard accepted get the same kernel, grid and constexprs. The new window check rejects one more case on the single-KV-head PS path: 0 < sliding_window <= query_length. Before this PR, these inputs gave masked output that was not valid attention.

PR Self-Review

Reviewed revision

8ccf42a

Behavior and intent

pa_decode_gluon accepts query_length > 4 when it selects the single-KV-head PS kernel, because that launch spreads the query tokens over the grid and the query tile stays at max(16, next_pow2(group)) rows. The old global limit blocked MTP with more than 3 draft tokens. All other kernels keep query_length <= 4 and query_length * query_group_size <= 64. The token split stays a power of two, so query_length 5 to 8 compiles for narrow groups. The single-KV-head PS path also rejects windows that are not longer than the query, because they mask all keys.

Validation and unverified scope

  • black --check and ruff check on the changed files: passed.
  • CPU-only checks (no GPU) with python3 -I scripts that run the code of the changed files: _ps_query_split gives the same tokens per program and programs per sequence as the old split for all 133 shapes that the old guard accepted (query_length 1 to 4, query_group_size 1 to 64, product <= 64). The query guard of pa_decode_gluon accepts all 1728 case-set configurations of the test file and rejects the 5 cases of test_unsupported_query_shape_is_rejected. Each case of the one-partition phase of ps_long_query_accuracy gets one partition, so it runs the PS kernel in one-shot mode.
  • GPU, CI Triton Test on gfx950 (MI35X) for revision c23bdd4 (https://github.com/ROCm/aiter/actions/runs/41613999935): all tests of op_tests/triton_tests/test_pa_decode_gluon.py passed, including phase 1 of ps_long_query_accuracy (48 cases) and the 5 cases of test_unsupported_query_shape_is_rejected. Only 5 of the 16 cases of phase 2 (one partition, 256-token context) failed, each with 0.01% or less of the output out of the 5e-4 (bf16) or 5e-3 (fp8) tolerance. The cause is the bf16 rounding of the probabilities on a short context, not a wrong store (see commit 8ccf42a). Phase 2 now uses ragged lengths and the kv_varlen tolerance. A CPU emulation of the kernel numerics with these lengths gives no failures.
  • GPU, CI Triton Test on gfx950 (MI35X) for this revision (https://github.com/ROCm/aiter/actions/runs/41624013859): passed. All 49 tests of op_tests/triton_tests/test_pa_decode_gluon.py passed, including both phases of ps_long_query_accuracy and the 5 cases of test_unsupported_query_shape_is_rejected. No output was out of tolerance.
  • Unverified: gfx942 (MI300X), because the ci:triton-300x label is not set. Groups below 8 (4, 2 and 1) with query_length > 4 are not tested: they put 4, 8 or 16 tokens in each program, and the tests cover only 1 and 2 tokens. Performance is not measured: the launch does not change for inputs that the old guard accepted. Asymmetric Q/K192-V128 heads with query_length > 4 are not tested. End-to-end model accuracy with MTP-7 is not covered by this PR.

PR-specific question

ps_long_query_accuracy fails before this PR: pa_decode_gluon raises AssertionError for query_length 5 and 8. With only the guard relaxed, query_length 5 at group 8 does not compile (3 tokens, a 24-row tile), so the case set also covers the new token split. Its second phase uses ps=False with one partition, so it also covers the automatic PS dispatch and the direct output store of one-shot mode. No existing case set runs query_length > 4: ps_accuracy uses 1 and 4. test_unsupported_query_shape_is_rejected passes before and after this PR. It makes sure that the relaxed limits apply only to the single-KV-head PS path, and it covers the new window check (ps_one_kv_head_window_8). No existing test checks these rejections.

Changed op tests

op_tests/triton_tests/test_pa_decode_gluon.py:

  • ps_long_query_accuracy, a CASE_SETS entry that test_multi_case_set runs: compares with the torch reference for query_length 5 and 8, fp8 and bf16, and windows 0 and 128. Phase 1 uses heads (8, 1), (16, 1) and (64, 1) with ps=True and 2048 and 8192 contexts with several splits. Phase 2 uses heads (8, 1) and (16, 1) with ps=False and ragged lengths of at most 256 tokens, which is one partition: pa_decode_gluon selects the PS kernel, and the kernel stores the output directly. It is not redundant: the other case sets use query_length <= 4.
  • test_unsupported_query_shape_is_rejected: five shapes that must fail before launch (see above). It is not redundant: no other test checks the guard.
  • The CLI -q option accepts 1 to 8, so --case_set ps_long_query_accuracy -q 8 works.

@zejunchen-zejun
zejunchen-zejun requested review from a team and a balanced review from Copilot October 8, 2026 04:01
@github-actions

github-actions Bot commented Oct 8, 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
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 6244 --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.

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.

🔵 Needs a closer look

Expanded GPU launch shapes need runtime validation, and the sliding-window correctness issue remains unresolved.

1 open finding
What changed in this PR

Extends Gluon paged-attention decode to support deeper speculative queries on the single-KV-head PS path.

Changes:

  • Applies query limits according to the selected kernel path.
  • Keeps query-token packing power-of-two.
  • Adds long-query accuracy cases and unsupported-shape rejection tests.
File Description
op_tests/​triton_tests/​test_pa_decode_gluon.py Adds long-query and rejection coverage.
aiter/​ops/​triton/​gluon/​pa_decode_gluon.py Updates path selection, query packing, validation, and docstrings.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@k50112113

Copy link
Copy Markdown
Contributor

Please resolve conflicts thanks

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

please resolve conflict thanks

…KV-head PS path

pa_decode_gluon rejected query_length > 4 and query_length *
query_group_size > 64 before choosing a kernel. With PS and a single KV
head the launch spreads the query tokens over the grid's middle axis, so
one program's query tile is max(16, next_pow2(group)) rows at any
query_length. The guard therefore blocked speculative decoding deeper
than 3 draft tokens (e.g. MTP-7, query_length 8) on a path whose tile
never grows.

Bound the tile per path instead. On the single-KV-head PS path only the
group bounds the tile (<= 64 rows, the largest the QK layout has register
bases for). Every other kernel holds every query token of a sequence in
one tile and keeps both old limits. The launch wrapper, this guard and the
asymmetric Q/K and V head check get the PS kernel choice from one helper,
_uses_ps_kernel.

The narrow-group split (group < 16) derived its tokens per program as
cdiv(next_pow2(query_length), splits), which is not a power of two for
e.g. query_length 5 at group 8 (3 tokens, a 24-row tile) and fails to
compile in define_layout. _ps_query_split packs
min(next_pow2(query_length), 16 // group_pow2) tokens per program instead.
For every input accepted before, the grid and constexprs are unchanged.

Tests: the ps_long_query_accuracy case set covers query_length 5 and 8 on
(8, 1), (16, 1) and (64, 1), fp8 and bf16, multi-split 2048/8192 contexts,
with and without a sliding window. test_unsupported_query_shape_is_rejected
keeps the one-tile paths and a 128-row group rejected before launch.
@zejunchen-zejun
zejunchen-zejun force-pushed the zejun/pa-gluon-mtp-qlen branch from 27ee786 to 28c163e Compare November 3, 2026 09:18
Copilot AI balanced review requested due to automatic review settings November 3, 2026 09:18
@aiter-bot

aiter-bot commented Nov 3, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 8ccf42a784dc · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

`pa_decode_gluon` accepts `query_length > 4` when it selects the single-KV-head PS kernel, because that launch spreads the query tokens over the grid and the query tile stays at `max(16, next_pow2(group))` rows. The old global limit blocked MTP with more than 3 draft tokens. All other kernels keep `query_length <= 4` and `query_length * query_group_size <= 64`. The token split stays a power of two, so `query_length` 5 to 8 compiles for narrow groups. The single-KV-head PS path also rejects windows that are not longer than the query, because they mask all keys.

Validation and unverified scope

- `black --check` and `ruff check` on the changed files: passed.
- CPU-only checks (no GPU) with `python3 -I` scripts that run the code of the changed files: `_ps_query_split` gives the same tokens per program and programs per sequence as the old split for all 133 shapes that the old guard accepted (`query_length` 1 to 4, `query_group_size` 1 to 64, product <= 64). The query guard of `pa_decode_gluon` accepts all 1728 case-set configurations of the test file and rejects the 5 cases of `test_unsupported_query_shape_is_rejected`. Each case of the one-partition phase of `ps_long_query_accuracy` gets one partition, so it runs the PS kernel in one-shot mode.
- GPU, CI Triton Test on gfx950 (MI35X) for revision c23bdd4af0 (https://github.com/ROCm/aiter/actions/runs/41613999935): all tests of `op_tests/triton_tests/test_pa_decode_gluon.py` passed, including phase 1 of `ps_long_query_accuracy` (48 cases) and the 5 cases of `test_unsupported_query_shape_is_rejected`. Only 5 of the 16 cases of phase 2 (one partition, 256-token context) failed, each with 0.01% or less of the output out of the 5e-4 (bf16) or 5e-3 (fp8) tolerance. The cause is the bf16 rounding of the probabilities on a short context, not a wrong store (see commit 8ccf42a784). Phase 2 now uses ragged lengths and the kv_varlen tolerance. A CPU emulation of the kernel numerics with these lengths gives no failures.
- GPU, CI Triton Test on gfx950 (MI35X) for this revision (https://github.com/ROCm/aiter/actions/runs/41624013859): passed. All 49 tests of `op_tests/triton_tests/test_pa_decode_gluon.py` passed, including both phases of `ps_long_query_accuracy` and the 5 cases of `test_unsupported_query_shape_is_rejected`. No output was out of tolerance.
- Unverified: gfx942 (MI300X), because the `ci:triton-300x` label is not set. Groups below 8 (4, 2 and 1) with `query_length > 4` are not tested: they put 4, 8 or 16 tokens in each program, and the tests cover only 1 and 2 tokens. Performance is not measured: the launch does not change for inputs that the old guard accepted. Asymmetric Q/K192-V128 heads with `query_length > 4` are not tested. End-to-end model accuracy with MTP-7 is not covered by this PR.

PR-specific question

`ps_long_query_accuracy` fails before this PR: `pa_decode_gluon` raises `AssertionError` for `query_length` 5 and 8. With only the guard relaxed, `query_length` 5 at group 8 does not compile (3 tokens, a 24-row tile), so the case set also covers the new token split. Its second phase uses `ps=False` with one partition, so it also covers the automatic PS dispatch and the direct output store of one-shot mode. No existing case set runs `query_length > 4`: `ps_accuracy` uses 1 and 4. `test_unsupported_query_shape_is_rejected` passes before and after this PR. It makes sure that the relaxed limits apply only to the single-KV-head PS path, and it covers the new window check (`ps_one_kv_head_window_8`). No existing test checks these rejections.

Changed op tests

`op_tests/triton_tests/test_pa_decode_gluon.py`:

- `ps_long_query_accuracy`, a `CASE_SETS` entry that `test_multi_case_set` runs: compares with the torch reference for `query_length` 5 and 8, fp8 and bf16, and windows 0 and 128. Phase 1 uses heads (8, 1), (16, 1) and (64, 1) with `ps=True` and 2048 and 8192 contexts with several splits. Phase 2 uses heads (8, 1) and (16, 1) with `ps=False` and ragged lengths of at most 256 tokens, which is one partition: `pa_decode_gluon` selects the PS kernel, and the kernel stores the output directly. It is not redundant: the other case sets use `query_length <= 4`.
- `test_unsupported_query_shape_is_rejected`: five shapes that must fail before launch (see above). It is not redundant: no other test checks the guard.
- The CLI `-q` option accepts 1 to 8, so `--case_set ps_long_query_accuracy -q 8` works.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

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.

🟡 Changes recommended

The API guide still lists outdated query-length and tile limits, omitting the single-KV-head PS exception and its sliding-window exclusion for 1024-token blocks.

2 open issues

Review effort: Balanced

…ery on the single-KV-head PS path

The PS sliding-window kernels give each query token sliding_window -
query_length keys. When sliding_window <= query_length, all keys are
masked and the output is not valid attention. The single-KV-head PS path
now takes query_length > 4, so it rejects these windows before launch.
test_unsupported_query_shape_is_rejected adds query_length 8 with an
8-token window.

The multi-KV-head PS kernel and the 1024-token-block kernel use the same
window but keep query_length <= 4, so their behavior does not change. The
non-PS kernel gives each query token sliding_window keys.

Update the pa_decode_gluon docstring and aiter/ops/triton/gluon/README.md
with the query limits of the single-KV-head PS path.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 09:39

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.

🔵 Needs a closer look

The accuracy tests lack explicit coverage of automatic PS dispatch and direct output stores for long queries with ps=False and a single context partition.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Cover automatic PS dispatch and direct stores

aiter/​ops/​triton/​gluon/​pa_decode_gluon.py:4958

Long queries are also allowed with ps=False and one context partition, but the new accuracy cases do not explicitly cover automatic PS dispatch and direct output stores. Add accuracy cases with ps=False, max_context_partition_num=1, query lengths 5 and 8, and groups 8 and 16.

2 resolved since last review

Review effort: Balanced

… with ps=False

With one context partition, pa_decode_gluon selects the PS kernel also
for ps=False, and the kernel stores the output directly. Large batches
also take this path, because get_recommended_splits can return 1. Add a
ps_long_query_accuracy phase with ps=False, context length 256, groups 8
and 16, and query_length 5 and 8.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 09:48
@zejunchen-zejun

Copy link
Copy Markdown
Contributor Author

@k50112113 could you help review this PR? Thank you

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.

🔵 Needs a closer look

Human assessment is needed because long-query accuracy tests cover only 1- and 2-token programs, leaving the newly enabled 8- and 16-token layouts and partial-program behavior unverified.

No open issues 🎉

Review effort: Balanced

…rtition long-query phase

CI run 41613999935 failed 5 of the 16 cases of the one-partition phase of
ps_long_query_accuracy, all without a sliding window. In each case, 0.01%
or less of the output was out of the 5e-4 (bf16) or 5e-3 (fp8)
tolerance. The kernel rounds the probabilities to the compute type
before the PV MFMA. A 256-token context gives larger outputs than the
2048- and 8192-token contexts of phase 1, so this rounding is more than
the tolerance. A CPU emulation of these numerics gives the same failure
rate at 5e-4, and no failures at 5e-3 with the lengths of this phase.

Use ragged KV lengths of at most 256 tokens. They keep one partition and
get the kv_varlen tolerance of run_pa_gluon_test. A wrong direct store
changes full output rows, so this tolerance still finds it.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 11:00

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.

🔵 Needs a closer look

Human assessment is needed to evaluate a zero-divisor risk in an accepted kernel configuration and test coverage gaps for supported query layouts and tail masks.

No open issues 🎉

Review effort: Balanced

@k50112113
k50112113 self-requested a review November 4, 2026 16:59
@k50112113
k50112113 merged commit b7a59e2 into main Nov 4, 2026
@k50112113
k50112113 deleted the zejun/pa-gluon-mtp-qlen branch November 4, 2026 17:00
amd-mghanimi added a commit to amd-mghanimi/aiter that referenced this pull request Nov 6, 2026
…S path.

Co-authored-by: Cursor <[email protected]>

ROCm#6244 opens query length 8 only for one KV head. Muse Spark at TP8 has two KV heads and eight query heads per KV head, so a DSpark K=7 verify row still hits the one-tile assert. That tile is already laid out through 64 rows, and query length 8 fills it. Non-PS kernels stay at query length 4.
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.

4 participants