You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Triton/Gluon] Gluon PA decode: allow query_length > 4 on the single-KV-head PS path - #6244
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.
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.
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.
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.
…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.
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.
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.
…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.
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.
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.
… 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.
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.
…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.
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.
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Let
pa_decode_gluontakequery_length > 4on the single-KV-head PS path. This enables speculative decoding with more than 3 draft tokens, for example MTP-7 (query_length8). The other kernels keep their limits.Motivation
pa_decode_gluonrejectedquery_length > 4andquery_length * query_group_size > 64before 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 ofmax(16, next_pow2(group))rows at anyquery_length. So the guard blocked speculative decoding with more than 3 draft tokens on a path whose tile does not grow.Changes
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_kernelis the one PS-dispatch check. The launch wrapper, the query guard and the asymmetric Q/K and V head check use it._ps_query_splitpacksmin(next_pow2(query_length), 16 // group_pow2)tokens in each program. The old split usedcdiv(next_pow2(query_length), splits)tokens. For some inputs that is not a power of two, for example 3 tokens (a 24-row tile) atquery_length5 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.sliding_window <= query_length. The PS sliding-window kernels give each query tokensliding_window - query_lengthkeys, so a shorter window masks all keys.pa_decode_gluondocstring andaiter/ops/triton/gluon/README.mdgive the limits of each path.Testing
Documentation
Dependencies
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_gluonacceptsquery_length > 4when it selects the single-KV-head PS kernel, because that launch spreads the query tokens over the grid and the query tile stays atmax(16, next_pow2(group))rows. The old global limit blocked MTP with more than 3 draft tokens. All other kernels keepquery_length <= 4andquery_length * query_group_size <= 64. The token split stays a power of two, soquery_length5 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 --checkandruff checkon the changed files: passed.python3 -Iscripts that run the code of the changed files:_ps_query_splitgives the same tokens per program and programs per sequence as the old split for all 133 shapes that the old guard accepted (query_length1 to 4,query_group_size1 to 64, product <= 64). The query guard ofpa_decode_gluonaccepts all 1728 case-set configurations of the test file and rejects the 5 cases oftest_unsupported_query_shape_is_rejected. Each case of the one-partition phase ofps_long_query_accuracygets one partition, so it runs the PS kernel in one-shot mode.op_tests/triton_tests/test_pa_decode_gluon.pypassed, including phase 1 ofps_long_query_accuracy(48 cases) and the 5 cases oftest_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.op_tests/triton_tests/test_pa_decode_gluon.pypassed, including both phases ofps_long_query_accuracyand the 5 cases oftest_unsupported_query_shape_is_rejected. No output was out of tolerance.ci:triton-300xlabel is not set. Groups below 8 (4, 2 and 1) withquery_length > 4are 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 withquery_length > 4are not tested. End-to-end model accuracy with MTP-7 is not covered by this PR.PR-specific question
ps_long_query_accuracyfails before this PR:pa_decode_gluonraisesAssertionErrorforquery_length5 and 8. With only the guard relaxed,query_length5 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 usesps=Falsewith one partition, so it also covers the automatic PS dispatch and the direct output store of one-shot mode. No existing case set runsquery_length > 4:ps_accuracyuses 1 and 4.test_unsupported_query_shape_is_rejectedpasses 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, aCASE_SETSentry thattest_multi_case_setruns: compares with the torch reference forquery_length5 and 8, fp8 and bf16, and windows 0 and 128. Phase 1 uses heads (8, 1), (16, 1) and (64, 1) withps=Trueand 2048 and 8192 contexts with several splits. Phase 2 uses heads (8, 1) and (16, 1) withps=Falseand ragged lengths of at most 256 tokens, which is one partition:pa_decode_gluonselects the PS kernel, and the kernel stores the output directly. It is not redundant: the other case sets usequery_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.-qoption accepts 1 to 8, so--case_set ps_long_query_accuracy -q 8works.