Skip to content

fix(ds4): paged V4.1 lanes attend their own rows, whole routes at every width - #981

Merged
davide221 merged 4 commits into
mainfrom
fix/ds4-paged-lane-isolation
Nov 10, 2026
Merged

davide221 merged 4 commits into
mainfrom
fix/ds4-paged-lane-isolation

Conversation

@davide221

@davide221 davide221 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What was wrong

On ds41-r9700-gorgon with --paged-attention, a sequence's output depended on things other than its own prompt. There were two faults.

  1. Paged lanes read the wrong raw K/V rows.
    • The profile sets both fused F16 verify K/V flags (LUCE_DS4_HYBRID_F16_VERIFY_KV=1, LUCE_DS4_F16_KV_LANES=1). Their branch in build_mla_attention_lane_core reads 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.
    • Where the branch was taken: V4.1's compress ratios are 0, 0, then 2 (layers 2 to 19) and 1 (layers 20 to 39). So it was taken at layers 0 and 1 on every row, and at ratio-2 layers only at position 0 (no compressed history and no row emitted yet). Ratio-1 layers emit a row every token and never took it.
    • Slot 1 and up attended slot 0's rows instead of their own.
    • Slot 0 was wrong even alone. Before its ring wraps, at a position p that is not a multiple of 16, its real current row sits in the masked padding and pool row ceil16(p) (stale data from an earlier user of the slot) is attended as the current row. After the wrap it reads the right rows in ring order rather than time order, which changes the summation order.
  2. A row depended on how many rows shared its step.
    • In the hybrid expert tier, a paged step with more than one row summed the six routed experts as 4 + 2. A one-row step sums them in one combine. The two orders round differently.
    • This does not depend on the F16 flags.

Who is affected

  • Fault 1: paged serving with both F16 K/V flags set. Among the shipped profiles that is ds41-r9700-gorgon only. One paged request alone is affected too (slot 0, see above), not only requests that share steps.
  • Fault 2: every step of more than one row on a two-GPU paged setup whose GPUs share a runtime, at layers that stream no experts. On ds41-r9700-gorgon every 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.
  • Not affected: one request at a time with the drafter (the non-paged path takes neither branch), and single-GPU profiles.

Paged output on ds41-r9700-gorgon changes 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:
    • every paged step keeps the six routes in one owner graph, the combine a one-row step uses;
    • paged steps never balance routes dynamically (MoeHybridRouteBalance::Disabled). With LUCE_MOE_TP_DYNAMIC_ROUTE_BALANCE set, 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=1 still restores the 4 + 2 split for verify lanes, for bisection; paged steps ignore it.
  • paged_attention_config.h: LUCE_DS4_TP_NATIVE_ROUTE_WIDTH leaves 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_WIDTH selects 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:

  • Both expert stacks are entirely ROCmFP2. In the V4.1 Flash 1017 ROCMFP2S file, all 40 ffn_gate_exps, 40 ffn_up_exps and 40 ffn_down_exps tensors are Q2_0_ROCMFP2. The hybrid storage copies them into the primary and secondary stacks with their types unchanged (new_like_with_expert_count).
  • Each row runs as its own one-row chain. Paged serving refuses grouped MMVQ, so for a ROCmFP2 owner moe_owner_branch_tokenwise is true. At more than one row, build_batched_routed_graph then runs gate, up, SwiGLU, down and the route sum per row at one token: the kernels a one-row step runs.
  • What does see the whole step: the owner route remap (a lookup and a multiply over rows x 6 routes), the per-row copies and the concat of the row outputs, and the owner join. The 4 + 2 form ran the same operations over the whole step on main, with 4 and 2 route columns.
  • One-row steps are unchanged. The 4 + 2 split only ever applied above one row, so a lone paged sequence already ran the six-route branch on main.
  • If the expert stacks were not ROCmFP2 (other V4.1 files), the owners would run MUL_MAT_ID over 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_gate pins that). The soak below runs the same branch under load.

Evidence

Regression test

server/test/unit/test_ds4_paged_exact_model.cpp builds on HIP as test_ds4_paged_exact_model, wired like test_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.

test_ds4_paged_exact_model target.gguf placement.json router_bias.bin [hotness.csv]

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.

  • It starts the engine as the server does for this profile with paged attention and six slots (the paged cap): the profile's environment minus what paged V4.1 leaves out, the profile's device flags, and the expert-device environment. The server's helpers for that are local to server_main.cpp, so the test restates them.
  • It decodes each of six prompts (code and prose, 29 to 813 tokens) alone in an idle engine.
  • Then, in each case below, every sequence's first 64 greedy tokens must match its alone run. Each case asserts the slots it names.

Cases:

  • one lane in slot 3, while the other slots hold different text;
  • two lanes, slot 0 inside its first raw ring pass (the test checks the prompt length), in slot order;
  • two lanes, slot 0 past its first pass, in reversed order;
  • four lanes, in slot order and in reversed order;
  • six lanes, in mixed order;
  • prompts arriving while others decode.

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.

tree result
main FAIL: 21 of 23 sequences differ, in all 7 cases; first differences at tokens 2 to 29
main + F16 K/V hunk only FAIL: 12 of 23 differ, in the 6 cases where sequences share steps; the lone sequence in slot 3 passes
main + whole-routes hunk only FAIL: 18 of 23 differ, in all 7 cases, from token 2
main + both hunks PASS: 23 of 23 identical
main + this PR (final, with the slot assertions) PASS: 23 of 23 identical, every case in the slots it names
  • Each hunk alone leaves the test failing, so the test pins both.
  • On main, the alone references are themselves wrong for slot 0 (fault 1). So "differs from alone" there means both sides were computed by the faulty code.

Build. These runs used GGML_HIP_GRAPHS=OFF, which is how the product builds this engine. Dockerfile.rocm does 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.

  • Flags: the launcher's paged flags, --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.
  • Prompts: code, prose, SQL and a story (31 to 48 prompt tokens), each with a unique salt, 200 greedy tokens. Each prompt ran alone, in pairs and four at once, in 2 passes with the slot order rotated.
  • Both builds ran on the same salts, so the same prompts.
main main + this PR
alone, decode tok/s 24.1 24.2
2 at once, decode tok/s per request (sum) 13.6 (27.2) 16.4 (32.8)
4 at once, decode tok/s per request (sum) 8.0 (32.1) 10.2 (40.7)
greedy text beside 1 other equals alone 0 of 8 8 of 8
greedy text beside 3 others equals alone 0 of 8 8 of 8
  • None of the 24 texts (alone, in pairs, four at once) is identical between main and this PR. That includes each request alone: a lone request runs in slot 0, and its short prompt decodes through the slot's first ring pass, where on main every position that is not a multiple of 16 attended a stale pool row instead of its own current row (fault 1).
  • Shared steps are faster with the fix: 21% per request for pairs, 27% for four at once. Alone is unchanged.

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.

  • Duration 1,817 s. 260 requests, 62,018 generated tokens (roughly 15,500 steps of up to four decode rows), 0 errors.
  • Throughput was steady: 33.4, 34.3 and 34.2 tok/s across the four clients in the three 10-minute thirds (34.1 overall).
  • Kernel log, from the end of the test run through the soak: no amdgpu, kfd or hung-task line (the only kernel lines were 5 unrelated audit notes). The server log has no error, assert or failure line.
  • Memory: at load the R9700 had 26.94 of 31.86 GiB in use (4.92 GiB free, 1.50 GiB of it reserved headroom). The Gorgon Halo holds the 146.67 GiB secondary expert stack within its 165.81 GiB budget. Memory was not sampled during the soak; there was no allocation failure.

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

davide221 and others added 4 commits November 10, 2026 18:31
…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]>
@davide221

Copy link
Copy Markdown
Contributor Author

CI failed on 0a4be703

Build failed because the runner could not reach GitHub to download a pinned PNG library

The build stopped during CMake configuration because the self-hosted runner could not resolve raw.githubusercontent.com to download lodepng, a pinned third-party file the build fetches. This is a network or DNS problem on the runner, not a code problem. The change under test touches paged attention code and docs and has nothing to do with this download.

How to fix: Re-run the failed job; the runner had a transient DNS/network outage.

  1. Re-run the failed GPU tests (self-hosted DGX GB10, sm_121 verifier) job from the GitHub Actions page ("Re-run failed jobs").
  2. If it fails the same way again, log into the lucebox_gb10 runner host and check DNS: nslookup raw.githubusercontent.com.
  3. Check the runner's outbound network/proxy (e.g. curl -I https://raw.githubusercontent.com) and restore egress to GitHub.
  4. Once DNS resolves from the runner, re-run the job again to confirm green.

network failure fetching build dependency · high confidence · run

Details and evidence

Failed: GPU tests (self-hosted DGX GB10, sm_121 verifier) › Build focused NVIDIA verifier tests (sm_121)

Job GPU tests (self-hosted DGX GB10, sm_121 verifier), step Build focused NVIDIA verifier tests (sm_121), failed at CMake configure time. The decisive log lines:

CMake Error at cmake/ImageCodecs.cmake:74 (message):
  lodepng: could not fetch lodepng.cpp with SHA256
  d98e1f40d303c1038a096ebf93b413a565a91cf2c72b9d2fa5c625c4279c3cb6
  (6;"Couldn't resolve host name")

server/cmake/ImageCodecs.cmake:66-68 downloads lodepng.cpp from https://raw.githubusercontent.com/lvandeve/lodepng/<pinned commit>/ with file(DOWNLOAD ... STATUS status); status code 6 is libcurl's "couldn't resolve host", i.e. DNS resolution for raw.githubusercontent.com failed on the runner. The script already retries the download 3 times (server/cmake/ImageCodecs.cmake:58), so this was a sustained outage during the configure run, not a single dropped packet. The PR's own server/CMakeLists.txt change only adds an optional HIP-only test target and does not touch this path; the same configure step fetches libjpeg-turbo from github.com earlier, which also would fail without network. Nothing in the diff can cause a DNS failure.

Other things to try

  • If the failure keeps recurring, check DNS on the runner: nslookup raw.githubusercontent.com and curl -I https://raw.githubusercontent.com from the runner host, and inspect any egress proxy or firewall rules.
  • To make CI immune to this, vendor lodepng.cpp/lodepng.h (and the libjpeg-turbo archive) into the repository or pre-seed them into a runner-local cache directory that ImageCodecs.cmake checks before downloading.
  • Reproduce the configure step locally to confirm the code is fine: cd server && cmake -B build -DLUCE_ENABLE_BSA=OFF -DCMAKE_BUILD_TYPE=Release.
Prompt for a coding agent
A GitHub Actions run failed in Luce-Org/lucebox. Please fix it.

- Pull request #981 (branch `fix/ds4-paged-lane-isolation`), commit 0a4be703de15895580c44716a96b3bf23fee08f3
- Workflow: CI (https://github.com/Luce-Org/lucebox/actions/runs/42879554648)
- Failed: GPU tests (self-hosted DGX GB10, sm_121 verifier) › Build focused NVIDIA verifier tests (sm_121)

Diagnosis:
Job `GPU tests (self-hosted DGX GB10, sm_121 verifier)`, step `Build focused NVIDIA verifier tests (sm_121)`, failed at CMake configure time. The decisive log lines:

```
CMake Error at cmake/ImageCodecs.cmake:74 (message):
  lodepng: could not fetch lodepng.cpp with SHA256
  d98e1f40d303c1038a096ebf93b413a565a91cf2c72b9d2fa5c625c4279c3cb6
  (6;"Couldn't resolve host name")
```

`server/cmake/ImageCodecs.cmake:66-68` downloads `lodepng.cpp` from `https://raw.githubusercontent.com/lvandeve/lodepng/<pinned commit>/` with `file(DOWNLOAD ... STATUS status)`; status code 6 is libcurl's "couldn't resolve host", i.e. DNS resolution for raw.githubusercontent.com failed on the runner. The script already retries the download 3 times (`server/cmake/ImageCodecs.cmake:58`), so this was a sustained outage during the configure run, not a single dropped packet. The PR's own `server/CMakeLists.txt` change only adds an optional HIP-only test target and does not touch this path; the same configure step fetches libjpeg-turbo from github.com earlier, which also would fail without network. Nothing in the diff can cause a DNS failure.

Proposed fix: Re-run the failed job; the runner had a transient DNS/network outage.
1. Re-run the failed `GPU tests (self-hosted DGX GB10, sm_121 verifier)` job from the GitHub Actions page ("Re-run failed jobs").
2. If it fails the same way again, log into the `lucebox_gb10` runner host and check DNS: `nslookup raw.githubusercontent.com`.
3. Check the runner's outbound network/proxy (e.g. `curl -I https://raw.githubusercontent.com`) and restore egress to GitHub.
4. Once DNS resolves from the runner, re-run the job again to confirm green.

Check out that commit, confirm the diagnosis, make the fix (adjust it if the diagnosis is wrong), and re-run the failing step locally before pushing.

Reply with /ci-fix and what to change to get a revised diagnosis.

@davide221
davide221 marked this pull request as ready for review November 10, 2026 22:43

@davide221 davide221 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@davide221
davide221 merged commit f6f4082 into main Nov 10, 2026
26 of 27 checks passed
davide221 added a commit that referenced this pull request Nov 10, 2026
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]>
@davide221
davide221 deleted the fix/ds4-paged-lane-isolation branch November 12, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant