Repository navigation
fix(ds4): paged V4.1 lanes attend their own rows, whole routes at every width - #981
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]>
CI failed on
|
davide221
left a comment
There was a problem hiding this comment.
Code review
No issues found. Checked for bugs and logic errors in the changed code.
Reviewed 0a4be703 · 0 candidate issues 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]>
What was wrong
On
ds41-r9700-gorgonwith--paged-attention, a sequence's output depended on things other than its own prompt. There were two faults.LUCE_DS4_HYBRID_F16_VERIFY_KV=1,LUCE_DS4_F16_KV_LANES=1). Their branch inbuild_mla_attention_lane_corereads the raw K/V source from row 0. For a gathered (paged) lane that source is the flat pool of every slot's raw ring, while the lane's mask is laid out for its gathered rows: valid history in time order, padding to a multiple of 16, then the current row.Who is affected
ds41-r9700-gorgononly. One paged request alone is affected too (slot 0, see above), not only requests that share steps.ds41-r9700-gorgonevery expert is resident, so that is every layer.ds41-halo(R9700 + Strix Halo) is not affected with its shipped placement: every layer streams 52 or more experts (the budgets only demote experts, never promote them), and a layer with streamed experts already kept the six routes whole. A custom placement that leaves a layer fully resident would be affected there too.Paged output on
ds41-r9700-gorgonchanges with this fix, including one request alone.The fix
deepseek4_graph.cpp: a gathered lane no longer takes the fused F16 K/V branch (!gathered_history). It attends its own gathered rows, under the mask laid out for them.deepseek4_fused_verify.inc:MoeHybridRouteBalance::Disabled). WithLUCE_MOE_TP_DYNAMIC_ROUTE_BALANCEset, steps of up to five rows would balance and a six-row step would not, so a row would again depend on its company;LUCE_DS4_TP_HEAD4_TAIL2=1still restores the 4 + 2 split for verify lanes, for bisection; paged steps ignore it.paged_attention_config.h:LUCE_DS4_TP_NATIVE_ROUTE_WIDTHleaves the paged refused list (see the next section).No new flags or environment variables.
Whole routes and the paged refused list
LUCE_DS4_TP_NATIVE_ROUTE_WIDTHselects exactly the six-route branch that paged steps now always take, and it was on the list of switches paged V4.1 refuses because "with them it has faulted the GPU". The docs do not say which switch of that list faulted. So the question is whether paged steps now run an expert kernel that a one-row step never runs. From the code, they do not:ffn_gate_exps, 40ffn_up_expsand 40ffn_down_expstensors areQ2_0_ROCMFP2. The hybrid storage copies them into the primary and secondary stacks with their types unchanged (new_like_with_expert_count).moe_owner_branch_tokenwiseis true. At more than one row,build_batched_routed_graphthen runs gate, up, SwiGLU, down and the route sum per row at one token: the kernels a one-row step runs.MUL_MAT_IDover the whole step with six routes. On main that kernel already ran over the whole paged step with four and two routes, and DSpark verify runs it with six.With this PR, the switch changes nothing in a paged step, so it leaves the refused list (
test_feature_gatepins that). The soak below runs the same branch under load.Evidence
Regression test
server/test/unit/test_ds4_paged_exact_model.cppbuilds on HIP astest_ds4_paged_exact_model, wired liketest_ds4_paged_prefill_model: an optional full-model test, not registered in ordinary CI. It exits 77 (skip) without the model files, or when the visible GPUs are not the profile's.The invariant it checks: with paged attention, a sequence's output depends only on its own prompt. It must not depend on the other sequences' text or number, on its slot, on the lane order, or on whether it shares a step.
How it runs.
server_main.cpp, so the test restates them.Cases:
The engine API returns tokens, not logits, so the test checks greedy tokens.
Results on main 0b378da: R9700 + Ryzen AI Max+ PRO 495, V4.1 Flash 1017 ROCmFP2. Each run takes about 3.5 minutes, model load included.
Build. These runs used
GGML_HIP_GRAPHS=OFF, which is how the product builds this engine.Dockerfile.rocmdoes not set the flag, so the CMake default (OFF,server/CMakeLists.txt) applies. With graph replay compiled in, the same ggml graph is built and its kernels are replayed rather than launched one by one; the fix changes which graph is built, not how it is launched. A graphs-ON run was not made.Server (main vs main + this PR)
Setup.
--profile ds41-r9700-gorgon --paged-attention --max-concurrency 4 --kv-pool-tokens 131072 --ds4-prefill sparse --max-ctx 131072 --kv-cache-dir off, no drafter.Soak
Main + this PR, the same flags, four clients at once for 30 minutes, each sending one salted greedy request after another (eight tasks, 128, 256 or 384 tokens). This runs the six-route branch at up to four rows per step for the whole run.
Known limit
Batch-invariant dense products hold to 8 columns. Hybrid paged steps hold at most 6 rows (one per sequence, at most 6 sequences), so they stay inside that limit.
🤖 Generated with Claude Code