Skip to content

[FlyDSL] [QSA] qsa_sparse_prefill: public selection-width and byte-limit query - #8083

Merged
ZLkanyo009 merged 2 commits into
mainfrom
lingzha/qsa-sparse-prefill-support-query
Nov 18, 2026
Merged

ZLkanyo009 merged 2 commits into
mainfrom
lingzha/qsa-sparse-prefill-support-query

Conversation

@ZLkanyo009

@ZLkanyo009 ZLkanyo009 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

ATOM's Qwen4Exp QSA layer picks the FlyDSL sparse prefill (aiter.ops.qsa.qsa_sparse_prefill) before it builds the selection. It also writes the top-k selection straight into a buffer of the narrowest width the kernel takes, so the kernel gets it without a padded copy (ROCm/ATOM#3450). To decide, ATOM currently mirrors three of the entry's rules:

  • the GPU must be gfx942;
  • the accepted widths, 4T + 3 for T = 256 / 512 / 768 / 1024 (ATOM's _FLYDSL_WIDTHS = (1027, 2051, 3075, 4099));
  • the int32 selection must span fewer than 2**31 bytes.

If aiter changes any of them, the mirror goes stale silently: ATOM then sends selections the entry rejects, or falls back where it does not need to. ATOM's reviewer asked for a support query in aiter instead of the mirrors.

Changes

  • aiter.ops.qsa.qsa_sparse_prefill_widths() returns the accepted widths in increasing order, or () where qsa_sparse_prefill cannot run: no FlyDSL, or the GPU is not gfx942.
  • aiter.ops.qsa.qsa_sparse_prefill_supports_selection(rows, width) answers whether the entry takes an int32 [rows, width] selection: the width is one of qsa_sparse_prefill_widths() (so False wherever that is empty) and rows * width * 4 < 2**31. Q/K/V, kv_slots and the lengths are still checked by the call.
  • Both are backed by aiter/ops/flydsl/qsa_sparse_prefill.py:
    • flydsl_qsa_sparse_prefill_available() (get_gfx_runtime() == "gfx942"); the entry's arch check now calls it;
    • SELECTION_WIDTHS and flydsl_qsa_sparse_prefill_supports_selection(rows, width); the entry's indices check calls the latter (plus 2-D, row count, dtype, device and contiguity, as before).
  • Accepted inputs and the error messages are unchanged.

Test plan

  • tests/test_qsa_sparse_prefill_support.py (new, collected by the focused pytest tests step; it needs FlyDSL importable but no GPU, and patches the GPU arch, so it runs on MI35X) checks:
    • on gfx942: the widths; the byte boundary for every width (the last row count under 2**31 bytes is accepted, the next is rejected); and that the query matches the entry's former inline rule over widths around each accepted one, plus 0, 3, 7, 4103 and 5123, and row counts up to 2**20;
    • on gfx950, gfx90a and gfx1250: not available, no widths, nothing supported;
    • without FlyDSL: no widths, nothing supported.
  • On MI308X (gfx942), with the real kernel:
    • For each width, qsa_sparse_prefill runs at the largest row count the query accepts, with a valid selection, and matches a torch reference on sampled rows: 522756 rows at 1027, 261760 at 2051, 174592 at 3075, 130976 at 4099.
    • One row more is rejected with the indices error.
    • Widths 1023, 1026, 1028, 2047, 2052, 4103 and 5123 are rejected.
    • With the arch patched to gfx950, the queries say () / False and the entry raises "requires gfx942" on the same inputs it runs on gfx942.
  • op_tests/test_flydsl_qsa_sparse_prefill.py, default cases on MI308X: passes (rc 0).
  • black and ruff (0.16.0) are clean.

Follow-up in ATOM

Once this lands and ATOM's CI picks it up, ATOM replaces its _FLYDSL_WIDTHS, 2**31-byte and gfx942 mirrors with these two calls (ROCm/ATOM#3450).

PR Self-Review

Reviewed revision

7043bd2

Behavior and intent

Behavior change: aiter.ops.qsa gains two public, side-effect-free queries, qsa_sparse_prefill_widths() and qsa_sparse_prefill_supports_selection(rows, width), which answer whether qsa_sparse_prefill runs on this GPU and which selections it takes. They are backed by flydsl_qsa_sparse_prefill_available, SELECTION_WIDTHS and flydsl_qsa_sparse_prefill_supports_selection in aiter/ops/flydsl/qsa_sparse_prefill.py, and the entry's arch and indices checks call the same functions. What qsa_sparse_prefill accepts, what it rejects and its error messages are unchanged.

Why the existing behavior is insufficient: a caller has to decide whether it can take the FlyDSL sparse prefill, and at which width to build its selection, before it calls the entry. The entry only answers by raising ValueError after the selection is built. So ATOM mirrors the rules (gfx942, _FLYDSL_WIDTHS = (1027, 2051, 3075, 4099) and the 2**31-byte selection limit), and those copies go stale silently if aiter changes one. ATOM's reviewer asked for an aiter query instead (ROCm/ATOM#3450).

Validation and unverified scope

Validated at 7043bd2 on MI308X (gfx942), ROCm 7.2.4, torch 2.10, using an overlay of the 95d2112 image build with only the two changed modules and the new test replaced (both modules are identical between that build and main 403b24d; main has since moved, with no change to them):

  • python3 -m pytest -q tests/test_qsa_sparse_prefill_support.py: 10 passed (gfx942 rules, three other GPUs, no FlyDSL; see Test plan).
  • Real kernel, via a standalone script through aiter.ops.qsa.qsa_sparse_prefill. For each width, the largest row count the query accepts runs with a valid selection and matches a torch reference on sampled rows (max abs error under 8e-3): 522756 rows at 1027, 261760 at 2051, 174592 at 3075, 130976 at 4099. One row more is rejected with the indices ValueError. Widths 1023, 1026, 1028, 2047, 2052, 4103 and 5123 are rejected, and the query says False for all of them. With get_gfx_runtime patched to gfx950, the queries answer () / False and the entry raises QSA sparse attention requires gfx942.
  • python3 op_tests/test_flydsl_qsa_sparse_prefill.py (default cases): rc 0, no failures.
  • black and ruff check (ruff 0.16.0, as pinned in pre-checks): clean on the three files.

Unverified:

  • The real "FlyDSL not importable" path of aiter.ops.qsa was not run. The test covers it by setting _HAS_FLYDSL_PREFILL = False, which is exactly what the import fallback sets.
  • tests/test_qsa_sparse_prefill_support.py skips where flydsl is not importable.
  • A real gfx950 / gfx1250 was not used for the queries (the arch is patched); the kernel itself is gfx942-only, as before.
  • aiter CI's full op_test suite was not run locally; only the QSA prefill op test above.

PR-specific question

The most important boundary is the query agreeing exactly with what the entry, and so the kernels, accept. If the query says True where the entry raises, a caller that pre-sizes its selection buffer fails at call time. If it says False where the entry accepts, the caller falls back without need.

Evidence:

  • The entry's arch check calls flydsl_qsa_sparse_prefill_available and its indices check calls flydsl_qsa_sparse_prefill_supports_selection, the same functions the queries use, so they cannot drift apart.
  • The shape predicate equals the former inline rule over the boundary grid in tests/test_qsa_sparse_prefill_support.py: shape (M, 4T+3) with T % 256 == 0, 256 <= T <= 1024, and numel * 4 < 2**31.
  • On gfx942, the last accepted row count per width runs through the real kernel, and the first rejected one raises before any launch (see Validation).

The 2-D, row-count, dtype, device and contiguity checks stay in the entry. The docstrings say that the queries do not answer for Q/K/V, kv_slots or the lengths: those are still checked by the call.

Changed op tests

None: no op_tests/ file changes. The new test is tests/test_qsa_sparse_prefill_support.py. It needs no GPU, so it runs in the focused pytest tests step, and it covers only the new queries. The kernels stay covered by the unchanged op_tests/test_flydsl_qsa_sparse_prefill.py.

…mit query

Callers such as ATOM pick the FlyDSL sparse prefill, and the narrowest width
that holds their selection, before building the selection. Today they mirror
the entry's rules (widths 4T + 3 for T = 256/512/768/1024, int32 selection
under 2**31 bytes). Expose them instead:

- aiter.ops.qsa.qsa_sparse_prefill_widths(): the accepted widths, increasing;
  empty without FlyDSL.
- aiter.ops.qsa.qsa_sparse_prefill_supports_selection(rows, width).

Both are backed by SELECTION_WIDTHS and
flydsl_qsa_sparse_prefill_supports_selection in the FlyDSL module, and the
entry's indices check now reuses the latter. Accepted inputs and the error
are unchanged.

Co-authored-by: Cursor <[email protected]>
@ZLkanyo009
ZLkanyo009 requested a review from a team November 17, 2026 06:31
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu 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: 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 8083 --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.

@aiter-bot

aiter-bot commented Nov 17, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 7043bd2f5c65 · 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

Behavior change: `aiter.ops.qsa` gains two public, side-effect-free queries, `qsa_sparse_prefill_widths()` and `qsa_sparse_prefill_supports_selection(rows, width)`, which answer whether `qsa_sparse_prefill` runs on this GPU and which selections it takes. They are backed by `flydsl_qsa_sparse_prefill_available`, `SELECTION_WIDTHS` and `flydsl_qsa_sparse_prefill_supports_selection` in `aiter/ops/flydsl/qsa_sparse_prefill.py`, and the entry's arch and `indices` checks call the same functions. What `qsa_sparse_prefill` accepts, what it rejects and its error messages are unchanged.

Why the existing behavior is insufficient: a caller has to decide whether it can take the FlyDSL sparse prefill, and at which width to build its selection, before it calls the entry. The entry only answers by raising `ValueError` after the selection is built. So ATOM mirrors the rules (gfx942, `_FLYDSL_WIDTHS = (1027, 2051, 3075, 4099)` and the `2**31`-byte selection limit), and those copies go stale silently if aiter changes one. ATOM's reviewer asked for an aiter query instead (ROCm/ATOM#3450).

Validation and unverified scope

Validated at 7043bd2f5 on MI308X (gfx942), ROCm 7.2.4, torch 2.10, using an overlay of the 95d211284 image build with only the two changed modules and the new test replaced (both modules are identical between that build and main 403b24d8b; main has since moved, with no change to them):

- `python3 -m pytest -q tests/test_qsa_sparse_prefill_support.py`: 10 passed (gfx942 rules, three other GPUs, no FlyDSL; see Test plan).
- Real kernel, via a standalone script through `aiter.ops.qsa.qsa_sparse_prefill`. For each width, the largest row count the query accepts runs with a valid selection and matches a torch reference on sampled rows (max abs error under 8e-3): 522756 rows at 1027, 261760 at 2051, 174592 at 3075, 130976 at 4099. One row more is rejected with the indices `ValueError`. Widths 1023, 1026, 1028, 2047, 2052, 4103 and 5123 are rejected, and the query says False for all of them. With `get_gfx_runtime` patched to gfx950, the queries answer `()` / `False` and the entry raises `QSA sparse attention requires gfx942`.
- `python3 op_tests/test_flydsl_qsa_sparse_prefill.py` (default cases): rc 0, no failures.
- `black` and `ruff check` (ruff 0.16.0, as pinned in pre-checks): clean on the three files.

Unverified:

- The real "FlyDSL not importable" path of `aiter.ops.qsa` was not run. The test covers it by setting `_HAS_FLYDSL_PREFILL = False`, which is exactly what the import fallback sets.
- `tests/test_qsa_sparse_prefill_support.py` skips where `flydsl` is not importable.
- A real gfx950 / gfx1250 was not used for the queries (the arch is patched); the kernel itself is gfx942-only, as before.
- aiter CI's full op_test suite was not run locally; only the QSA prefill op test above.

PR-specific question

The most important boundary is the query agreeing exactly with what the entry, and so the kernels, accept. If the query says True where the entry raises, a caller that pre-sizes its selection buffer fails at call time. If it says False where the entry accepts, the caller falls back without need.

Evidence:

- The entry's arch check calls `flydsl_qsa_sparse_prefill_available` and its `indices` check calls `flydsl_qsa_sparse_prefill_supports_selection`, the same functions the queries use, so they cannot drift apart.
- The shape predicate equals the former inline rule over the boundary grid in `tests/test_qsa_sparse_prefill_support.py`: shape `(M, 4T+3)` with `T % 256 == 0`, `256 <= T <= 1024`, and `numel * 4 < 2**31`.
- On gfx942, the last accepted row count per width runs through the real kernel, and the first rejected one raises before any launch (see Validation).

The 2-D, row-count, dtype, device and contiguity checks stay in the entry. The docstrings say that the queries do not answer for Q/K/V, `kv_slots` or the lengths: those are still checked by the call.

Changed op tests

None: no `op_tests/` file changes. The new test is `tests/test_qsa_sparse_prefill_support.py`. It needs no GPU, so it runs in the focused `pytest tests` step, and it covers only the new queries. The kernels stay covered by the unchanged `op_tests/test_flydsl_qsa_sparse_prefill.py`.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

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.

ZLkanyo009 pushed a commit to ROCm/ATOM that referenced this pull request Nov 17, 2026
Review of #3450. The FlyDSL selection widths and the 2**31-byte check
mirror aiter's `qsa_sparse_prefill`; each mirror now points to
ROCm/aiter#8083, which exposes them as `qsa_sparse_prefill_widths()` and
`qsa_sparse_prefill_supports_selection()`, and goes once it lands.

`_FlyDSLPrefill` keeps its row count as `rows` instead of reading it back
from the key, and its docstring says why the host lengths may stay out of
the key: the layout lives on one forward's metadata, which the bridge builds
anew each forward, and a trimming `for_tokens` drops it.

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

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

⚠️ Action required before merge (2)

  1. Make the queries answer the gfx942 rule too, so ATOM keeps no copy of it. The entry raises QSA sparse attention requires gfx942 (aiter/ops/flydsl/qsa_sparse_prefill.py:348). qsa_sparse_prefill_widths() and qsa_sparse_prefill_supports_selection() (aiter/ops/qsa.py:220-233) only check _HAS_FLYDSL_PREFILL. So on gfx950 or gfx1250 they return (1027, 2051, 3075, 4099) / True for a call that always raises, and the docstring "empty where it is not available (no FlyDSL)" is wrong there. Because of this, ROCm/ATOM#3450 still has to keep its own get_gfx_runtime() == "gfx942" check ("aiter's entry raises on anything but gfx942"), which is one more hand copy of this entry's rules. Fix: add one helper in the FlyDSL module (for example flydsl_qsa_sparse_prefill_available()) and use it in the entry in place of the inline arch check. Then make qsa_sparse_prefill_widths() return () and supports_selection return False when the helper says no. The focused pytest tests step runs on MI35X (gfx950), so the widths test needs a monkeypatched arch, not the live GPU.
  2. Small cleanups: merge the two from aiter.ops.flydsl.qsa_sparse_prefill import statements (aiter/ops/qsa.py:42-48) into one, and annotate flydsl_qsa_sparse_prefill_supports_selection(rows: int, width: int) -> bool (qsa_sparse_prefill.py:51) to match its public wrapper.

Checked and fine: the predicate equals the old inline rule (a CPU probe over widths 0..5999 and 14 row counts found 0 mismatches, including the boundary rows 522756/261760/174592/130976). The entry calls the predicate itself, so the two cannot drift. The kernels under kernels/qsa/ take topk as a parameter and keep no second width table. Rejected inputs and the error text are unchanged.


Reviewed at 47b8dc6.

… GPU

flydsl_qsa_sparse_prefill_available() says whether the kernel runs on the live
GPU (gfx942, via get_gfx_runtime) and is what the entry checks.
qsa_sparse_prefill_widths() is () and qsa_sparse_prefill_supports_selection()
False where it is unavailable, so a caller needs no arch check of its own.
The two FlyDSL imports in aiter.ops.qsa are one; the shape query is typed.
tests/ patches the GPU arch: gfx942, other GPUs, and no FlyDSL.

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

Copy link
Copy Markdown
Contributor Author

@valarLip Thanks. Pushed 47b8dc6d1..7043bd2f5 (one commit).

  1. The query answers the gfx942 rule too. aiter/ops/flydsl/qsa_sparse_prefill.py has flydsl_qsa_sparse_prefill_available() (get_gfx_runtime() == "gfx942"), and the entry's arch check calls it instead of the inline comparison; the error text is unchanged. qsa_sparse_prefill_widths() returns () where FlyDSL is missing or the helper says no, and qsa_sparse_prefill_supports_selection() is False whenever the widths are empty. The docstring now says "empty where it cannot run (no FlyDSL, or the GPU is not gfx942)". The gfx942 fact lives only in that helper. tests/test_qsa_sparse_prefill_support.py patches get_gfx_runtime, so it runs on MI35X: gfx942 (widths, byte boundary per width, the former inline rule), gfx950 / gfx90a / gfx1250 (nothing available or supported), and no FlyDSL.
  2. Cleanups. The two from aiter.ops.flydsl.qsa_sparse_prefill import blocks in aiter/ops/qsa.py are one. ruff 0.16.0's isort rule splits an as import into its own block, so SELECTION_WIDTHS is now imported under its own name. flydsl_qsa_sparse_prefill_supports_selection(rows: int, width: int) -> bool is typed.

Validation at 7043bd2f5, MI308X (gfx942), overlay of the image build with only the three files replaced:

  • pytest -q tests/test_qsa_sparse_prefill_support.py: 10 passed.
  • Real kernel through aiter.ops.qsa.qsa_sparse_prefill. At the largest row count the query accepts, each width runs and matches a torch reference on sampled rows (max abs error under 8e-3): 522756 rows at 1027, 261760 at 2051, 174592 at 3075, 130976 at 4099. One more row is rejected by the entry. Widths 1023 / 1026 / 1028 / 2047 / 2052 / 4103 / 5123 are rejected by both the query and the entry. With get_gfx_runtime patched to gfx950, the query gives () / False, and the entry raises "QSA sparse attention requires gfx942" on inputs it runs on gfx942.
  • python3 op_tests/test_flydsl_qsa_sparse_prefill.py (default cases): rc 0.
  • black and ruff 0.16.0 clean.

CI: On 47b8dc6d1, MI35X standard shard 3 failed in op_tests/test_flydsl_hgemm.py: a segfault at k_stagger=127 (job log). It is unrelated to this PR, which changes only aiter/ops/qsa.py, aiter/ops/flydsl/qsa_sparse_prefill.py and tests/test_qsa_sparse_prefill_support.py; test_flydsl_hgemm.py imports none of them. The run on 7043bd2f5 (44058503039) is still building wheels; it reruns that shard.

@valarLip valarLip 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

Both r35 asks are fixed at 7043bd2:

  1. The gfx942 rule now has one helper, flydsl_qsa_sparse_prefill_available() (aiter/ops/flydsl/qsa_sparse_prefill.py:52-54). The entry calls it (:355), and qsa_sparse_prefill_widths() / qsa_sparse_prefill_supports_selection() (aiter/ops/qsa.py:219-234) return () / False when it says no. The test patches get_gfx_runtime for gfx942, gfx950, gfx90a, gfx1250 and no FlyDSL, so it runs in the MI35X pytest -q tests step.
  2. The imports are merged into one block (qsa.py:41-51) and the predicate is typed (rows: int, width: int) -> bool.

Checked: a CPU probe of the real function bodies finds 0 mismatches against the old inline rule (widths 0..5999 x 15 row counts, including the per-width boundary rows). Other GPUs give () / False. With FlyDSL missing (the names undefined), the queries short-circuit to () / False. The PR merges cleanly onto main b9e08da. ROCm/ATOM#3450 can now drop all three copies: _FLYDSL_WIDTHS becomes qsa_sparse_prefill_widths(), the 2**31 check becomes qsa_sparse_prefill_supports_selection(rows, width), and _flydsl_arch_supported becomes bool(qsa_sparse_prefill_widths()).

Please merge only after the MI35X Standard Tests at this head are green. Shard 0 runs the new test; all shards were still pending when I checked.


Re-reviewed at 7043bd2. Already fixed: shared gfx942 availability helper used by the entry and the queries; merged imports; typed predicate.

@valarLip valarLip 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. Approved at 7043bd2; all checks green.

@ZLkanyo009

Copy link
Copy Markdown
Contributor Author

@valarLip The MI35X Standard Tests at 7043bd2f5c are green: all 8 shards passed, including shard 0 with tests/test_qsa_sparse_prefill_support.py, and the Aiter Test Gate passed. No further changes from my side; it is ready for a maintainer to merge.

@zufayu
zufayu requested review from coderfeli and ruanjm November 18, 2026 01:26
@ZLkanyo009
ZLkanyo009 merged commit db870a8 into main Nov 18, 2026
@ZLkanyo009
ZLkanyo009 deleted the lingzha/qsa-sparse-prefill-support-query branch November 18, 2026 02:57
ZLkanyo009 added a commit to ROCm/ATOM that referenced this pull request Nov 18, 2026
…mit and GPU

aiter.ops.qsa answers the selection widths, the selection byte limit and
whether the kernel runs on this GPU (ROCm/aiter#8083), so the layer and the
SGLang bridge ask it instead of mirroring them: _FLYDSL_WIDTHS, the 2**31-byte
check and the gfx942 check go.
ZLkanyo009 added a commit to ROCm/ATOM that referenced this pull request Nov 18, 2026
…83 query

aiter.ops.qsa is imported at module level now, so the lazy
_flydsl_attention_op() wrapper has no reason left: qsa_sparse_prefill joins
that import and the layer calls it; the tests patch that name.

The ATOM_QSA_FLYDSL_ATTN row described the old mirrored rules (non-gfx942,
fixed budgets, a padded selection's 2**31 bytes) and ROCm/aiter#6576. It now
says the layer falls back where aiter reports no widths, has none for the
budget, or rejects the selection, and that every import needs ROCm/aiter#8083.
eppaneamd added a commit that referenced this pull request Nov 18, 2026
Conflicts with #8083 (selection-width and byte-limit query):
- flydsl_qsa_sparse_prefill_available() answers gfx942 and gfx950, the
  architectures this branch admits; _check_call's architecture rule asks it.
- _check_call's indices rule uses flydsl_qsa_sparse_prefill_supports_selection,
  as main's entry does; the message and the rule order are unchanged.
- __all__ and the FlyDSL imports in aiter.ops.qsa list both sides' names.
- tests/test_qsa_sparse_prefill_support.py holds both test sets; the support
  query's tests run on gfx942 and gfx950, and gfx950 left "other GPUs".

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ZLkanyo009 added a commit to ROCm/ATOM that referenced this pull request Nov 18, 2026
…rd's selection wiring

The envs.py comment still said gfx942 and ROCm/aiter#6576. aiter reports where
the kernel runs (qsa_sparse_prefill_widths()), and qsa_attention imports its
queries at module level, so every import needs ROCm/aiter#8083, flag on or off.

test_forward_selects_into_the_kernel_buffer runs Qwen4ExpAttention.forward on
a prefill with spies for the selection ops and the kernel, whole and
sequence-parallel: the layout is made, the selection is written into its
kernel-width buffer (out=, out[:, :width] when sharded), and the kernel reads
that buffer.
valarLip pushed a commit to ROCm/ATOM that referenced this pull request Nov 19, 2026
…ot table and select at the kernel width (#3450)

* perf(sglang/qwen4-exp): QSA FlyDSL prefill reads K/V in place and selects at kernel width

Under SGLang (page 64) each QSA layer of an eager prefill took the aiter
FlyDSL sparse attention through a host path that repeated per layer what
is the same for the whole forward, and copied data the kernel can read
where it is:

- K/V: with a prefix, each layer index_selected the whole context's K and
  V rows out of its paged pool. aiter's qsa_sparse_prefill reads a token
  pool in place through a slot table (kv_slots) when every four-token
  block of a request sits in four consecutive pool rows starting at a
  multiple of four, which a page size divisible by four guarantees (the
  bridge already requires the page to be divisible by the compress
  ratio, 4). The bridge now emits the context rows as int32, the slot
  table's type; the layer passes the pool and the table. aiter documents
  the result as the same as for the packed rows.
- Selection: each layer padded its selection with -1 to the kernel width
  (a copy, also when the width already matched). The first layer of the
  forward now allocates one kernel-width buffer filled with -1, and every
  layer's selection writes its leading columns in place; the columns past
  the selection are never written, so they stay -1.
- Checks: the flag, the layer support check, the per-call checks, the
  width and the per-request prefix lengths are made once per forward
  (_FlyDSLPrefill, kept on the forward's QSA metadata, keyed by
  everything they read from the layer and its inputs).

Native ATOM, whose metadata has no FlyDSL layout, keeps its path.

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

* test(qwen4-exp): QSA FlyDSL prefill layout, in-place reads and kernel-width selection

- One layout per forward (checks and prefix lengths made once), a new one
  for another row count.
- The kernel-width selection buffer reaches the kernel as is, -1 past the
  selection, reused by a second layer.
- With a prefix the pool and the bridge's int32 slot table go to the
  kernel; int64 rows or a strided pool are gathered as before.
- GPU: the real kernel on the slot table and the in-place selection gives
  the same bits as gathered rows and a padded copy (hit, second chunk,
  mixed unaligned prefixes, short, no prefix).
- The bridge's context rows are int32 and contiguous.

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

* test(qwen4-exp): sharded QSA selection written into the kernel-width buffer

The sequence-parallel path expands the all-gathered groups itself; into a
column prefix of the kernel-width buffer it writes the same columns as
into a fresh tensor and leaves -1 past them (GPU).

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

* perf(qwen4-exp): QSA FlyDSL prefill always reads K/V through the slot table

Review of #3433. The bridge is the only producer of `context_slots`, always
as int32, and already requires a page size divisible by the compress ratio,
so `kv_slots` is passed whenever there are context rows; aiter validates the
slot table itself. The gather branch and the hand copy of aiter's slot-table
rule go away. So does the pad fallback: `forward` builds the layout before
the selection and writes it into the kernel-width buffer, which is what the
kernel gets.

The layout is now looked up once per layer in `forward` (no second lookup in
`_flydsl_attention`), computes the selection width itself (once per forward
instead of once per layer), reads `qsa.flydsl_prefill` directly, and no
longer keys on the index size, which is always int32. The metadata comment
now says what `for_tokens` does with the layout.

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

* test(qwen4-exp): run the QSA FlyDSL host cases in the CPU job

The CPU cases of `tests/test_qwen4_exp_qsa_flydsl_gate.py` were skipped by
its module-level `importorskip("aiter.ops.enum")`. They move to
`tests/model_ops/test_qsa_flydsl_prefill_host.py`, which imports the model
code through `atom_without_aiter` and builds a real `Qwen4ExpQSAMetadata`
per forward. The int64 / strided gather cases go with the branch they
covered. The gate module keeps the GPU cases; its bit-for-bit reference is
now the kernel called directly on gathered rows and a padded selection.

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

* test: stand in einops for model code imported without AITER

The CPU job installs no einops (ATOM does not depend on it), and
`qwen4_exp_attn` reaches it through `gdn_attn` -> `attention_gdn`, so the new
QSA host cases errored at setup there. `stubbed_external_kernel_modules` now
serves it like aiter and triton, only where it is not installed, so a host
with einops keeps the real one.

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

* build: declare einops; drop its test stand-in

Review of #3450. Model code imports einops at module level (`attention_gdn`,
`fla_ops/chunk`, `qwen3_next`, `kimi_k3/model`, ...), but it was not a
declared dependency, so the CPU job, which installs ATOM through pip, had
none. Declare it (the image ships 0.8.2) and drop the einops branch that
844a485 added to `tests/aiter_stub.py`, which is back to its earlier form.

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

* refactor(qwen4-exp): reference aiter's support query at the QSA mirrors

Review of #3450. The FlyDSL selection widths and the 2**31-byte check
mirror aiter's `qsa_sparse_prefill`; each mirror now points to
ROCm/aiter#8083, which exposes them as `qsa_sparse_prefill_widths()` and
`qsa_sparse_prefill_supports_selection()`, and goes once it lands.

`_FlyDSLPrefill` keeps its row count as `rows` instead of reading it back
from the key, and its docstring says why the host lengths may stay out of
the key: the layout lives on one forward's metadata, which the bridge builds
anew each forward, and a trimming `for_tokens` drops it.

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

* refactor(qwen4-exp): make the selection-width helper public for the QSA layout

Self-review of #3450. `qsa_attention` imported the private
`_selection_widths` from `qwen4_exp/ops/qsa.py` to size the kernel-width
selection buffer before selecting. It is now `qsa_selection_widths`; its two
callers in `ops/qsa.py` and the host test's spy follow, and nothing else
used it.

`_FlyDSLPrefill`'s docstring now names everything the layout reads from the
forward's metadata and keeps out of the key (the host lengths, plus the block
table width and longest sequence behind the selection width), and the comment
in `forward` no longer describes the code this PR replaced. No behavior
change.

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

* docs: ATOM_QSA_FLYDSL_ATTN reads prefixed K/V in place

Self-review of #3450. The variable's row still said prefixed chunks gather
their requests' full-context K/V from the paged cache once per layer; with
this PR they read it in place through the bridge's slot table.

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

* qwen4_exp: QSA FlyDSL prefill asks aiter for its widths, selection limit and GPU

aiter.ops.qsa answers the selection widths, the selection byte limit and
whether the kernel runs on this GPU (ROCm/aiter#8083), so the layer and the
SGLang bridge ask it instead of mirroring them: _FLYDSL_WIDTHS, the 2**31-byte
check and the gfx942 check go.

* qwen4_exp: name the QSA selection width; correct the 67-column test docstring

The selection's own width is selection_width, not columns. A 40-token context
reaches 10 groups, rounded up to a power of two: 16, so 67 columns.

* qwen4_exp: call aiter's qsa_sparse_prefill directly; document the #8083 query

aiter.ops.qsa is imported at module level now, so the lazy
_flydsl_attention_op() wrapper has no reason left: qsa_sparse_prefill joins
that import and the layer calls it; the tests patch that name.

The ATOM_QSA_FLYDSL_ATTN row described the old mirrored rules (non-gfx942,
fixed budgets, a padded selection's 2**31 bytes) and ROCm/aiter#6576. It now
says the layer falls back where aiter reports no widths, has none for the
budget, or rejects the selection, and that every import needs ROCm/aiter#8083.

* qwen4_exp: ATOM_QSA_FLYDSL_ATTN names ROCm/aiter#8083; test the forward's selection wiring

The envs.py comment still said gfx942 and ROCm/aiter#6576. aiter reports where
the kernel runs (qsa_sparse_prefill_widths()), and qsa_attention imports its
queries at module level, so every import needs ROCm/aiter#8083, flag on or off.

test_forward_selects_into_the_kernel_buffer runs Qwen4ExpAttention.forward on
a prefill with spies for the selection ops and the kernel, whole and
sequence-parallel: the layout is made, the selection is written into its
kernel-width buffer (out=, out[:, :width] when sharded), and the kernel reads
that buffer.

---------

Co-authored-by: root <[email protected]>
Co-authored-by: Cursor <[email protected]>
apinge added a commit to apinge/ATOM that referenced this pull request Nov 23, 2026
Merge upstream cabbc6a without rewriting the published PR commits.
Resolve the MTP import conflict by retaining both the TP-size helper used
by the scoped gfx942 policy and main's arch helper for gfx1250. Adopt
main's einops>=0.7 dependency instead of duplicating the declaration.

Preserve main's optional consecutive-prefill-overlap section once in the
recipe, together with the pure TP2/TP4 instructions. Apply the pending
release-container documentation cleanup and automatic MoE CSV discovery
wording. Document the AITER QSA support-query dependency introduced by
upstream ATOM ROCm#3450 (ROCm/aiter#8083).

Adapt the padding-lifecycle runner fixture to main's weight-sync contract:
call _init_weight_updater and provide the standard config double and
attention family. Keep the existing padding, shared-slot loading, zero-tail,
online-source, and single-token scope changes.

Compatibility and validation:
- The original container AITER 95d211284 cannot import the merged Qwen model:
  it lacks qsa_sparse_prefill_widths and
  qsa_sparse_prefill_supports_selection.
- With user authorization, fast-forward /app/aiter-test to db870a851,
  the merge of #8083. Remove old JIT shared libraries, build directories,
  and FlyDSL cache, then rebuild on demand for gfx942 only. The two Qwen
  FP8 PTPC/BF16 MoE CSVs are byte-identical across this update.
- Use the container's existing Python/Torch/Triton/FlyDSL environment;
  no temporary virtual environment or runtime overlay. SGLang remains
  on its existing v0.5.22 checkout, including pre-existing local files.
- Related CPU regressions: 111 passed.
- FP8/BF16 x TP2/TP4 single-rank GPU forward/reference/graph cases:
  4 passed after the AITER update and cold JIT rebuild.
- Full SGLang+ATOM serving: pure TP2 and TP4, EP1, MTP enabled with EAGLE
  steps=3, draft_tokens=4, topk=1, rejection sampling enabled. Both start,
  capture target verify/draft decode/draft extend graphs, and complete
  eight requests each: short answers, four concurrent requests, a
  2701-token chunked prefill, 128-token generation, and sampled generation.
  All six reference-answer checks per TP pass; MTP verification and draft
  acceptance are present. The 128-token case reports acceptance length
  3.12 for both TP sizes.
- Validation uses context=4096, max_total_tokens=16384, and matching
  max_running_requests / cuda_graph_max_bs_decode of 4. It does not
  establish large-concurrency capacity, full GSM8K accuracy, or performance.
- Logs show FP8 per-token and BF16 MoE at 513 experts/top-k 11 and physical
  widths 320 (TP2) / 192 (TP4), with no CK-kernel-not-found warning.
- Black, Ruff, shell-snippet syntax, and git diff --check passed.

Test servers were stopped after validation. No push was performed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants