Repository navigation
[FlyDSL] [QSA] qsa_sparse_prefill: public selection-width and byte-limit query - #8083
Conversation
…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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
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
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (2)
- 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()andqsa_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)/Truefor 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 ownget_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 exampleflydsl_qsa_sparse_prefill_available()) and use it in the entry in place of the inline arch check. Then makeqsa_sparse_prefill_widths()return()andsupports_selectionreturnFalsewhen the helper says no. The focusedpytest testsstep runs on MI35X (gfx950), so the widths test needs a monkeypatched arch, not the live GPU. - Small cleanups: merge the two
from aiter.ops.flydsl.qsa_sparse_prefill importstatements (aiter/ops/qsa.py:42-48) into one, and annotateflydsl_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]>
|
@valarLip Thanks. Pushed
Validation at
CI: On |
valarLip
left a comment
There was a problem hiding this comment.
✅ LGTM
Both r35 asks are fixed at 7043bd2:
- 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), andqsa_sparse_prefill_widths()/qsa_sparse_prefill_supports_selection()(aiter/ops/qsa.py:219-234) return()/Falsewhen it says no. The test patchesget_gfx_runtimefor gfx942, gfx950, gfx90a, gfx1250 and no FlyDSL, so it runs in the MI35Xpytest -q testsstep. - 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 The MI35X Standard Tests at |
…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.
…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.
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]>
…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.
…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]>
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.
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:4T + 3forT = 256 / 512 / 768 / 1024(ATOM's_FLYDSL_WIDTHS = (1027, 2051, 3075, 4099));2**31bytes.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()whereqsa_sparse_prefillcannot 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 ofqsa_sparse_prefill_widths()(soFalsewherever that is empty) androws * width * 4 < 2**31. Q/K/V,kv_slotsand the lengths are still checked by the call.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_WIDTHSandflydsl_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).Test plan
tests/test_qsa_sparse_prefill_support.py(new, collected by the focusedpytest testsstep; it needs FlyDSL importable but no GPU, and patches the GPU arch, so it runs on MI35X) checks:2**31bytes 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;qsa_sparse_prefillruns 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.()/Falseand 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).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.qsagains two public, side-effect-free queries,qsa_sparse_prefill_widths()andqsa_sparse_prefill_supports_selection(rows, width), which answer whetherqsa_sparse_prefillruns on this GPU and which selections it takes. They are backed byflydsl_qsa_sparse_prefill_available,SELECTION_WIDTHSandflydsl_qsa_sparse_prefill_supports_selectioninaiter/ops/flydsl/qsa_sparse_prefill.py, and the entry's arch andindiceschecks call the same functions. Whatqsa_sparse_prefillaccepts, 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
ValueErrorafter the selection is built. So ATOM mirrors the rules (gfx942,_FLYDSL_WIDTHS = (1027, 2051, 3075, 4099)and the2**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).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 indicesValueError. Widths 1023, 1026, 1028, 2047, 2052, 4103 and 5123 are rejected, and the query says False for all of them. Withget_gfx_runtimepatched to gfx950, the queries answer()/Falseand the entry raisesQSA sparse attention requires gfx942.python3 op_tests/test_flydsl_qsa_sparse_prefill.py(default cases): rc 0, no failures.blackandruff check(ruff 0.16.0, as pinned in pre-checks): clean on the three files.Unverified:
aiter.ops.qsawas 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.pyskips whereflydslis not importable.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:
flydsl_qsa_sparse_prefill_availableand itsindicescheck callsflydsl_qsa_sparse_prefill_supports_selection, the same functions the queries use, so they cannot drift apart.tests/test_qsa_sparse_prefill_support.py: shape(M, 4T+3)withT % 256 == 0,256 <= T <= 1024, andnumel * 4 < 2**31.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_slotsor the lengths: those are still checked by the call.Changed op tests
None: no
op_tests/file changes. The new test istests/test_qsa_sparse_prefill_support.py. It needs no GPU, so it runs in the focusedpytest testsstep, and it covers only the new queries. The kernels stay covered by the unchangedop_tests/test_flydsl_qsa_sparse_prefill.py.