Repository navigation
perf(split): faster R9700 + iGPU split decode (+36.9% Qwen3.8-Flash-Next), ported to DeepSeek V4.1 and Qwen3.8-27B - #966
Merged
Merged
Conversation
Split decode of Qwen3.8-Flash-Next (R9700 runs the dense layers, attention, hot experts and the MTP drafter; the Strix Halo runs the cold experts) goes from 61.02 to 83.51 tok/s (+36.9%) on an R9700 + Ryzen AI Max+ PRO 495 box with the same greedy text, short prompts and 191 to 70K tokens of context. Split engine: - GDN step in fewer launches, router in one launch, fused HC mixes, verify rollback as one batched copy on a side stream, async draft uploads and pinned staging for verify uploads and output reads. - One expert split per MoE layer, batched peer copies (one copy kernel per hop), the hop copy captured at the graph's tail. - R9700: reads the next layer's first 56 MB of weights into its Infinity Cache while it waits for the Strix (ggml_moe_fused_prefetch). - Strix: 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); Q4_K expert loop at 2 rows per wave with the rounding written out; a wake hold so its first kernel after the hop runs at speed. - 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. ggml-cuda (every model): argmax in two launches for rows of 8192+, small contiguous concat 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, PLE conv fused at every width. Tests: test_qn_split_fusions (every fusion bitwise against the segmented graph, LM head row split on both GPUs), test_cuda_copy_batch, test_ple_conv_fusion, test_ds41_mmid_width_invariance. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…m-rope fusion for Qwen3.5 M-RoPE DeepSeek V4.1 split verify (R9700 + Ryzen AI Max+ iGPU): in every MoE layer 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 (Q down/up, KV, compressor and indexer projections, output projections; the output head after the last layer) into its 64 MB Infinity Cache (ggml_moe_fused_prefetch, a new MoeHybridGraphInputs::prefetch_next list). Nothing the graph reads changes. A decode step is 2.1% shorter on a short prompt, 3.1% at 2K and 1.7% at 26K tokens than without the read, same text (ds41-r9700-gorgon, x2). Qwen3.5 family (Qwen3.8-27B): the RMS_NORM -> MUL -> ROPE [-> PERMUTE -> CONT] fusion now runs for every HIP M-RoPE graph, including interleaved M-RoPE (attention Q and K: one launch each instead of three or four), with the separate kernels' bits. test_norm_rope_fusion covers interleaved M-RoPE at the 27B shapes, with and without the qwen4exp profile. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With several slots and the full context, the fit moves some attention layers' KV cache and weights to the expert device (move_qwen4exp_attention). The next-layer read after such a layer took those weights too, so the scheduler placed the read on the CPU, which has no MOE_FUSED kernel, and the first decode step aborted. The read now keeps only weights of the target's own buffer type. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Windows CUDA build compiles ggml-cuda.cu's host code with MSVC, which has no __atomic_store_n. The hold's flag (pinned host memory the hold kernel polls) is now raised with a release fence and a volatile store, the same ordering on every host compiler. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nvcc on Windows has no __builtin_fmaf in device code. The Q4_K register dot now calls a small helper: clang's builtin on HIP (the same instruction as before), __fmaf_rn on CUDA. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- QSA positions: finish the stable-input uploads before the scheduler copies them to the expert device. - Norm-rope fusion: no overlap of the output with x, gamma or the positions; enabled per device (RDNA3.5 and RDNA4, where the tests compare it bit for bit). - HIP graph tail: a context destroyed with its capture still open ends it first, on any thread (one list of open captures for all threads, so a context freed off its opener's thread leaves no stale entry); retired graph instances wait for their last launch; a freed backend publishes the peer copies that name it; get_stream flushes the work the backend still holds back. - Wait-read prefetch: every thread's loads stay live (the sink store almost never runs). - Stacked alpha/beta views on HIP only (CUDA routes the 48- and 96-row products to different kernels). - Scheduler: a registered late cross input never takes the waits-already shortcut. - Router test: the LUT gather's row count is computed in 64 bits (CodeQL). Co-Authored-By: Claude Opus 5.5 <[email protected]>
A user input copied to another backend waited for the split backend's last event first, because the blocking copy is not ordered with that backend's stream. A copy flagged input and output has memory of its own for the whole graph (allocated first, never freed) and is written before its first use, so when every backend was idle at the start there is nothing to wait for. Layers placed on the second GPU read the target's positions and masks this way, which drained that GPU in the middle of every decode step. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The Engram row upload runs as a node of the graph instead of a blocking read before it. - The Engram wkv projection is cut into chunks that run in the MoE layers' waits for the expert device (MoeHybridGraphInputs::wait_work). - LUT uploads go through one pinned staging buffer; per-step inputs are pinned. - A verify-cache miss rebuilds over a slot built for an earlier stretch of the context (its smallest padded compressed-row count is below what any later verify of the generation can span) and keeps that slot's scheduler, pinned staging, allocator buffers and metadata arena, instead of creating them again in a never-built slot. ggml_backend_sched_replan makes the kept scheduler plan the new graph afresh: the new key can give the old graph's node and leaf counts with another topology, which the scheduler would otherwise reuse by node index. Same text; a rebuild costs 10.2 ms instead of 16.8 ms, decode step -1.6% (code) and -4.9% (2K-token prompt) on ds41-r9700-gorgon. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The batched decode ran GET_ROWS, CONCAT, CONT, SET_ROWS, SSM_CONV, SILU and two RMS_NORM + SCALE per GDN layer and slot group, plus four gate ops. The GDN conv step kernel now takes slot ids (one state slab per slot), the HIP backend runs the chain as one launch (GGML_CUDA_QN_GDN_CONV_SLOTS), q and k share one norm, and the recurrence applies the raw gates as the one-token step does. Unit tests compare both against the unfused graph bit for bit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Tree commit: ggml_backend_cuda_tree_commit_transaction_async runs the preflight on the host's own copies of the indices (no readbacks), checks device placement once per set of addresses, and commits every cache, the feature rows and each run of same-shape layers in one launch each (129 launches per step become 4; same per-element bodies; overlapping destinations keep the per-layer order), stream-ordered with one sync at the end of the round. - Drafter uploads go through pinned staging; the drafter's tail (top-k) stays on the GPU. Qwen3.8-27B, Manage's flags (8 slots): +3.3% / +3.5% alone, +2.6% / +4.6% at 4 at once (two interleaved runs). Texts differ between runs of the same build on this path (main vs main 3 of 4); the host path stays within that. test_tree_commit_async compares the async commit with the synchronous one byte for byte. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On one device the MoE router is no longer queued ahead of the experts: with it first, MTP steps on gfx1151 alone differed from plain decode from run to run (smoke_qwen4exp_forward --mtp 64 --mtp-draft 3: logits and all 16 rollback cases). Split mode keeps the early router. The rollback's batched copies only take the device buffer type on the CUDA backend, and the prefix cache test's queued backend gets its own guid. Co-Authored-By: Claude <[email protected]>
Contributor
Author
Contributor
|
@davide221 cubic can't start this review because your workspace has reached its monthly review limit. cubic has reviewed 160,512 of the 160,000 allowed lines of code this month. Reviews resume on 24 November 2026 (in 14 days). Enable flex capacity to cover overages automatically and resume reviews now. Learn how flex capacity works. To help optimise your usage, you can tune cubic to get the most out of your usage limits:
|
A benchmark-only setter, its global and eleven block shapes only it could select. Nothing called it. Co-Authored-By: Claude <[email protected]>
… one stream entry The peer copy kernel and peer copy batching were forced on for qwen4exp graphs, so GGML_CUDA_PEER_COPY_KERNEL=0 and GGML_BATCH_PEER_COPIES=0 no longer turned them off there; and the HIP graph tail ran for any batch of kernel copies, which reached DeepSeek V4.1 profiles that set both. Unset now means on for qwen4exp graphs and off elsewhere, "0" means off everywhere, and the tail runs only on a backend that ggml_backend_cuda_set_copy_tail turned on: the qwen4exp split scheduler. DeepSeek V4.1 is back to the copies it had before this series. Work queued on a backend's stream from outside its own launches goes through one entry, ggml_cuda_enter_stream (collected peer copies, an open graph tail, an idle hold, pending side copies, the device), including two callers that skipped it: the GDN chain commit and the vision rotary. ggml_backend_cuda_get_stream is a lookup again, as before this series; ggml_backend_cuda_enter_stream is the call that settles. Also: the router's wake post is set through ggml_backend_cuda_div_wake_post and one GGML_MOE_FUSED_WAKE_SLOTS, the MTP staging falls back to a blocking upload when its pinned buffer is full, and the idle hold's bound has a name. test_cuda_copy_batch: the tail stays off without the setter and with either variable at 0, and enter_stream publishes collected peer copies where get_stream does not. Co-Authored-By: Claude <[email protected]>
4 of 5 tasks
This reverts 45e5501 (perf(qwen35): DFlash2 rounds with 3 host waits instead of ~100). That commit reworked how the Qwen3.8-27B concurrent engine commits the accepted tokens of a batched verify round: a stream-ordered tree commit validated on the host's copy of the indices, pinned uploads for the drafter and the selector's top-k on the GPU. It belongs to the 27B concurrent-verify work, not to the split decode this branch is about; it measured no clear gain on that model; and another open pull request reworks the same commit step with a different design. Dropping it here leaves that step to that pull request. server/src/qwen35, the DFlash2 drafter and selector files in server/src/common, pinned_stage.h and gdn-replay-log.cu are back to main byte for byte. test_tree_commit_async and the async cases of test_draft_topk_cuda go with the code they tested. Kept: ggml_backend_cuda_enter_stream, which that commit added. The later review fixes rebuilt it on ggml_cuda_enter_stream, the one entry for work queued on a backend's stream from outside its own launches (batched copies, the GDN chain commit, the vision rotary), and test_cuda_copy_batch checks that it publishes collected peer copies. Co-Authored-By: Claude <[email protected]>
davide221
marked this pull request as ready for review
November 10, 2026 22:43
davide221
added a commit
that referenced
this pull request
Nov 10, 2026
… base) Co-Authored-By: Claude <[email protected]>
davide221
commented
Nov 10, 2026
davide221
left a comment
Contributor
Author
There was a problem hiding this comment.
Code review
No issues found. Checked for bugs and logic errors in the changed code.
Reviewed e7816f6c · 2 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again
davide221
added a commit
that referenced
this pull request
Nov 10, 2026
Conflicts kept both sides: - moe_hybrid_ffn_eval.h: MoeHybridGraphInputs keeps overlap_owners and gains main's prefetch_next / prefetch_bytes / wait_work. - deepseek4_fused_verify.inc: a layer sets overlap_owners (paged steps) and then main's prefetch weights, prefetch budget and Engram wait work. Main consumes the prefetch and wait work in the device-join branch only, so paged overlap steps build as reviewed. Co-Authored-By: Claude <[email protected]>
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.
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:
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):ggml_moe_fused_prefetch, 56 MB)ggml_moe_fused_prefetch_rows)ggml_backend_cuda_mul_mat_rdna4_rows, so every logit keeps the R9700's bits)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 newMoeHybridGraphInputs::prefetch_nextlist. 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/qwen35is 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
qwen4expand once indeepseek4). They change timing only, never an output.rope_rotateused by the fused and unfused paths, a named helper for the allocator lifetime edges inqwen4exp_graph.cpp, and the MTP staging onPinnedStage.Test plan
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.🤖 Generated with Claude Code