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] [QSA] Add qsa_select_paged_groups for row-sharded selection - #7815
Add qsa_select_paged_groups to aiter/ops/qsa.py: the score + top-k half of qsa_select_paged_tokens, returning [tokens, block_topk] int32 group ids and the token width qsa_expand_block_indices must emit for them. qsa_select_paged_tokens now calls it and then qsa_expand_block_indices; its signature and output are unchanged.
Source: ROCm/ATOM atom/model_ops/qwen4_exp/ops/qsa.py at ROCm/ATOM#2847 (cd2f5a0c). No kernel changes.
Motivation
aiter's QSA operators (#6469, #6515, #7008) were synced from ATOM at ROCm/ATOM#2652 (32a355f0). ROCm/ATOM#2847 then split the selection so each TP rank scores and selects only its own query rows; the ranks all-gather the group ids and expand every row locally. ATOM's qsa_attention.py calls qsa_select_paged_groups, so ROCm/ATOM#2679 (switch ATOM to aiter's QSA kernels) needs it from aiter.ops.qsa.
git diff 32a355f0 cd2f5a0c -- atom/model_ops/qwen4_exp/ops/qsa.py touches only qsa_select_paged_tokens and the new helpers; no @triton.jit code changed, so aiter/ops/triton/_triton_kernels/attention/qsa.py is unchanged here.
Changes
aiter/ops/qsa.py
_selection_widths(...) -> (scored columns, block_topk, output_width), factored out of qsa_select_paged_tokens (same power-of-two bucketing by max_seq_len).
qsa_select_paged_groups(...) -> (groups, output_width): chunked scoring + top_k_per_row_prefill(stable=True) into one [rows, block_topk] buffer. Same parameters as qsa_select_paged_tokens minus out, including allow_flydsl, compressed_k_scale and stacked_decode.
qsa_select_paged_tokens = qsa_select_paged_groups + one qsa_expand_block_indices over all rows (previously expanded per logits chunk; output is identical).
Exported in __all__, together with QSA_CACHE_FORMATS (ATOM imports the cache format names from aiter.ops.qsa).
New public op qsa_select_paged_groups for row-sharded selection. qsa_select_paged_tokens behavior unchanged; it now allocates the group ids for all rows at once (rows x block_topk int32) instead of per logits chunk, matching ATOM. QSA_CACHE_FORMATS is now importable from aiter.ops.qsa.
Validation and unverified scope
MI308X (gfx942), aiter main 023a9d147 + this change (c1749cb1d):
_expand_selected_groups offset widening: qsa_expand_block_indices over 2200 rows with out.stride(0) = 1_000_000, so the last row starts at element 2,199,000,000 (past int32): rows 0, 2147, 2148, 2149 and 2199 all match the reference. Before the cast the same script trips Memory access fault / GPU Hang. Suite caveat on the verification box: 47 FP4/MXFP4 cases fail there identically with and without this change (the image's Triton rejects ROUNDING_MODE in _mxfp4_quant_op); the 11 tests it ran before this PR all pass.
End to end with ROCm/ATOM#2679 (49251b2f, ATOM on these ops instead of its vendored copies): SGLang 0.5.22, Qwen3.8-Flash-Next-PTPC-FP8, TP4/EP4, MTP, BF16 KV, against the same image with ATOM's vendored QSA kernels. 4096 x 32 input throughput 29,978 vs 30,101 tok/s (mean of 6 runs each, -0.4%, within run-to-run spread), 30720 x 8 28,426 vs 28,663 tok/s, decode 4096 x 16 TPOT 9.63 vs 10.16 ms, GSM8K 400 0.975 vs 0.9675. Every rank logged the FlyDSL prefill attention line and no QSA fallback warning.
Not run: gfx950.
PR-specific question
Before this PR there is no qsa_select_paged_groups and no test that scores and selects a subset of rows, so the new test_qsa_row_sharded_groups_match_whole_batch fails on import/attribute lookup rather than on a wrong value: it is the only coverage of shard assembly.
test_qsa_multi_chunk_selection_matches_unchunked would fail on the pre-PR code only if chunk offsets were wrong, which the old per-chunk expand hid. It passes on main, and exists because the new one-call expand changed that: with the budget derived from _selection_widths, 1100 rows run as 400 + 400 + 300 and 1500 as 400 + 400 + 400 + 300, so a nonzero first-row offset and a short final chunk both occur. Writing every chunk at offset 0 makes both cases fail.
The int64 widening in _expand_selected_groups is the case that is not covered by a canonical test: 2200 rows x 2,051 columns only exceeds int32 with a out.stride(0) near 1e6, which no existing test builds. With row * out_s0 left in int32 it faults the GPU instead of failing an assert, so no default-shape test can catch it.
Changed op tests
op_tests/triton_tests/attention/test_qsa.py::test_qsa_row_sharded_groups_match_whole_batch[2|4]: 1500 rows after a 2000-token prefix, split into 2 / 4 shards (all > 256 rows, so every call uses the same scorer as the whole batch). Each shard runs qsa_select_paged_groups; the concatenated groups expanded by qsa_expand_block_indices must equal whole-batch qsa_select_paged_tokens exactly, and every shard must report the same width. Not redundant: no existing test calls the split API or checks shard assembly.
op_tests/triton_tests/attention/test_qsa.py::test_qsa_multi_chunk_selection_matches_unchunked[1100|1500]: with a 400-row logits_workspace_bytes, 1100 rows run as 400 + 400 + 300 and 1500 as 400 + 400 + 400 + 300, so a nonzero first-row offset and a short final chunk both occur. Groups, reported width and expanded tokens must equal an unchunked call exactly. Not redundant: the other selection tests fit in one chunk (the default workspace holds 32,768 rows at 256 columns) and so never write at a nonzero offset.
Port of ROCm/ATOM#2847 (cd2f5a0c), atom/model_ops/qwen4_exp/ops/qsa.py.
Scoring + top-k (qsa_select_paged_groups) is split from token expansion
(qsa_expand_block_indices) so a caller can select a row shard and expand
the gathered rows. qsa_select_paged_tokens keeps its signature and output.
No kernel changes.
ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm
vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 7815 --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.
Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.
PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers
Behavior and intent
New public op `qsa_select_paged_groups` for row-sharded selection. `qsa_select_paged_tokens` behavior unchanged; it now allocates the group ids for all rows at once (`rows x block_topk` int32) instead of per logits chunk, matching ATOM. `QSA_CACHE_FORMATS` is now importable from `aiter.ops.qsa`.
Validation and unverified scope
MI308X (gfx942), aiter main `023a9d147` + this change (`c1749cb1d`):
```
pytest op_tests/triton_tests/attention/test_qsa.py
112 passed
```
`_expand_selected_groups` offset widening: `qsa_expand_block_indices` over 2200 rows with `out.stride(0) = 1_000_000`, so the last row starts at element 2,199,000,000 (past int32): rows 0, 2147, 2148, 2149 and 2199 all match the reference. Before the cast the same script trips `Memory access fault` / `GPU Hang`. Suite caveat on the verification box: 47 FP4/MXFP4 cases fail there identically with and without this change (the image's Triton rejects `ROUNDING_MODE` in `_mxfp4_quant_op`); the 11 tests it ran before this PR all pass.
End to end with ROCm/ATOM#2679 (`49251b2f`, ATOM on these ops instead of its vendored copies): SGLang 0.5.22, Qwen3.8-Flash-Next-PTPC-FP8, TP4/EP4, MTP, BF16 KV, against the same image with ATOM's vendored QSA kernels. 4096 x 32 input throughput 29,978 vs 30,101 tok/s (mean of 6 runs each, -0.4%, within run-to-run spread), 30720 x 8 28,426 vs 28,663 tok/s, decode 4096 x 16 TPOT 9.63 vs 10.16 ms, GSM8K 400 0.975 vs 0.9675. Every rank logged the FlyDSL prefill attention line and no QSA fallback warning.
Not run: gfx950.
PR-specific question
Before this PR there is no `qsa_select_paged_groups` and no test that scores and selects a subset of rows, so the new `test_qsa_row_sharded_groups_match_whole_batch` fails on import/attribute lookup rather than on a wrong value: it is the only coverage of shard assembly.
`test_qsa_multi_chunk_selection_matches_unchunked` would fail on the pre-PR code only if chunk offsets were wrong, which the old per-chunk expand hid. It passes on main, and exists because the new one-call expand changed that: with the budget derived from `_selection_widths`, 1100 rows run as 400 + 400 + 300 and 1500 as 400 + 400 + 400 + 300, so a nonzero first-row offset and a short final chunk both occur. Writing every chunk at offset 0 makes both cases fail.
The int64 widening in `_expand_selected_groups` is the case that is not covered by a canonical test: 2200 rows x 2,051 columns only exceeds int32 with a `out.stride(0)` near 1e6, which no existing test builds. With `row * out_s0` left in int32 it faults the GPU instead of failing an assert, so no default-shape test can catch it.
Changed op tests
`op_tests/triton_tests/attention/test_qsa.py::test_qsa_row_sharded_groups_match_whole_batch[2|4]`: 1500 rows after a 2000-token prefix, split into 2 / 4 shards (all > 256 rows, so every call uses the same scorer as the whole batch). Each shard runs `qsa_select_paged_groups`; the concatenated groups expanded by `qsa_expand_block_indices` must equal whole-batch `qsa_select_paged_tokens` exactly, and every shard must report the same width. Not redundant: no existing test calls the split API or checks shard assembly.
`op_tests/triton_tests/attention/test_qsa.py::test_qsa_multi_chunk_selection_matches_unchunked[1100|1500]`: with a 400-row `logits_workspace_bytes`, 1100 rows run as 400 + 400 + 300 and 1500 as 400 + 400 + 400 + 300, so a nonzero first-row offset and a short final chunk both occur. Groups, reported width and expanded tokens must equal an unchunked call exactly. Not redundant: the other selection tests fit in one chunk (the default workspace holds 32,768 rows at 256 columns) and so never write at a nonzero offset.
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
FAIL — Aiter Test Gate: failed
Required CI failed; fix it before requesting human review.
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.
🔵 Needs a closer look
The selection tests cover only one logits chunk, leaving nonzero-offset group-buffer writes and partial final chunks untested against an unchunked call.
Test multi-chunk selection with a partial final chunk
aiter/ops/qsa.py:212
The selection tests use only one logits chunk (this new case permits 32,768 rows per chunk but uses 1,500), so writes to the shared groups buffer with a nonzero row offset are not tested. Add a small-workspace case that forces multiple chunks, including a partial final chunk, and compare its groups and expanded tokens with an unchunked call.
Review effort: Balanced
zovonoir
added a commit
to mengfei-jiang/ATOM
that referenced
this pull request
Nov 11, 2026
…ked decode scorer
* import qsa_select_paged_groups from aiter.ops.qsa (ROCm/aiter#7815); the
row-sharded indexer selection from ROCm#2847 calls it.
* aiter scores decode-sized calls with the stacked kernel only when asked:
pass stacked_decode=ATOM_QSA_STACKED_DECODE_SCORER at every selection
call, as ATOM's own scorer read the flag before.
* drop the verification test that now lives in aiter's test_qsa.py.
`qsa_select_paged_tokens` now expands every selected row in one call instead
of per logits chunk, so `_expand_selected_groups` can see the whole batch: at
1,048,576 rows x 2051 output columns the last row's `row * out_s0` is
2,150,627,325 elements, past int32. Cast the row index to int64 before the
multiply, as the neighbouring kernels already do.
Also add `test_qsa_multi_chunk_selection_matches_unchunked`, which forces a
400-row logits workspace so nonzero chunk offsets and a partial final chunk
are exercised against an unchunked call.
The scored width is rounded up to a power of two, so a page table with 256
columns and 4 compressed tokens per page scores 1024 columns, not 256. The
400-row budget was computed from the raw column count and therefore produced
100-row chunks with no partial final chunk. Use `_selection_widths` so the
chunks are the intended 400 + 400 + 300 and 400 + 400 + 400 + 300.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Launch-size and pointer-offset changes require human confirmation with head-matched GPU validation, particularly for large output strides and the untested gfx950 path.
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
Add
qsa_select_paged_groupstoaiter/ops/qsa.py: the score + top-k half ofqsa_select_paged_tokens, returning[tokens, block_topk]int32 group ids and the token widthqsa_expand_block_indicesmust emit for them.qsa_select_paged_tokensnow calls it and thenqsa_expand_block_indices; its signature and output are unchanged.Source: ROCm/ATOM
atom/model_ops/qwen4_exp/ops/qsa.pyat ROCm/ATOM#2847 (cd2f5a0c). No kernel changes.Motivation
aiter's QSA operators (#6469, #6515, #7008) were synced from ATOM at ROCm/ATOM#2652 (
32a355f0). ROCm/ATOM#2847 then split the selection so each TP rank scores and selects only its own query rows; the ranks all-gather the group ids and expand every row locally. ATOM'sqsa_attention.pycallsqsa_select_paged_groups, so ROCm/ATOM#2679 (switch ATOM to aiter's QSA kernels) needs it fromaiter.ops.qsa.git diff 32a355f0 cd2f5a0c -- atom/model_ops/qwen4_exp/ops/qsa.pytouches onlyqsa_select_paged_tokensand the new helpers; no@triton.jitcode changed, soaiter/ops/triton/_triton_kernels/attention/qsa.pyis unchanged here.Changes
aiter/ops/qsa.py_selection_widths(...)->(scored columns, block_topk, output_width), factored out ofqsa_select_paged_tokens(same power-of-two bucketing bymax_seq_len).qsa_select_paged_groups(...) -> (groups, output_width): chunked scoring +top_k_per_row_prefill(stable=True)into one[rows, block_topk]buffer. Same parameters asqsa_select_paged_tokensminusout, includingallow_flydsl,compressed_k_scaleandstacked_decode.qsa_select_paged_tokens=qsa_select_paged_groups+ oneqsa_expand_block_indicesover all rows (previously expanded per logits chunk; output is identical).__all__, together withQSA_CACHE_FORMATS(ATOM imports the cache format names fromaiter.ops.qsa).op_tests/triton_tests/attention/test_qsa.py:test_qsa_row_sharded_groups_match_whole_batch.Testing
Documentation
Dependencies
Breaking Changes
None. New function;
qsa_select_paged_tokenskeeps its signature and results.PR Self-Review
Reviewed revision
c1749cb
Behavior and intent
New public op
qsa_select_paged_groupsfor row-sharded selection.qsa_select_paged_tokensbehavior unchanged; it now allocates the group ids for all rows at once (rows x block_topkint32) instead of per logits chunk, matching ATOM.QSA_CACHE_FORMATSis now importable fromaiter.ops.qsa.Validation and unverified scope
MI308X (gfx942), aiter main
023a9d147+ this change (c1749cb1d):_expand_selected_groupsoffset widening:qsa_expand_block_indicesover 2200 rows without.stride(0) = 1_000_000, so the last row starts at element 2,199,000,000 (past int32): rows 0, 2147, 2148, 2149 and 2199 all match the reference. Before the cast the same script tripsMemory access fault/GPU Hang. Suite caveat on the verification box: 47 FP4/MXFP4 cases fail there identically with and without this change (the image's Triton rejectsROUNDING_MODEin_mxfp4_quant_op); the 11 tests it ran before this PR all pass.End to end with ROCm/ATOM#2679 (
49251b2f, ATOM on these ops instead of its vendored copies): SGLang 0.5.22, Qwen3.8-Flash-Next-PTPC-FP8, TP4/EP4, MTP, BF16 KV, against the same image with ATOM's vendored QSA kernels. 4096 x 32 input throughput 29,978 vs 30,101 tok/s (mean of 6 runs each, -0.4%, within run-to-run spread), 30720 x 8 28,426 vs 28,663 tok/s, decode 4096 x 16 TPOT 9.63 vs 10.16 ms, GSM8K 400 0.975 vs 0.9675. Every rank logged the FlyDSL prefill attention line and no QSA fallback warning.Not run: gfx950.
PR-specific question
Before this PR there is no
qsa_select_paged_groupsand no test that scores and selects a subset of rows, so the newtest_qsa_row_sharded_groups_match_whole_batchfails on import/attribute lookup rather than on a wrong value: it is the only coverage of shard assembly.test_qsa_multi_chunk_selection_matches_unchunkedwould fail on the pre-PR code only if chunk offsets were wrong, which the old per-chunk expand hid. It passes on main, and exists because the new one-call expand changed that: with the budget derived from_selection_widths, 1100 rows run as 400 + 400 + 300 and 1500 as 400 + 400 + 400 + 300, so a nonzero first-row offset and a short final chunk both occur. Writing every chunk at offset 0 makes both cases fail.The int64 widening in
_expand_selected_groupsis the case that is not covered by a canonical test: 2200 rows x 2,051 columns only exceeds int32 with aout.stride(0)near 1e6, which no existing test builds. Withrow * out_s0left in int32 it faults the GPU instead of failing an assert, so no default-shape test can catch it.Changed op tests
op_tests/triton_tests/attention/test_qsa.py::test_qsa_row_sharded_groups_match_whole_batch[2|4]: 1500 rows after a 2000-token prefix, split into 2 / 4 shards (all > 256 rows, so every call uses the same scorer as the whole batch). Each shard runsqsa_select_paged_groups; the concatenated groups expanded byqsa_expand_block_indicesmust equal whole-batchqsa_select_paged_tokensexactly, and every shard must report the same width. Not redundant: no existing test calls the split API or checks shard assembly.op_tests/triton_tests/attention/test_qsa.py::test_qsa_multi_chunk_selection_matches_unchunked[1100|1500]: with a 400-rowlogits_workspace_bytes, 1100 rows run as 400 + 400 + 300 and 1500 as 400 + 400 + 400 + 300, so a nonzero first-row offset and a short final chunk both occur. Groups, reported width and expanded tokens must equal an unchunked call exactly. Not redundant: the other selection tests fit in one chunk (the default workspace holds 32,768 rows at 256 columns) and so never write at a nonzero offset.