Skip to content

perf(qwen4_exp): Qwen3.8-Flash-Next TP prefill follow-ups: drafter FlyDSL QSA, row-sharded indexer selection, sequence-parallel drafter - #2847

Merged
valarLip merged 29 commits into
ROCm:mainfrom
zovonoir:qwen38-flash-tp-dedup-followup
Nov 9, 2026

Conversation

@zovonoir

@zovonoir zovonoir commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Stacked PR. It depends on #2653 (QSA FlyDSL prefill attention, head 93eb8e97e) and #2834 (sequence-parallel HC residual streams); merge order is #2653 -> #2834 -> this PR. Until those land, the diff also shows their commits. Review only the last eighteen commits:

  1. fb69dc2b0 perf(sglang): FlyDSL QSA attention for the drafter's eager prefill extend
  2. 219048aa5 perf(qwen4_exp): split the replicated QSA indexer selection across TP ranks
  3. bf9006828 perf(qwen4_exp): sequence-parallel MTP drafter prefill extend
  4. e5da84f4a fix(qwen4_exp): shard only above HC_QUANT_ROWS_MAX tokens (review follow-up on perf(qwen4_exp): sequence-parallel HC residual streams for Qwen3.8-Flash-Next TP prefill #2834's code, see below)
  5. 458bee5a3 test(qwen4_exp): row-sharded selection on the serving prefill scorer
  6. c76066cb0 test(qwen4_exp): drafter prefill extend matches its replicated forward under SP
  7. c338c29d3 fix(qwen4_exp): fused-quant floor for the target only; test _select_tokens(rows=)
  8. 632088a18 docs(env): ATOM_QWEN4_EXP_SP_MIN_TOKENS and ATOM_QSA_FLYDSL_ATTN
  9. cd3051d65 test(qwen4_exp): half-shard scoring calls in the row-sharded selection test
  10. 41ba3431e perf(sglang): build the FlyDSL QSA layout only when the kernel can run
  11. 9c909c545 fix(sglang): FlyDSL layout context rows on device; KV dtype from the bound pool
  12. 9caccaf95 test(qwen4_exp): FlyDSL QSA attention vs the native kernel on short contexts
  13. 4c3b815a9 fix(env): parse ATOM_QWEN4_EXP_SP_MIN_TOKENS with _nonnegative_int_env
  14. 5a1743a9c refactor(qwen4_exp): one FlyDSL QSA support predicate for the layer and the bridge
  15. 0a3e3b1cb fix(qwen4_exp): _SequenceParallel pads rows on dim 0 for any rank
  16. e66da95dd perf(qwen4_exp): head shape in the shared FlyDSL predicate; log its fallbacks
  17. 0d63078d3 perf(qwen4_exp): run QSA prefill attention on FlyDSL by default
  18. 90ec5dda0 fix(qwen4_exp): FlyDSL fallback warning states the state, not a setting

Fixes for review comments on the #2834 code will also land here; #2834 itself is frozen. The branch was rebased onto #2653's current head, which adds the prefixed FlyDSL context-gather test, so the commit hashes changed.

Summary

#2834 shards the hyper-connection (HC) residual streams across the TP ranks for large eager prefill forwards. This PR applies the same idea to two more places where TP4 prefill still does replicated work, and moves the MTP drafter's prefill extend onto #2653's FlyDSL attention.

Commit Bottleneck (TP4 prefill profile, MTP on) Change
FlyDSL attention for the drafter's prefill extend After each prefill chunk the drafter extends over the same tokens. Its QSA attention stayed on the native qsa_sparse_paged_gqa (16 ms per call) because build_qsa_metadata skipped the FlyDSL host layout for draft forwards. The target's call of the same shape takes about 1.3 ms with FlyDSL. atom/plugin/sglang/qwen4_exp_bridge.py: build host_lens / context_slots for every eager unpacked extend. Packed draft steps (decode, draft-extend-v2) return earlier and keep the native kernel. The drafter's prefill extend has the target's KV layout (one KV head per rank, D256), and #2653's _flydsl_attention gate still applies.
Split the replicated QSA indexer selection The QSA indexer (4-head MQA scoring of every compressed key group, then a per-row top-512 group select) uses ReplicatedLinear weights, so all TP ranks compute the same selection. At long context it is the fastest-growing part of prefill: at 129024 x 2, scoring plus top-k is about 16% of a 16K-token step. ops/qsa.py: qsa_select_paged_tokens is split into qsa_select_paged_groups (score + top-k) and the existing qsa_expand_block_indices; the combined call is unchanged. qsa_attention.py: under #2834's sharding (rows=sp), each rank scores and selects only its own query rows. The ranks then all-gather the [rows, block_topk] int32 group ids (2 KB per token) and expand all rows locally. The indexer K projection and the cache writes still cover every token.
Sequence-parallel MTP drafter prefill extend The drafter's pre-fc norms, fc_embedding, fc_hidden ([4T,2560]x[2560,2560]) and its unfused HC still ran replicated over every prefill token. _SequenceParallel.maybe() is now shared by the target and the drafter: TP > 1, at least ATOM_QWEN4_EXP_SP_MIN_TOKENS tokens, not capturing. Qwen4ExpMultiTokenPredictor.forward shards the embeddings and the target HC state, _forward_unfused(sp=) all-gathers the attention / MoE inputs and reduce-scatters their partial sums, and the four output streams are gathered once at the end. Draft decode, verify and draft-extend-v2 keep the current path when captured or below the threshold. An eager batch at or above it shards too, for example a verify batch above the graph's maximum batch size; that path is equally valid.

Numerics:

  • Drafter on FlyDSL. Within the kernel difference perf(sglang): aiter FlyDSL QSA sparse attention for Qwen3.8-Flash-Next eager prefill #2653 measured (1 BF16 ulp per layer). The drafter has a single layer, and its K/V depend only on the input, so this changes only the first draft token at each prefill position.
  • Indexer split. Identical selection logic per row, but not guaranteed bit-identical. Each row's selection depends only on its own query, request and position, and the output widths depend only on the batch-wide page table and max_seq_len, which every rank has. qsa_paged_mqa_logits picks its scorer by the row count of each call: stacked up to 256 rows; above that, FlyDSL in serving prefill (gfx942, BF16 keys) and Triton MFMA otherwise. With sharding only above 1024 tokens (480f72a29), TP2 and TP4 shards always have more than 256 rows, so they use the same scorer as the whole batch. A shard can still reach the stacked scorer through a logits-workspace chunk of 256 rows or fewer (at long context), which the unsharded path does for its own tail chunks too, or as a 129-256-row TP8 shard. The scorers agree on every visible logit to a few FP32 ulps: measured max differences of 1.9e-6 to 2.9e-6 at |logit| up to about 12. A different group can therefore only be picked at a top-k tie that close. No accuracy effect was observed: GSM8K 400 is 0.975 with and without this PR (see Results), and in earlier validation of the same change on the image tree, passkey retrieval at 3K-120K tokens (4 seeds per length) was 20/20 both with and without the split.
  • Drafter sharding. Mathematically identical; as in perf(qwen4_exp): sequence-parallel HC residual streams for Qwen3.8-Flash-Next TP prefill #2834, only the BF16 summation order can differ.

Tests:

  • tests/test_qwen4_exp_sequence_parallel.py::test_select_tokens_row_sharded_matches_replicated drives the real Qwen4ExpAttention._select_tokens(rows=_SequenceParallel) on simulated TP2 / TP4 / TP8 ranks: a prefixed + fresh 1500-row prefill, on the Triton scorer and on the FlyDSL scorer that serving prefill uses (gfx942). Every rank must end with the replicated selection and index caches. It fails if a shard scores the wrong positions.
  • tests/test_qwen4_exp_mtp.py::test_qsa_row_sharded_selection_matches_whole_batch compares the op-level row-shard selection with the whole batch exactly, across allow_flydsl False / True, TP2 / TP4 / TP8, 2503 and 1025 (the smallest sharded forward) rows, and three call sizes. "shard" scores each shard in one call. "half-shard" chunks it in two: TP2 / TP4 at 2503 rows and TP2 at 1025 rows stay above 256 per call, so this is the same scorer as the whole batch. "200-rows" is forced onto the stacked scorer as the deliberate cross-scorer case. All 36 cases match.
  • test_qsa_index_scorers_agree_on_visible_logits checks that the stacked scorer agrees with the FlyDSL / Triton MFMA scorer on every visible logit to atol 1e-5.
  • test_drafter_forward_matches_unsharded runs the real Qwen4ExpMultiTokenPredictor.forward and Qwen4ExpDecoderLayer._forward_unfused on simulated TP2 / TP4 ranks at 1024 / 1026 / 1027 tokens. Stand-in sub-layers return per-rank partial sums: a causal token-mixing attention and a per-token MoE. It compares against the unsharded forward and fails if the final gather or the MoE input gather is dropped.
  • test_sp_gates pins the target and drafter gates (next section).
  • The prefixed FlyDSL route (context_slots, request-major full-context K/V gather) is covered in perf(sglang): aiter FlyDSL QSA sparse attention for Qwen3.8-Flash-Next eager prefill #2653 by tests/test_qwen4_exp_qsa_flydsl_gate.py::test_mixed_prefix_batch_gathers_full_contexts, which this branch now includes. The drafter takes the same _flydsl_attention route.

Follow-up on #2834: the target shards only above HC_QUANT_ROWS_MAX (e5da84f4a, narrowed to the target in c338c29d3). In #2834, SP starts at ATOM_QWEN4_EXP_SP_MIN_TOKENS tokens (default 1024) and sharded layers skip mix_fused_quant, so the FP8 attention-input projection quantizes the gathered BF16 rows itself (aiter per_token_quant_hip). The unsharded path keeps the fused quant (hc_gated_mean_quant) up to HC_QUANT_ROWS_MAX (1024) tokens. As a result, an eager TP > 1 forward of exactly 1024 tokens (or any count between a lower env threshold and 1024) used a different activation-quant path with SP on than with SP off. The two paths can differ by about 1 ulp in the FP32 scale and in occasional FP8 roundings. Both paths already exist in production; the inconsistency was only which one a given size took. Qwen4ExpModel._sequence_parallel() now also requires num_tokens > HC_QUANT_ROWS_MAX, whatever the env value (0 still disables), so a sharded target forward always uses the same quantization as the unsharded one. The MTP drafter's unfused HC never fuses the quant, so the drafter keeps _SequenceParallel.maybe() with the env threshold alone, and shards from 1024 tokens. test_sp_gates pins both gates: at 1024 tokens only the drafter shards and the target stays replicated; at 1025 both shard; env 512 does not lower the target; env 2048 applies to both; env 0 disables. The forward-equivalence cases now use 1026 / 1027 / 1032 tokens.

Both flags are now documented in docs/environment_variables.md (632088a18).

FlyDSL host layout (41ba3431e, 9c909c545). build_qsa_metadata now builds the FlyDSL layout only when a QSA layer can take the kernel: ATOM_QSA_FLYDSL_ATTN, compression ratio 4 with a supported budget, a BF16 KV pool, and gfx942. The KV dtype is read from the same pool bind_qsa_caches binds the QSA caches from (forward batch, then attention backend, then its full_attn_backend). If the dtype cannot be read, the native kernel is kept. This matters because an FP8 SGLang pool binds no scale planes, so the layer cannot detect it. The context rows of prefixed batches are built on the device from the per-request lengths (upload_numpy plus repeat_interleave(output_size=), no host sync), instead of host index arrays staged through a fresh pin_memory() every forward.

The fourth piece of the original optimization, BF16 GEMM tuning for the drafter / mixer / PLE prefill shapes on MI308X, is an aiter tuned-config change and goes to ROCm/aiter separately: ROCm/aiter#7204.

Results

4x MI308X, TP4 / EP4, Qwen3.8-Flash-Next-PTPC-FP8, BF16 KV cache (--kv-cache-dtype bf16, for every number in this PR), MTP on (EAGLE 2 steps), radix cache on and flushed before each measured run; server-side #cached-token = 0 for every measured run. The image tree is the same as in #2834: ATOM 6293e75b5 (main a0527c9db plus the Qwen3.8-Flash SGLang PRs that have since merged and an earlier revision of #2653, ATOM_QSA_FLYDSL_ATTN=1), aiter 04a254638 with ROCm/aiter#6576, SGLang 94602c9c2b.

Workload: sglang.bench_serving random, range 1.0, OSL 1, ~800K input tokens per case. Each value is the mean of runs r1 and r2 after a discarded warmup run; where the two runs differed by more than 3% (marked *), r3 was added and r1-r3 are averaged. Baseline was measured earlier the same day with the same image, GPUs and scripts. The other three columns were measured back to back.

Input throughput, tok/s; each gain is over the previous column, and the last column is the total over baseline:

ISL x CON baseline #2834 this PR + aiter#7204 total
1024 x 64 22,953 28,015 (+22.1%) 28,913 (+3.2%) 29,806 (+3.1%) +29.9%
4096 x 32 23,169 28,813 (+24.4%) 29,534 (+2.5%) 30,450 (+3.1%) +31.4%
16384 x 16 22,222 27,252 (+22.6%) 28,521 (+4.7%) 29,300 (+2.7%) +31.9%
30720 x 8 21,521 26,377 (+22.6%) 28,197 (+6.9%) 28,734* (+1.9%) +33.5%
63488 x 4 20,818 25,016 (+20.2%) 27,218 (+8.8%) 27,760 (+2.0%) +33.4%
129024 x 2 19,154 22,853 (+19.3%) 25,968 (+13.6%) 26,675* (+2.7%) +39.3%
geomean 21,595 26,310 (+21.8%) 28,034 (+6.5%) 28,759 (+2.6%) +33.2%

This PR's gain grows with context length, because the indexer selection it splits grows with context. The same holds for TTFT: at 129024 x 2, mean TTFT is 12,684 ms (baseline), 10,620 ms (#2834), 9,359 ms (this PR) and 9,109 ms (+ aiter#7204).

baseline #2834 this PR + aiter#7204
GSM8K 400 (run_eval, chat, thinking off) 0.970 0.975 0.975 0.9775
MTP accept length (greedy, ISL 4096, OSL 16, 128 requests: the first draft of each request comes from the prefill extend) - 2.67 2.70 2.66

SP accuracy A/B with every prefill sharded. The run_eval GSM8K above only partly covers SP. With radix cache on, the shared few-shot prefix is cached, so only the first wave of 64 questions is prefilled in batches above the threshold, about 55% of prefill tokens; the other 336 questions prefill around 180 new tokens each and stay replicated. So this A/B uses benchmark/gsm8k/bench_sglang.py --num-shots 10 (chat template, thinking off, temperature 0) with --disable-radix-cache. Every question then prefills about 2.1K new tokens, and 99.97% of prefill tokens ran in batches above 1024 tokens. Same TP4 / EP4 MTP server and tree as the throughput table, which has #2834 and this PR's sharded drafter and indexer, so SP on vs off toggles all of them. Two runs per setting:

GSM8K 10-shot, all 1319 test questions, greedy run 1 run 2 mean
SP on (default) 0.964 0.970 0.967
SP off (ATOM_QWEN4_EXP_SP_MIN_TOKENS=0) 0.967 0.969 0.968

Per-question McNemar tests across all six pairs: SP on vs SP off differ on 23-28 answers with p = 0.17-1.0. The two SP-on runs differ on 28 answers (p = 0.13) and the two SP-off runs on 22 (p = 0.80): the run-to-run variation from MTP and batch composition is as large as the SP on/off difference. No accuracy effect from SP is detectable.

This PR's head on current main, real TP4. ATOM = this branch (main + #2653 + #2834 + this PR), aiter main 59fae2078 plus ROCm/aiter#6576's QSA attention kernels, SGLang 94602c9c2b. TP4 / EP4, BF16 KV, MTP on, ATOM_QSA_FLYDSL_ATTN=1.

check at 41ba3431e at 9c909c545 (head)
GSM8K 400 (run_eval, chat, thinking off, radix on) 0.9725 / 0.965 0.9775
GSM8K 10-shot, all 1319 questions, greedy, radix off (99.995% of prefill tokens in sharded batches) 0.968 -
Input throughput 30720 x 8 (OSL 1, no prefix hits) - 28,630 tok/s

Prefixed FlyDSL route vs native kernel (drafter and target prefill attention). These are per-layer QSA attention calls at TP4 per-rank shapes (6 Q heads, 1 KV head, D256, budget 2048, BF16 KV, random keys), on gfx942 with aiter main plus ROCm/aiter#6576's kernels. The FlyDSL time includes the request-major gather of the full-context K/V. The host layout (_flydsl_prefill_layout) runs once per forward, not per layer:

prefixes chunk tokens native qsa_sparse_paged_gqa ms FlyDSL route ms speedup host layout ms max / mean abs diff
4096 4096 4.32 1.17 3.7x 0.18 9.8e-4 / 8.0e-5
28672 4096 4.45 1.21 3.7x 0.51 2.0e-3 / 7.8e-5
61440 4096 4.54 1.39 3.3x 0.55 2.0e-3 / 7.8e-5
122880 8192 9.21 3.43 2.7x 0.83 9.8e-4 / 7.8e-5
0 / 8192 / 16384 / 32768 4 x 4096 18.05 4.69 3.9x 0.60 1.6e-2 / 8.6e-5

In the serving profile (4096 x 32, TP4) the drafter's prefill-extend attention took 16 ms per call on the native kernel, while the target's FlyDSL call of the same shape takes about 1.3 ms. Routing the drafter there took the DRAFT step from 50 ms to 36 ms. End to end, these numbers are part of the "this PR" column above.

TP2 on this PR's head

9caccaf95, aiter main 59fae2078 + the ROCm/aiter#6576 attention, SGLang b368e685e5, TP2 / EP2, otherwise the TP4 setup above (BF16 KV, MTP on, radix flushed, #cached-token = 0 in every measured run, ATOM_QSA_FLYDSL_ATTN=1 on both sides). SP off sets ATOM_QWEN4_EXP_SP_MIN_TOKENS=0, which turns off #2834's HC sharding, the indexer row split and the drafter SP together; SP on is the default. The two servers ran side by side on GPUs 4,5 and 6,7. Mean of r1 and r2 after a discarded r0; r1/r2 differ by at most 1.9%.

ISL x CON SP off SP on gain
1024 x 64 16,665 17,966 +7.8%
4096 x 32 16,682 18,208 +9.1%
16384 x 16 16,145 17,691 +9.6%
30720 x 8 15,839 17,524 +10.6%
63488 x 4 15,308 17,066 +11.5%
129024 x 2 14,416 16,364 +13.5%
geomean +10.3%

GSM8K 400 (run_eval, chat, thinking off): SP off 0.980, SP on 0.9725 (TP4 baseline 0.975).

Merged-mainline validation (all five PRs, current heads)

ATOM_QSA_FLYDSL_ATTN now defaults to on (0d63078d3): 0 / false / off disables it. With no flag set on the merged stack (TP4, GPUs 2,3,6,7), every rank logs the FlyDSL INFO line and no fallback; GSM8K 400 is 0.9725 and 4096 x 32 runs at 30,290 / 30,465 tok/s (r1 / r2). The table below was measured with the flag set explicitly.

ATOM main e281d58ac + #2653 93eb8e97e + #2834 + this PR e66da95dd (rebased onto #2653 after its import fix; #2834's three commits are identical to #2834 and drop on rebase once it lands). aiter main bd4ff1c70 + ROCm/aiter#7204 39cbce3f5 + ROCm/aiter#6576 2544b2927, with no pre-rename #6576 files left. SGLang v0.5.20 (94602c9c2b), as pinned by docker/sglang_release.dockerfile. ATOM_QSA_FLYDSL_ATTN=1, BF16 KV, MTP on, radix on and flushed before measured runs, #cached-token = 0 in every measured input run. Input is r1 after a discarded r0; reference values are r1-r3 means from the earlier image runs.

case this stack reference
TP4 input 1024 x 64 29,012 29,420
TP4 input 4096 x 32 30,310 30,375
TP4 input 129024 x 2 26,756 26,060
TP4 decode 4096 x 16 (OSL 2048) 1,484 tok/s, TPOT 9.48 ms, accept 2.53 1,397-1,506, 9.35-9.67 ms, 2.40-2.48
TP4 GSM8K 400 / greedy accept length 0.970 / 2.66 0.9725-0.9775 / 2.67-2.71
TP2 input 4096 x 32 18,478 18,208 (this PR, pre-rename), 16,173 (original image, same run)
TP2 input 30720 x 8 17,637 17,524, 15,285
TP2 decode 4096 x 16 (OSL 2048) 1,179 tok/s, TPOT 11.82 ms, accept 2.55 1,091, 12.90 ms, 2.50 (original image, same run)
TP2 GSM8K 400 / greedy accept length 0.970 / 2.68 0.975 / 2.68 (original image)

Every rank logs QSA attention runs eager prefill on the aiter FlyDSL kernel and no fallback. Radix: the repeated 65.7K-token customer request hits 65,664 cached tokens. Multimodal and customer requests finish with stop. tests/test_qwen4_exp*.py + tests/plugin/test_sglang_qwen4_exp*.py: 304 passed, so the real-kernel short-context test runs against #6576 2544b2927.

Test plan

zovonoir and others added 4 commits October 29, 2026 21:07
… aiter FlyDSL

Behind ATOM_QSA_FLYDSL_ATTN=1 (default off), SGLang-ATOM eager prefill calls
aiter's qsa_sparse_attention_flydsl (ROCm/aiter#6576) instead of
qsa_sparse_paged_gqa. The plugin records host query/seq lengths, and for
prefixed requests the flat cache rows of each full context, which are gathered
into contiguous K/V. Selections are padded with -1 to the next width the kernel
accepts. Decode, verify, draft and graph capture keep the native kernel.
ATOM_QSA_FLYDSL_ATTN_CHECK=1 also runs the native kernel and logs the
per-layer difference.
The check mode ran the native QSA kernel next to the FlyDSL one and logged
the per-layer difference. It was used to validate the FlyDSL path and is not
meant to land; feddb03 keeps it for reference.

Co-authored-by: Cursor <[email protected]>
…chs FlyDSL cannot serve

- Take the FlyDSL path only for compression ratio 4 and a budget of
  1024 / 2048 / 3072 / 4096. Padding a selection laid out for another
  budget moves the causal tail, and the kernel reads it at the wrong column.
- Fall back when the KV cache is quantized: the prefixed path gathers raw
  cache rows and the kernel accepts BF16 only.
- Fall back on anything but gfx942, where aiter's entry raises.

Addresses the review threads on ROCm#2653.

Co-authored-by: Cursor <[email protected]>
…tighten FlyDSL gate tests

- A padded selection of 2**31 bytes or more (e.g. a 131072-row eager
  prefill at budget 4096) makes aiter raise; keep the native kernel there.
- Gate tests no longer reach the real CUDA capture query, exercise padding
  with a genuinely short selection (width 11 -> 1027, -1 fill checked),
  and cover the byte limit.

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

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Run after the PR is approved and Pre Checkin passes
  • ✅ Run immediately when an approval review is submitted
  • ✅ Can be requested before approval with labels
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, and SGLang
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests

Heavy jobs are skipped when the PR is not approved and no matching ci:* label is present.
Add labels via the sidebar or gh pr edit 2847 --add-label <label>

@zovonoir
zovonoir marked this pull request as ready for review October 30, 2026 08:46
Copilot AI balanced review requested due to automatic review settings October 30, 2026 08:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Row sharding changes the scoring reduction order at the 256-row boundary, allowing FP32 rounding to alter near-tied top-k selections and invalidate the claimed bit-identical behavior.

1 open issue
What changed in this PR

This PR extends Qwen3.8-Flash-Next prefill optimizations in ATOM, building on the stacked FlyDSL attention and sequence-parallel residual-stream changes.

Changes:

  • Enables FlyDSL QSA attention for eligible eager drafter prefill extends.
  • Distributes QSA scoring and group selection across tensor-parallel ranks.
  • Shards drafter projections and hyper-connections, with selection-equivalence and sequence-parallel tests.
File Description
tests/​test_qwen4_exp_sequence_parallel.py Tests simulated collectives, padding, and target-model sharding.
tests/​test_qwen4_exp_qsa_flydsl_gate.py Tests FlyDSL eligibility, padding, and native fallbacks.
tests/​test_qwen4_exp_mtp.py Adds row-sharded selection equivalence coverage.
atom/​utils/​envs.py Defines FlyDSL and sequence-parallel controls.
atom/​plugin/​sglang/​qwen4_exp_bridge.py Builds FlyDSL layouts for eligible target and drafter extends.
atom/​models/​qwen4_exp.py Shares sequence-parallel helpers and supports sharded decoder execution.
atom/​models/​qwen4_exp_mtp.py Shards drafter projections and gathers output streams.
atom/​model_ops/​qwen4_exp/​qsa_attention.py Integrates row-sharded selection and gated FlyDSL attention.
atom/​model_ops/​qwen4_exp/​ops/​qsa.py Separates group selection from token-index expansion.
atom/​model_ops/​attentions/​qwen4_exp_attn.py Adds host lengths and context slots to QSA metadata.

Review effort: Balanced

…h fallbacks

- test_mixed_prefix_batch_gathers_full_contexts: a prefixed / fresh / prefixed
  batch with unequal lengths on non-consecutive pages crossing page
  boundaries. _flydsl_prefill_layout must return every request's full context
  rows in request-major order, and _flydsl_attention must hand the kernel
  exactly those K/V rows with the per-request query and prefix lengths.
- tests/plugin/test_sglang_qwen4_exp_graph_padding.py: _flydsl_prefill_layout
  returns no context rows for an unprefixed batch, and (None, None) for padded
  tokens, partial batches, missing host lengths and an extend longer than its
  sequence.
ZLkanyo009
ZLkanyo009 previously approved these changes Oct 30, 2026

@ZLkanyo009 ZLkanyo009 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, approving. I reviewed this PR's own three commits (65f0930, 5381862, f25d8ab); the rest of the branch is #2653 and #2834, which I approved separately.

  • Row-sharded indexer selection:
    • No hang risk. _select_tokens has no rank-dependent return before rows.gather(groups). Even a rank with an empty slice allocates [0, block_topk], pads it to rows.chunk and joins the gather. block_topk comes from _selection_widths over batch-wide data, so the gathered shapes match on every rank.
    • Same result. Padding sits only on the trailing ranks, so trimming in gather restores the row order. Expanding after the gather gives the same int32 selection with the same -1 columns as the combined call.
  • Drafter FlyDSL: this only applies to unpacked eager extends, whose host lengths and positions match the target's. The prefix K/V comes from the drafter's own cache, and #2653's fallbacks still apply.
  • Sequence-parallel drafter:
    • Valid to shard. The fc and HC weights are replicated and every op before the attention/MoE gather is per-token, so sharding tokens is valid.
    • Reduce-scatter is correct. With reduce_results=False on the MoE and the shared expert, the reduce-scatter of their summed partials is correct.
    • Output and hand-off. The output is gathered back before the view(n, hc, D), and the target still gathers its HC state before the hand-off.

One optional wording fix: the description says draft decode, verify and draft-extend-v2 are "below the threshold or captured". Eager batches of ATOM_QWEN4_EXP_SP_MIN_TOKENS or more tokens can still take the sharded drafter path, e.g. verify above the graph max batch size (342+ requests at 3 tokens each). As far as I can tell that path is correct too, so this only affects the description.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The tests do not exercise the new drafter sequence-parallel forward path, and the chunked scoring test selects a different scorer from its reference, missing the intended same-scorer comparison.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Add TP drafter forward-equivalence coverage for the SP path

atom/​models/​qwen4_exp_mtp.py:151

The new drafter SP branch is not exercised by the forward-equivalence tests: test_model_forward_matches_unsharded uses Qwen4ExpModel with a stand-in _Layer, while test_mtp_shared_projection_uses_full_width_hidden_norm uses only five tokens and stays unsharded. Neither would catch a missing or misordered gather/reduce-scatter in the new MTP path. Please add TP2/TP4 comparisons of the drafter forward against its unsharded result, with more than 1024 tokens and an uneven split, exercising the new _forward_unfused(sp=...) path as well as the pre-FC sharding.

Medium severity Use half-shard chunks to exercise the intended scorer

tests/​test_qwen4_exp_mtp.py:653

This workspace limit caps each scoring call at 200 rows, selecting the stacked scorer by default while the 2503-row reference uses the MFMA scorer. The test therefore misses the intended same-scorer comparison, and exact equality depends on the accepted cross-scorer rounding differences not affecting this fixture. Use half a shard as the chunk size so every scoring chunk in these TP2/TP4 cases stays above 256 rows while still exercising chunking.

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 30, 2026 11:42
@zovonoir

Copy link
Copy Markdown
Contributor Author

Re the indexer-split test (both sides used allow_flydsl=False, while serving prefill uses allow_flydsl=True; at TP4 with 1024 tokens each rank had exactly 256 rows, which crosses from the FlyDSL / Triton scorer to the stacked scorer):

  • The 256-row TP4 case no longer shards. Since 480f72a29, SP only runs above HC_QUANT_ROWS_MAX (1024) tokens, so TP4 shards have at least 257 rows and TP2 shards at least 513. Both use the same >256-row scorer as the whole batch. A shard still reaches the stacked scorer through a logits-workspace chunk of 256 rows or fewer (at long context), which the unsharded path also does for its own tail chunks, or as a 129-256-row TP8 shard.
  • Scorer switch, measured. On every visible column, the stacked scorer agrees with the FlyDSL and Triton MFMA scorers to 1.9e-6 to 2.9e-6, at |logit| up to about 12, which is a few FP32 ulps. So the selection can only change at a top-k tie that close.
  • Tests (456f8f8a3). test_qsa_row_sharded_selection_matches_whole_batch now runs allow_flydsl False and True (FlyDSL skipped off gfx942), TP2 / TP4 / TP8, and two batches: 2503 rows, and 1025 rows, the smallest sharded forward (257-row TP4 and 129-row TP8 shards). Each case runs with shard-sized scoring calls (same scorer as the whole batch, except TP8 at 1025) and with 200-row calls (forced onto the stacked scorer). All 24 cases select exactly what the whole batch selects. test_qsa_index_scorers_agree_on_visible_logits pins the logit agreement to atol 1e-5. tests/test_qwen4_exp*.py: 148 passed on gfx942.

This also covers Copilot's "use half-shard chunks to exercise the intended scorer": the shard-sized calls are the same-scorer comparison, and the 200-row calls are kept on purpose as the cross-scorer one. The description's numerics and test notes are updated accordingly, including the drafter wording: eager batches at or above the threshold shard too.

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes needed

ci jobs cancelled, please re-run. any perf number? gsm8k? drafter sp equivalence test?

ci green.

Comment thread tests/test_qwen4_exp_mtp.py Resolved
Comment thread atom/models/qwen4_exp.py Resolved
Comment thread atom/utils/envs.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The sharded drafter’s unfused sequence-parallel path lacks automated regression coverage, leaving collective ordering, token-row alignment, and returned hyper-connection state unchecked.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Add regression test for sharded drafter unfused forward alignment

atom/​models/​qwen4_exp_mtp.py:161

No automated test exercises the sharded drafter forward through _forward_unfused(sp=...), leaving its collective ordering and token-row alignment unchecked. Add a TP2/TP4 predictor regression against sequence parallelism disabled, using more than 1024 tokens and an uneven row count. Exercise the unfused decoder with simulated collectives, checking both the returned hyper-connection state and the rows passed to attention and MoE.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 30, 2026 11:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The drafter’s collective sequencing and QSA dispatch require real multi-rank validation of the rebased TP4 MTP path with aiter, while existing tests use simulated collectives or a single GPU, serving measurements use an earlier image, and SGLang CI remains pending.

No open issues 🎉

Review effort: Balanced

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please cover the prefixed flydsl route and _select_tokens(rows)..

any perf number? and the prefixed flydsl path vs native kernel?

ci green.

Comment thread atom/utils/envs.py Resolved
Comment thread atom/models/qwen4_exp_mtp.py Resolved
Comment thread tests/test_qwen4_exp_mtp.py Resolved
@zovonoir

Copy link
Copy Markdown
Contributor Author

Two follow-ups:

  • Copilot, "Add TP drafter forward-equivalence coverage for the SP path" (atom/models/qwen4_exp_mtp.py:151): added in 36c084ccb. test_drafter_forward_matches_unsharded runs the real Qwen4ExpMultiTokenPredictor.forward and Qwen4ExpDecoderLayer._forward_unfused on simulated TP2 / TP4 ranks at 1026 / 1027 tokens (uneven splits above the threshold). Stand-in attention mixes tokens causally and MoE is per-token, each returning per-rank partial sums. The test compares against the unsharded forward, covering the pre-fc sharding, the attention / MoE gathers and reduce-scatters, and the final gather. It fails if the final gather or the MoE input gather is dropped. tests/test_qwen4_exp*.py: 151 passed.
  • SP accuracy with every prefill sharded. The run_eval GSM8K only shards about 55% of prefill tokens, because radix caching leaves most questions around 180 new tokens. So I ran GSM8K 10-shot with radix cache off, on all 1319 questions, greedy: every question prefills about 2.1K tokens, and 99.97% of prefill tokens ran in sharded batches. SP on: 0.964 / 0.970. SP off: 0.967 / 0.969. On vs off differ on 23-28 answers (McNemar p 0.17-1.0), and two runs of the same setting differ on 22-28. Details are in the description.

@zovonoir
zovonoir force-pushed the qwen38-flash-tp-dedup-followup branch from 36c084c to 0d5d43d Compare October 30, 2026 12:57
Copilot AI balanced review requested due to automatic review settings October 30, 2026 12:57

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes needed..

ci green.

Comment thread atom/utils/envs.py Resolved
Comment thread tests/test_qwen4_exp_qsa_flydsl_gate.py Resolved
With ATOM_QSA_FLYDSL_ATTN on by default, "ATOM_QSA_FLYDSL_ATTN=1, but ..."
named a setting the operator may never have made. The warning now reads
"FlyDSL QSA prefill attention is enabled, but QSA attention uses the
native kernel: <reason>".
Copilot AI balanced review requested due to automatic review settings October 31, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Coupled FlyDSL dispatch and tensor-parallel collective changes require human confirmation of prerequisite merge ordering, pending SGLang CI, and multi-GPU behavior that could not be verified in this environment.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@zovonoir

zovonoir commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

@valar-cop @valar-cop @valar-cop @valar-cop @valar-cop @valar-cop @valar-cop @valar-cop
STOP raising new comments every few hours. If there is feedback, consolidate it and provide it in a single review. The comments you've made so far concern different parts of the code, which means they could and should have been identified and raised together rather than trickling in over several hours.

From this point on, if you have additional feedback, please wait until you have completed your review of all relevant code paths and then provide ALL REMAINING COMMENTS AT ONCE. This will make the review process significantly more efficient for everyone involved.

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small things..

ci green.

Comment thread tests/test_qwen4_exp_qsa_flydsl_gate.py Resolved
Copilot AI balanced review requested due to automatic review settings November 4, 2026 09:04
JiaoliangYu
JiaoliangYu previously approved these changes Nov 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The cross-stack GPU attention and collective changes require maintainer confirmation of dependency merge order and real-kernel/multi-GPU validation unavailable in this static-only review environment.

No open issues 🎉

Review effort: Balanced

main now carries ROCm#2653 (083891e) and ROCm#2834 (d1fcfc7) as squash
commits, which add the same content this branch already had from their
original commits and then changes. The seven conflicts
(qsa_attention.py, qwen4_exp.py, qwen4_exp_bridge.py, envs.py,
test_sglang_qwen4_exp_graph_padding.py, test_qwen4_exp_qsa_flydsl_gate.py,
test_qwen4_exp_sequence_parallel.py) were resolved by a three-way merge
against ROCm#2834's head on this branch (338c59d) instead of the merge base:
each takes this branch's version.

The tree's diff against main is exactly the diff of this PR's own
commits (338c59d..90ec5dd).
Copilot AI balanced review requested due to automatic review settings November 5, 2026 01:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Sharding drafter FC inputs changes dynamic per-tensor quantization from a full-batch to a shard-local scale, causing output differences beyond BF16 summation-order effects when shard activation ranges differ.

1 open issue

Review effort: Balanced

Comment thread atom/models/qwen4_exp_mtp.py Resolved
@zovonoir

zovonoir commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@JiaoliangYu @ZLkanyo009 your earlier approvals were dismissed by later pushes. The current head is b3624f614. The stacked dependencies #2653 and #2834 are both merged, all review threads are resolved, and CI is green. Could you re-approve? @valarLip @yhl-amd, could one of you merge it once it is approved? Thanks!

@valarLip
valarLip merged commit cd2f5a0 into ROCm:main Nov 9, 2026
demonsan pushed a commit to demonsan/ATOM that referenced this pull request Nov 11, 2026
Conflicts resolved, keeping main's behaviour and re-applying the provider
hooks at the equivalent places:

* atom/model_engine/model_runner.py: imports only (main added
  local_device_index; ours configure/prewarm_aiter_fused_ops). The
  configure-before-build and prewarm-after-KV-bind-before-capture call sites
  merged cleanly and keep their order (AST-tested).
* atom/model_ops/qwen4_exp/qsa_attention.py: main's ROCm#2847 split selection into
  the whole-batch qsa_select_paged_tokens and the row-sharded
  qsa_select_paged_groups (+ gather + qsa_expand_block_indices). Both entries
  now switch together: self.qsa_select / self.qsa_select_groups are None
  (stock) unless an enabled provider declares the routed
  aiter.ops.qsa.qsa_paged_mqa_logits.

Drift: main changed ops/qsa.py's selection loop (ROCm#2847: _selection_widths,
qsa_select_paged_groups, qsa_select_paged_tokens as a wrapper). select.py
re-synced: qsa_select_paged_groups_with_scorer (stock groups loop, scorer
injected) and qsa_select_paged_tokens_with_scorer (stock wrapper over it);
both AST-compared with qsa.py. The rest of qsa.py (scorer, kernels, helpers)
is unchanged from the frozen 8a07708 reference; the whole-file sha pin is
replaced by a pin of qsa.py outside the selection entries (4f48345d..., equal
at 10b99a0 and 920a200).

Tests: row-sharded call site off/on, groups copy scoring through the routed
op. a08-1 no-device container: 207 passed (targeted suites).
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.
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.

7 participants