Repository navigation
[AMD][Qwen3.5] TP2 prefill: overlap the layer all-reduces with compute over SDMA (on by default) - #118
Merged
sammysun0711 merged 6 commits intoDec 2, 2026
Conversation
yicyang
marked this pull request as ready for review
November 30, 2026 03:28
There was a problem hiding this comment.
🟡 Changes recommended
CUDA-graph replay can read stale rows, and chunked dynamic FP8 projections change activation scaling, compromising computational correctness.
3 open issues
What changed in this PR
This PR reuses the Qwen4/mori SDMA infrastructure to overlap Qwen3.5 MoE TP2 prefill communication with projection and MoE computation on AMD GPUs.
Changes:
- Adds a chunked bf16 all-reduce pipeline with batch-size-based chunk counts and fallback checks.
- Updates the Qwen3.5 35B launcher and CI case to TP2, enabling mori and FlyDSL GDN decode.
- Adds correctness and timing benchmarks, optimized-path CI log checks, tests, and documentation.
| File | Description |
|---|---|
scripts/ci/test_qwen4_ci.py |
Tests workload selection and required optimized-path logs. |
scripts/ci/qwen4_ci.py |
Updates the TP2 workload and verifies optimized kernels through server logs. |
python/sglang/srt/models/qwen3_5.py |
Wraps output projections and dispatches eligible prefills to SDMA. |
python/sglang/srt/models/qwen3_5_sdma_all_reduce.py |
Implements eligibility checks, chunked reductions, and pipelined layer execution. |
python/sglang/srt/layers/sdma_mori.py |
Generalizes fallback warning and docstring wording to cover RCCL and aiter collectives. |
python/sglang/srt/environ.py |
Documents Qwen3.5 meanings of existing switches; defaults are unchanged. |
evaluation/Qwen4_Evaluation_Guide.md |
Updates TP2 launch instructions, workloads, and CI requirements. |
evaluation/launch_qwen3.5-35B-fp8_tp2_disable_prefix_cache.sh |
Configures TP2, the mori environment, and FlyDSL GDN decode. |
benchmark/qwen4_seq_parallel/README.md |
Documents the pipeline, tuning controls, and reported performance. |
benchmark/qwen4_seq_parallel/bench_qwen35_sdma_all_reduce.py |
Adds two-GPU correctness checks and layer-like timing comparisons. |
Review effort: Balanced
… over SDMA Qwen3.5-35B-A3B TP2 prefill spends ~28% of its GPU time in the two all-reduces per layer (RCCL at the xGMI limit for 32k-token batches). Apply the Qwen4-Exp SDMA overlap to Qwen3.5's plain residual stream: at TP2 an all-reduce is "push the partial to the peer, then add", so the residual stays replicated. - out_proj / o_proj run in row chunks; each chunk's partial is pushed to the peer over SDMA (mori, SdmaAllGather writer) as soon as it is computed. - Per landed chunk: rank 0 rows + rank 1 rows (bit-identical on both ranks), residual add + RMSNorm, then the MoE on that chunk with its all-reduce skipped; its output is pushed the same way and consumed by the next layer's input norm chunk by chunk. Eager TP2 EXTEND batches of Qwen3.5 MoE (qwen3_5_moe_text) only; everything else, including Qwen4-Exp / Qwen3.8, keeps its path. Shares the Qwen4 switches (no new environment variable): SGLANG_QWEN4_SP_SDMA_RS (default on), SGLANG_QWEN4_SEQ_PARALLEL_MIN_TOKENS (2048) and SGLANG_QWEN4_SP_SDMA_RS_CHUNKS (Qwen3.5 default 4). Without mori the all-reduce runs, with a warning. The TP2 launcher sets the mori runtime environment. Signed-off-by: Ethan Yang <[email protected]>
Select the gfx942 FlyDSL fused GDN decode kernel (qkvz/ba unpack + conv1d update + recurrence in one launch) with --linear-attn-decode-backend aiter. Qwen3.5 shares Qwen3_5GatedDeltaNet with Qwen3.8; at TP2 it runs 8 k-heads / 16 v-heads per rank (ratio 2), which the kernel's (H, HV) JIT covers. Signed-off-by: Ethan Yang <[email protected]>
…ch and docs - qwen4_ci.py: Qwen3.5-35B-TP2-Base fails when its server log lacks the FlyDSL GDN decode or, after the performance phase, the SDMA all-reduce line, so a missing mori cannot pass silently. Accuracy-only runs, which may stay below the 2048-token threshold, only require the decode line. - test_qwen4_ci.py: cover the check and give the sgl-project#117 workload test a server log with both lines. - benchmark/qwen4_seq_parallel: two-GPU correctness and layer timing for the Qwen3.5 SDMA all-reduce; README section with the serving results. - Evaluation guide: the 35B TP2 launcher's SDMA / mori requirement and the new CI check. Signed-off-by: Ethan Yang <[email protected]>
Each row chunk re-runs the MoE (gate, topk, sorting, quant, two GEMMs), the projection quant + GEMM and the add + norm, about 7 ms of host time per layer at 4 chunks regardless of the batch size. Small prefills were host-bound: single 4k-token requests went from 132 ms to 338 ms (GPU idle 329 of 434 ms), which cancelled the large-batch gain in the 8k-token CI workload's TTFT. Single-request prefill latency on MI308X TP2 (ms): tokens all-reduce 1 chunk 2 chunks 4 chunks 4096 132 143 199 338 8000 225 233 223 342 12000 337 362 298 352 16000 460 483 399 386 24000 724 740 657 598 32000 1021 1041 924 842 - Batches under 8192 tokens keep the all-reduce; 2 chunks up to 16383 tokens, 4 from 16384. - SGLANG_QWEN4_SEQ_PARALLEL_MIN_TOKENS and SGLANG_QWEN4_SP_SDMA_RS_CHUNKS still override, but only when set: their defaults are Qwen3.8's. - CI: smoke runs send single 8k prompts, now under the threshold, so the SDMA log line is only required after the full performance phase. Signed-off-by: Ethan Yang <[email protected]>
…bench.sh defaults Signed-off-by: Ethan Yang <[email protected]>
- Keep the all-reduce with speculative decoding (MTP drafts got accept length 1.0 on this path) and with LoRA (its wrappers replace o_proj / out_proj and bypass the chunked push, which raised on the first large prefill); also check at init that every projection is still wrapped. - Size the receive buffers to min(max prefill, chunked prefill) tokens and keep the all-reduce for larger batches; log the buffer size. - Require bf16 activations and a TP-partial MoE output. - Agree on SDMA availability across ranks before the group collective. - Disable the path after an exception mid-forward. - Reject SGLANG_QWEN4_SP_SDMA_RS_CHUNKS < 1. - Trim comments; README notes the excluded cases; the shared mori warning no longer names the aiter reduce-scatter. Signed-off-by: Ethan Yang <[email protected]>
yicyang
force-pushed
the
qwen35-tp2-sdma-ar-overlap
branch
from
December 1, 2026 05:56
6caf861 to
81bcc64
Compare
sammysun0711
reviewed
Dec 1, 2026
apinge
reviewed
Dec 2, 2026
apinge
approved these changes
Dec 2, 2026
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



[AMD][Qwen3.5] TP2 prefill: overlap the layer all-reduces with compute over SDMA (on by default)
Based on #117 (Qwen3.5 35B TP2 launcher and CI). Qwen3.5-35B-A3B TP2 prefill spends about 28% of its GPU time in the two all-reduces per layer: for 32k-token batches RCCL moves 128 MB per all-reduce at the xGMI limit (~2.45 ms each), with the compute units idle. This PR applies the Qwen3.8 SP + SDMA overlap idea (#89) to Qwen3.5 and moves those all-reduces under the GEMM / MoE.
How to enable
On by default in
evaluation/launch_qwen3.5-35B-fp8_tp2_disable_prefix_cache.sh(it now exports the mori runtime environment). No new environment variable; Qwen3.5 shares the Qwen4 SDMA switches:SGLANG_QWEN4_SP_SDMA_RS0keeps the all-reduceSGLANG_QWEN4_SEQ_PARALLEL_MIN_TOKENSSGLANG_QWEN4_SP_SDMA_RS_CHUNKSEXTENDbatches ofqwen3_5_moe_textmodels of at least 8192 tokens. Decode, CUDA-graph batches, speculative decoding (MTP / DFlash), LoRA, non-bf16 activations, TP != 2, DP attention and EP keep the original path.evaluation/Dockerfile.ci); without it the server logsSP SDMA overlap disabled (...)and keeps the all-reduce.Qwen3.5 TP2 prefill: all-reduces over SDMA in 2 / 4 ... row chunks.The launcher also selects the FlyDSL GDN decode (
--linear-attn-decode-backend aiter, #111), separate commit.Design
At TP2 an all-reduce is "push the whole partial to the peer, then add" - the same bytes per rank as reduce-scatter + all-gather - so Qwen3.5 does not need the Qwen3.8 sequence-parallel residual. It reuses the #89 SDMA machinery (
SdmaAllGatherrow-range writer, moriput_ptr+ engine-side completion signals, one-wave wait kernel):out_proj/o_projrun per row chunk and push each partial chunk as soon as it is computed.The post-attention norm and the MoE consume the all-reduce chunk by chunk, so chunk i+1's copy runs under chunk i's MoE; the MoE output is pushed the same way and consumed by the next layer's input norm.
Each landed chunk is summed as rank 0 rows + rank 1 rows on both ranks, so the replicas stay bit-identical; only the first chunk's wait and the last MoE chunk's copy stay exposed (figure).
Chunk count follows the batch. Each chunk re-runs the MoE (gate, topk, sorting, quant, two GEMMs), the projection quant + GEMM and the add + norm: about 7 ms of host time per layer at 4 chunks whatever the batch size, so small prefills would be host-bound (single 4k-token request: 132 -> 338 ms at 4 chunks, GPU idle 329 of 434 ms). Measured single-request prefill latency (ms):
Double buffering: a rank pushes all-reduce n only after it received all of n-1, which its peer posts after it finished reading n-2 (same slot).
Results
MI308X, TP2,
evaluation/run_qwen35_pure_text_bench.shwith its defaults (random 8000 in / 500 out, 128 prompts, 10 warmup, seed 42) at c8 / c16 / c32; radix cache off, no MTP, fresh server per configuration. Base = #117 as is; "+ GDN decode" = this PR withSGLANG_QWEN4_SP_SDMA_RS=0. Every number is the mean of two rounds (GPUs 2,3 and 6,7 swapped between rounds; round-to-round QPS spread at most 3.0% base, 0.5% GDN, 1.7% this PR).Accuracy
SGLANG_QWEN4_SEQ_PARALLEL_MIN_TOKENS=1): 0.9500 vs 0.9507 base.bench_qwen35_sdma_all_reduce.py, max rel. error 3.6e-3 vs an fp32 reference).Qwen3.8 is unchanged
The Qwen3.5 path is gated on
model_type == "qwen3_5_moe_text"and lives inQwen3_5ForCausalLM.forward, whichQwen4ExpModeloverrides; the shared environment variables keep their Qwen3.8 meaning. Qwen3.8-Flash-Next TP2 (MTP off,launch_qwen38_flash_next_fp8_mi308x_pure_tp_4_or_8_or_2.sh), two rounds each:Tests and CI
scripts/ci/qwen4_ci.py:Qwen3.5-35B-TP2-Basefails when the server log lacks the FlyDSL GDN decode or, after the performance phase, the SDMA all-reduce line, so a missing mori cannot pass silently.scripts/ci/test_qwen4_ci.pycovers both and the accuracy-only exemption (80 passed).benchmark/qwen4_seq_parallel/bench_qwen35_sdma_all_reduce.py: two-GPU correctness (bit-identical ranks, odd row counts, delayed producer) and a layer stand-in timing; README and the evaluation guide document the Qwen3.5 path.Trace
Before (out_proj)

Before(MOE)

After(out_proj)

After(MOE)
