Repository navigation
perf(ds4): paged hybrid steps overlap the two GPUs through a shared MoE overlap step - #983
Merged
Merged
Conversation
…ry width On a profile that sets both fused F16 verify K/V flags (ds41-r9700-gorgon) with --paged-attention, a sequence's output depended on the sequences beside it. A gathered lane took the fused F16 K/V branch, which reads the raw K/V source from row 0. For a paged lane that source is the flat pool of every slot's ring, so at layer 0 and at compressed layers without compressed rows yet each lane attended the pool from slot 0's ring onward instead of its own staged rows. A gathered lane no longer takes that branch. A paged step with more than one row summed the six routed experts as 4 + 2 while a one-row step sums them in one combine, so a row's bits depended on how many sequences shared its step. Paged steps keep the six routes whole at every width. test_ds4_paged_exact_model (optional full-model test, exits 77 without the model or two GPUs) decodes six prompts alone and then in seven shared layouts; every sequence's greedy tokens must equal its alone run. On main 21 of 23 sequences differ; with either hunk alone it still fails; with both, 23 of 23 are identical. Paged output on that profile changes with this fix. Steps with several sequences also get faster (2 at once 76 -> 61 ms, 4 at once 123 -> 98 ms a step on the tree the fix was written on). Co-Authored-By: Claude <[email protected]>
…esign Every paged step keeps the six routed experts in one owner graph, which is what LUCE_DS4_TP_NATIVE_ROUTE_WIDTH selects, so that switch now changes nothing under paged serving and leaves the paged refused list. Paged steps also pass Disabled for dynamic route balance (it applies up to five rows only, so a sixth row would change its company's arithmetic), and LUCE_DS4_TP_HEAD4_TAIL2 no longer reaches paged steps. The earlier commit's message understates fault 1: the F16 branch was taken at layers 0 and 1 on every row and at ratio-2 layers at position 0, and slot 0 was wrong alone too (its gathered rows are padded to 16, the pool view is not). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each case asserts the slots it names, the slot 0 cases check the prompt lengths against the ring, the test skips (77) unless the visible GPUs are the profile's, and its header states the invariant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oE split step In the paged (multi-user) step the MoE layers are split between the R9700 (attention, dense work, the shared expert, hot experts) and the iGPU (cold experts) without a device join. The scheduler copies a split's foreign inputs before any of its nodes run, so the R9700 split that held the hot experts, the shared expert and the join waited for the whole cold branch: the two GPUs took turns. A split step (new common/moe_split_step.h, written for any two-GPU MoE split): the cold experts are queued right after the routes, then the hot experts and the shared expert, then the join; the scheduler ends the R9700's split at the join (late cross-input split), so its own work runs while the iGPU computes. Scheduling only: every node computes the same bytes; one user (device join) is not touched. Co-Authored-By: Claude <[email protected]>
…copy per layer, all nodes placed A token-by-token owner (ROCmFP2 experts at 2+ rows) copied each token's input, routes and weights into tensors of their own, three launches per token, owner and layer; the copies were not placed, so the scheduler gave each the backend of its graph neighbour. In a split step the main owner's first copy follows the secondary owner's last node: it ran on the iGPU and the R9700's hot experts waited for the whole cold branch (no overlap at 2+ rows). A column of a dense tensor is dense, so the views are read directly; the input is gathered on the owner once per layer (one cross-device copy instead of one per token); any copy still needed is placed on the owner. Same bytes into the same kernels. Co-Authored-By: Claude <[email protected]>
Paged steps now build their MoE layers with a schedule graph (overlapping owners), which is what the Q8 handoff waits for: it would hand the secondary owner Q8_1 rows of the input, a path paged steps were never qualified with. List it with the other unqualified expert-owner switches, so a profile default is left out and an explicit setting is refused. Co-Authored-By: Claude <[email protected]>
…d a split
Review fixes for the overlapping-owner step:
- The overlap is set for paged steps only (the measured case). One user, a
two-GPU launch without a profile and other engines keep their graphs.
- Each join is marked for the scheduler (ggml_backend_sched_add_late_cross_
input_split_node) instead of turning on the late cross-input split for the
whole step, which also split the secondary owner at each of its inputs.
- The join is a plain add of two F32 sums; the cast for an F16 sum is gone
(it never ran for V4.1 and belongs to the engine that needs it).
- The main owner reads the layer input in place (no gather copy), and its
shared expert's nodes are placed on it like its routed experts.
- common/moe_split_step.{h,cpp} becomes the header-only common/moe_overlap.h
(moe_overlap_queue_expert, moe_overlap_join, moe_overlap_mark_join);
MoeHybridGraphInputs::split_join becomes overlap_owners. The names no longer
collide with the split-owner device join, split owners or split KV.
Co-Authored-By: Claude <[email protected]>
A 2-row graph with token-by-token ROCmFP2 owners and a shared expert, built with overlap_owners and a schedule graph, on a no_alloc context: every node reachable from the output has an owner list or reads a weight; every secondary-owner node precedes every main-owner node in graph order and the join comes last; the input crosses to the secondary owner in one copy and the main owner reads it in place, with no copy per token. Co-Authored-By: Claude <[email protected]>
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]>
davide221
marked this pull request as ready for review
November 10, 2026 23:04
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 b1da66f1 · 1 candidate issue checked, kept at ≥70% confidence · add the code-review label to review again
The lane-isolation fix this branch was stacked on is on main as #981, so the branch now carries only the overlap step on top of main. 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
On a Radeon AI PRO R9700 + Ryzen AI Max+ PRO 495, DeepSeek V4.1 Flash splits each MoE layer between two GPUs. The R9700 runs attention, the dense layers, the shared expert and the hot routed experts. The Radeon 8065S iGPU runs the cold routed experts.
In the multi-user (paged) step the two GPUs took turns inside every layer. With this PR they work at the same time, and each extra row needs fewer launches. Outputs are bit-identical.
Based on main, with #966's split stack and #981's paged lane isolation in. All numbers below compare against main on the same box (measured as main with #966, with #981 merged in; the PRs that landed after it change no file the V4.1 paged step uses).
The overlap rules live in common code (
common/moe_overlap.h, header only), written for any MoE layer split between two GPUs of one runtime. This PR uses them for DeepSeek V4.1's paged steps. Moving Qwen3.8-Flash-Next onto them is a follow-up.Why the GPUs took turns
What changed
common/moe_overlap.h(new, header only, model independent). The rules for overlapping the two owners of a MoE layer:moe_overlap_queue_expert);moe_overlap_join);moe_overlap_mark_join, the scheduler's existing per-node late cross-input split).common/moe_hybrid_ffn_eval.MoeHybridGraphInputs::overlap_owners. When it is set,build_moe_owner_joinqueues three things in order: the secondary owner's sum, then the main owner's routed experts and shared expert, then the join. The shared expert's nodes are placed on the main owner.build_batched_routed_graph): a token's input, routes and weights are column views of the batch, so no copy per token. The secondary owner gathers the input in one copy per layer; the main owner reads it in place. Any copy still needed is placed on its owner.deepseek4/deepseek4_fused_verify.inc. Setsoverlap_ownersfor paged steps whose two owners are GPUs of one runtime, without a device join, a cluster layer or a streamed layer, and marks their joins for the scheduler. One user, and every other path, keeps its graph.common/paged_attention_config.h.LUCE_MOE_Q8_HANDOFFjoins the switches paged steps leave out (a profile default is dropped, an explicit setting refused). It acts only on graphs built with a schedule graph, which paged steps now are, and paged mode was never qualified with it.No new environment variables. The settings refused for paged mode stay refused.
Why it is exact
ggml_addof the same two F32 sums.Evidence (this branch against main, same box, graphs-OFF builds):
Slot logits, bit for bit. 142 of 142 logits rows are identical. The probe covers:
In each build, every (phase, prompt, position) point has one bit pattern whatever the lane count, lane order or row packing: 28 points in 142 runs.
test_ds4_paged_exact_model(every case passes):PASS: prompts arriving while others decode (prompt@slot: 4@0 0@1 5@2 2@3)PASS: 23 sequences, 64 greedy tokens each, identical alone and beside othersPASS.Server greedy texts are identical: alone, 2 at once and 4 at once, before and after (code, prose, a 2K-token document, SQL).
Results
Paged step time
Median of 5 runs, ms per step.
Scheduler splits per step (
LUCE_DS4_TP_SPLIT_COUNT): before 161 at every width; after 201 at 1 row and 281 at 2 to 8 rows. Turning on the late split for the whole step instead (the scheduler's global flag, with the existingLUCE_DS4_TP_LATE_JOIN_SPLIT=1on the same build, measured before main's split stack was merged) gives 281 and 321 splits and a step no faster (slower at 1, 2, 3 lanes and 8 rows, within 0.2 ms at 4 lanes), so only the joins are marked.Server decode, paged
Manage launch flags:
--profile ds41-r9700-gorgon --paged-attention --max-concurrency 4 --kv-pool-tokens 131072 --ds4-prefill sparse --max-ctx 131072, no drafter. Decode tok/s per request, median.The 4-at-once total includes a 2K-token prefill in each round.
Both GPUs busy
Kernel trace (rocprofv3, 3 runs), share of the step with both GPUs running kernels, and with neither. Measured on this branch and its base before main's split stack was merged in (the paged step graph of this PR is the same).
Other changes in the same trace:
What it does not change
One user with the drafter.
overlap_ownersneeds a paged step, and the one-user profile also uses the device join. The token-by-token path runs only for two or more rows without grouped products, and the one-user profile runs grouped products. So the one-user graph is the graph on main. Measured, two interleaved passes (before, after, before, after), decode tok/s:Every difference is within the spread of the before runs themselves (49.58 and 50.12 for the 2K document). Texts are identical in all four runs.
Tests
Graphs-OFF build (this engine's product build):
test_moe_hybrid_overlap_owners_order_and_placement(intest_server_unit, no GPU): a 2-row layer with token-by-token ROCmFP2 owners and a shared expert, built withoverlap_owners:test_feature_gate:LUCE_MOE_Q8_HANDOFFis refused for paged mode.Passed: 5 Failed: 0, exit 0.test_server_unit:Passed: 1277 Failed: 0 Skipped: 4, exit 0.test_deepseek4_unitandtest_ds4_moe_combine_cuda(unchanged files, run as a regression check): exit 0; every combine casePASS(top_k 4 and 6, 1 to 401 tokens).Graphs-ON build (Flash-Next's product build, same common code):
luce_servercompiles.The logits probe above needs test-only engine hooks (forced rows per slot, a logits dump), so it stays out of the tree.
Known limits and follow-ups
ggml_moe_fused_prefetch, with the Engram rows due in the same wait), but only in the device-join branch, which paged steps do not take. Paged overlap steps would take it with the same two calls in the overlap branch (queue the wait work, then the read). That is a follow-up with its own measurement: on an earlier build that had both, the read was worth 0.6 to 1.2 ms per paged step. The copy tail from the same PR is set by Flash-Next's split scheduler only.qwen4exp_graph.cpp(moe_join, the late-split setup in its split scheduler, and the routed sum it queues right after its routes). Moving it ontomoe_overlap.his a follow-up.🤖 Generated with Claude Code