perf(split): faster R9700 + iGPU split decode (+36.9% Qwen3.8-Flash-Next), ported to DeepSeek V4.1 and Qwen3.8-27B
Summary
Faster decode when a model is split across an R9700 (dense layers, attention, hot experts, the drafter) and a gfx1151 iGPU (cold experts; the engine calls it the Strix), and the same ideas ported to DeepSeek V4.1 and Qwen3.8-27B. Every change is exact: greedy output is the same text as main.
Measured on an R9700 + Ryzen AI Max+ PRO 495 box:
| Model, setup | main | this PR | text |
|---|---|---|---|
| Qwen3.8-Flash-Next split, 1 slot, 11.8 GB hot experts, MTP width 3 | 61.02 tok/s | 83.51 tok/s (+36.9%) | same |
| DeepSeek V4.1 1017, ds41-r9700-gorgon, decode step (short / 2K / 26K prompt) | 59.1 / 61.4 / 59.9 ms | 57.7 / 58.5 / 57.8 ms (-2.4 / -4.7 / -3.5%) | same |
| DeepSeek V4.1 1017, one request with the drafter, code / prose / 1,951-token prompt (three and two runs) | 52.1-53.0 / 39.9-40.9 / 45.4 tok/s | 56.3 / 43.8-44.5 / 48.5 tok/s (+6 to +10%) | same |
| DeepSeek V4.1 1017, 4 slots paged without the drafter, each request with 1 / 2 / 4 active | 22.5-23.9 / 12.7-13.3 / 7.6-8.0 tok/s | 22.3-23.5 / 13.2-13.7 / 7.7-8.4 tok/s (no change) | same alone |
| Qwen3.8-Flash-Next split, 4 slots, full context (as Manage launches it), one request / 4 at once | 51.4 / 67.3 tok/s | 60.8 / 71.8 tok/s (+18.3 / +6.6%) | same |
| Qwen3.8-Flash-Next on the iGPU alone, 4 slots (as Manage launches it), one request / 4 at once | 38.2 / 52.5 tok/s | 42.0 / 54.6 tok/s (+10.0 / +3.9%), measured before the last commit, which costs a lone request 1-2% | same |
| Qwen3.8-27B, 8 slots paged (as Manage launches it), 1 / 2 / 4 / 8 requests at once, two runs each | 113-125 / 174-191 / 277-297 / 425-438 tok/s | 117-125 / 174-181 / 288-296 / 435-448 tok/s (no change beyond the runs' spread) | not compared: this model's greedy text already differs between two runs of main |
DeepSeek V4.1 is compared by step time: its drafter's acceptance moves a few percent between runs of the same build while the text stays the same, so tok/s carries that noise.
What changed
Qwen3.8-Flash-Next split engine (server/src/qwen4exp), in the order the changes landed (each measured alone, same text):
| Change | Split decode |
|---|---|
| GDN step in fewer launches (conv step, gated norm writing q8_1 rows, rms_norm + scale), Strix Q4_K expert prefetch, route-norm alias fix | +9.2% |
| Router in one launch, its outputs ahead of the expert nodes; verify rollback as one batched copy | +1.7% |
| Batched peer copies, one copy kernel per hop | +1.1% |
| One expert split per MoE layer | +2.7% |
| Scheduler: split events recorded when the next split starts | +0.9% |
| HC mix fused (all 96 verify mixes), split stable inputs async | +1.1% |
| Rollback on a side stream, async draft uploads, Strix idle hold | +1.7% |
| Pinned staging for verify uploads, output reads and the draft id read | +1.3% |
R9700 reads the next layer's first weights into its Infinity Cache while it waits for the Strix (ggml_moe_fused_prefetch, 56 MB) | +4.5% |
Strix read-ahead: a Q8_0 copy of the next router guesses the cold experts and reads their gate/up slices into the MALL (ggml_moe_fused_prefetch_rows) | +4.7% |
| Strix Q4_K expert loop at 2 rows per wave with the rounding written out | +1.3% |
| Strix wake hold: one wave sleeps until the R9700's router posts, so the first kernel after the hop runs at speed | +0.6% |
| Hop copy captured at the graph's tail | +1.0% |
| PLE conv fused at every width, verify argmax in two launches | +0.3% |
| RMS_NORM -> MUL -> ROPE fused on the R9700 too | +0.1% |
| Concat as one copy launch | +0.3% |
LM head: the last 20% of rows on the Strix, both GPUs on the RDNA4 Q8_0 matvec (per-node flag ggml_backend_cuda_mul_mat_rdna4_rows, so every logit keeps the R9700's bits) | +0.5% |
ggml-cuda (every model): argmax in two launches for rows of 8192+ (same pick rule), contiguous concat of up to 1 MiB as one copy launch, a batched copy kernel, split events recorded when the next split starts, a barrier fix in the soft_max and group_norm reductions (a race), the RDNA4 Q8_0 matvec on RDNA3.5 for flagged products.
DeepSeek V4.1 (server/src/deepseek4/deepseek4_fused_verify.inc, server/src/common/moe_hybrid_ffn_eval.*): in every MoE layer of the split verify the R9700 waits for the expert device's cold-expert sum once its hot and shared experts are done. In that wait it now reads the next layer's first 56 MiB of attention weights (the output head after the last layer) into its 64 MB Infinity Cache, through a new MoeHybridGraphInputs::prefetch_next list. Nothing the graph reads changes. 40 MiB gains less, 72 MiB (past the cache) loses.
Qwen3.8-27B (server/src/qwen35, one GPU): the RMS_NORM -> MUL -> ROPE [-> PERMUTE -> CONT] fusion now runs for every HIP M-RoPE graph, including the Qwen3.5 family's interleaved M-RoPE (attention Q and K: one launch each instead of three or four), with the separate kernels' bits.
This PR no longer changes how the Qwen3.8-27B engine commits accepted tokens after a batched verify round: that rework measured no clear gain on that model, and #964 reworks the same step with its own design, so it is left to that PR (reverted here in one commit; server/src/qwen35 is identical to main). The one piece the later commits here build on, ggml_backend_cuda_enter_stream (the single entry for work queued on a backend's stream from outside its own launches), stays. After the revert and the merge with main: both product builds, the split unit tests (31 of 31, 7 of 7), the exactness smoke on the iGPU alone and split, and 1 to 4 requests at once give the same text (39 of 39 requests) and the same speed as before.
Exactness
Texts compared run by run against main: Qwen3.8-Flash-Next (short prompts, 191 to 70K tokens of context), DeepSeek V4.1 (short, 2K and 26K prompts, x2). Unit tests, all passing on both GPUs with HIP graphs on and off:
test_qn_split_fusions(28): every fusion against the segmented graph, bitwise; the LM head row split on both GPUs at 1, 3, 4 and 8 columns (0 differing outputs; the Strix's own matvec differs in 73% of them, which is why the flag exists).test_norm_rope_fusion: 30 chains fused per GPU (standard and interleaved M-RoPE), same hash as the separate kernels, with and without the qwen4exp profile.test_cuda_copy_batch(6),test_ple_conv_fusion,test_ds41_mmid_width_invariance,test_deepseek4_unit,test_qwen4exp_chunk,test_server_unit(1205).
Known limits
- Five constants are fitted to one R9700 + iGPU pair and documented with their measurements where they are defined: the LM head share on the expert device (20%), the read-ahead depth (8 picks, 16 experts), the wake hold (500 us), the idle hold bound (8 ms) and the 56 MiB weight pre-read sized to the R9700's 64 MB cache (defined once in
qwen4expand once indeepseek4). They change timing only, never an output. - Left for a follow-up, to keep this PR from growing: one hold kernel and one clock-rate helper (there are two of each), one Q8 memo key helper, shared device helpers for the hand-copied router top-k, F32 twin and copy-batch loops, one
rope_rotateused by the fused and unfused paths, a named helper for the allocator lifetime edges inqwen4exp_graph.cpp, and the MTP staging onPinnedStage. - With several requests at once, DeepSeek V4.1's greedy text depends on how many requests are active, on main as on this branch (alone it is the same on both). Not changed here.
Test plan
- HIP build (gfx1201 + gfx1151), HIP graphs on and off
- Unit tests above on both GPUs
- Qwen3.8-Flash-Next split A/B vs main, same text
- DeepSeek V4.1 split A/B vs main, same text
- Qwen3.8-Flash-Next split with 4 slots (Manage flags), A/B vs main, same text
- Qwen3.8-Flash-Next on one gfx1151 alone:
smoke_qwen4exp_forward 300 --mtp 64 --mtp-draft 3passes 3 of 3 runs (MTP logits identical to plain decode, 16/16 rollback cases, 16/16 catchup); the same smoke in split mode passes 2 of 2. Before the last commit it failed every run on one gfx1151, at a different token each time: the one-device router was queued ahead of the experts. - The same smoke on a Gorgon Halo alone (2 of 2 runs) and its split (1 of 1), after the last commit
- Qwen3.8-27B with 8 slots, A/B vs main: no change
- CI (CUDA and ROCm jobs)
🤖 Generated with Claude Code