perf(qwen4exp): fewer target launches in split decode
Merged
DA
1mo ago+993+993+012345678901234567890123456789-61-61-01234567890123456789
Fewer kernel launches on the R9700 (the target) of the Qwen3.8-Flash-Next two-GPU split, on top of #933. Every fusion computes the same bits as the ops it replaces, so this PR's text equals main's byte for byte. No new environment variables or flags.
What changes
In the qwen4exp graph profile unless noted (ggml-cuda.cu, moe-fused-combine.cu, hc-cn.cu, hc-mix.cu, unary.cu):
- The router's weight renormalization (GET_ROWS, SUM_ROWS, CLAMP, DIV) in one launch, following
block_reduce'sWARP_SIZE-lane butterfly so the bits match. - The shared expert's sigmoid gate folded into the MoE combine.
- HC_COMBINE_NORM, the HC mix reduce and a gated unary (any model) write the q8_1 rows the next quantized matmul would make, so its quantize launch goes.
- SCALE then SILU in one launch (any model), also writing the next matmul's q8_1 rows.
- One query row reaches flash attention as the permuted view instead of a copy (
qwen4exp_graph.cpp). - ggml-cpu's argmax picks what the GPU argmax picks since #933: the host scan's choice, the lowest id of the row's maximum.
Measured
Qwen3.8-Flash-Next UD-Q4_K_XL, MTP draft, greedy, R9700 + Strix Halo. Same box and session, main (34b2087) and this PR alternating, two server starts each with two runs per prompt; decode tok/s, mean (min-max):
| code | prose | 2K-token document | |
|---|---|---|---|
one user, 131K context, --expert-placement: main | 62.9 (56.1-66.7) | 57.3 (56.2-58.0) | 51.9 (50.5-53.3) |
| this PR | 66.8 (66.1-68.1) | 58.4 (57.4-59.2) | 54.3 (52.9-54.9) |
| four users, default launch: main | 43.0 (42.6-43.3) | 47.1 (45.4-48.3) | 36.7 (36.1-37.2) |
| this PR | 44.5 (43.9-45.0) | 48.9 (48.2-49.2) | 38.3 (37.8-38.7) |
The text is identical to main's in all 24 replies (12 per launch).
Tests
test_qn_split_fusions(new, in the ROCm and NVIDIA GPU jobs): each fusion built as the qwen4exp graph builds it, computed as one graph and in segments a fusion cannot cross (node by node, or a q8_1 producer apart from its matmul): equal bits, and the fusion counters (ggml_backend_cuda_get_qn_fusion_count) show each fusion ran in the one-graph run only. The argmax, on every GPU and on the CPU backend, against a host scan of rows full of ties.- The ROCm GPU job's steps (same build flags and test list, draft top-K, capture-safe copies, DSpark load, model smoke, affine ROCmFP2 build) on main with this PR, #935 and #936 applied together, run by hand on an R9700 and a Strix Halo while the shared runner queue kept cancelling the job: all pass, 98 of 98 ctest cases on each GPU (the skips are the multi-GPU cases).
Follow-ups (separate PRs)
- Since #933, greedy text with
--draftdiffers from--verify-width 1on this split (6 of 6 replies here, on main and on this PR alike): a single-token decode and a verify column no longer take the same kernels somewhere on the target. Worth restoring, as the verify contract inqwen4exp_graph.hdescribes. - Late experts (a layer's cold experts join one layer late, so the GPUs overlap): they change the arithmetic, so as a flag with a quality gate.
- Routing stats for
--expert-placementfrom a serving run.
🤖 Generated with Claude Code