Repository navigation
perf(ds4): faster layer-major prefill, same bits - #988
Conversation
Pipelined layer-major prefill runs each caller band as max(LUCE_DS4_PREFILL_PIPELINE, 2) parts. With the band capped to 640 rows by primary memory, every part fell under the 512-row gate for the persistent routing and owner arenas, so each (layer, part) allocated and freed three arenas. Each free synchronizes its device, and the cold arena's free (about 4 ms) sat between one part's cold owner and the next, which drive the cold device in turn. A pipelined part now keeps the arenas, the path parts of 512 rows and more already take. The persistent cold arena also selects eager execution for the deferred cold owner (heterogeneous_prefill_eager_enabled), as for parts of 512 rows and more: the same kernels, so the same bits. HIP builds compile graph replay out by default (GGML_HIP_GRAPHS=OFF, as measured), so there the gain comes from the dropped allocations, frees and their syncs alone. Same bits: generated text identical to main at 1K, 4K, 16K and 60K prompts. Co-Authored-By: Claude <[email protected]>
A layer-major pass keeps its rows' residual on the device only when it fits beside 1.5 GiB of free memory. Otherwise the residual moves to the host and the pipeline turns off, much slower per row. Later passes of a long prompt find less free memory than the first, so their 16K-row spans fell back to the host. The prompt loop still groups bands into passes as before. A pass now runs its leading bands that fit on the device and leaves the rest as the next pass. The replay tail counts only for the part that reaches it. At least two bands run together, and a pass whose first two bands do not fit stays whole: its residual is on the host either way, and fewer passes cost less. A split never changes which bands run layer-major or how they are cut into pipeline parts: a lone band split off a layer-major pass runs layer-major too, so the output does not depend on free memory. Cluster ranks keep whole passes, since every rank must plan the same chunks. One fit rule (deepseek4_layer_major_residual_rows) now serves both the planner and the placement, with a CPU unit test, and each pass that falls back to the host residual is logged. Same bits: first-token logits and every tensor of the post-prefill state hash identical to main at 16K and 60K prompts. Co-Authored-By: Claude <[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 ab55f7c2 · 0 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again
What
Two small changes to the DeepSeek V4 layer-major prefill when it is split across two devices: dense
work and hot experts on the primary GPU, cold experts on a second device. Neither changes what a
kernel computes: (1) changes where owner arenas live, (2) changes which bands run together in one
pass, never which bands run layer-major or how they are cut into pipeline parts. First-token logits
and the whole post-prefill state hash identical to main (below).
Who gets it: the single-user launch of DeepSeek V4.1 on an R9700 beside a 192 GB Ryzen AI Max+ PRO
495 (
--profile ds41-r9700-gorgon, which setsLUCE_DS4_LAYER_MAJOR_DEVICE_RESIDUAL=1,LUCE_DS4_PREFILL_PIPELINE=2and dense prefill; the persistent owner arenas are on by default).Several users at once (
--paged-attention ... --ds4-prefill sparse) do not run the layer-majorprefill, and the
ds41-haloandds41-gorgonprofiles leave the device residual off, so neitherchange acts there.
Persistent owner arenas for pipelined parts. The routing, hot-owner and cold-owner arenas
already persist across calls from 512 rows. Pipelined prefill runs each caller band as
max(
LUCE_DS4_PREFILL_PIPELINE, 2) parts. When the band is capped below 1024 rows (tight primarymemory), every part falls under the 512-row gate, and each (layer, part) creates and frees three
arenas. Each free synchronizes its device, and the cold arena's (about 4 ms) sits on the cold
device's serial chain: the next part's cold owner waits for the previous one. A pipelined part
(its device outputs carry a deferred cold slot) now keeps the arenas, as parts of 512 rows or
more already do.
The persistent cold arena also selects eager execution for the deferred cold owner
(
heterogeneous_prefill_eager_enabled), as for parts of 512 rows or more: the same kernels. HIPbuilds compile graph replay out by default (
GGML_HIP_GRAPHS=OFF; the measured build and theproduct's both have it off), so on this box the whole gain comes from the dropped allocations,
frees and their syncs. On builds with graph replay the 320-row cold owners now run eagerly.
Passes split so the residual stays on the device. A layer-major pass keeps its rows'
residual on the device only when it fits beside 1.5 GiB of free memory. If it does not fit, the
residual goes to the host and the pipeline turns off, much slower per row. Later passes find less
free memory than the first, so on a long prompt the middle 16K-row passes fell back to the host.
that fit and leaves the rest as the next pass; the replay tail counts only for the part that
reaches it. A split never crosses a pass boundary of main.
residual is on the host either way, and fewer passes cost less. With no row free, or the
device residual off, nothing changes.
layer-major, and their pipeline parts, never depend on free memory.
deepseek4_layer_major_residual_rows) serves the planner and the placement, andeach pass that falls back to the host residual is now logged (before, only the first placement
was).
Trimming the pool before the fit check does not help: about 660 MiB of cached blocks returned to
the driver raised its free count by about 12 MiB.
Numbers
DeepSeek V4.1 Flash, R9700 (primary) + Ryzen AI Max+ PRO 495 iGPU (cold experts), the qualified
placement, DSpark drafter on, one user, greedy. Chunk 640 (memory bound), two pipeline parts per
band. Time to first token, interleaved main / branch server pairs on the committed head, long
answers (300 tokens compared):
Main's 1K time varies between runs (2.53 to 2.89 s in four runs, the branch 2.26 to 2.38 s), so
the 1K figure is the least certain.
Decode is unchanged: the 300-token answers ran at 44 to 51 tokens/s on both, within 2% of each
other at every size.
Engine timing (
LUCE_DS4_TIMING=1), main -> branch:8.4 -> 5.3 s.
Where the time went (in-process trace, main):
experts, close to its memory bandwidth) is the critical chain. Between parts the cold device sat
idle 8.8 ms on average, about 4 ms of it the per-part arena free. Both GPUs were idle together
for 28% of the prefill.
Their residual was on the host: a 25 MiB round trip each step, and no pipeline. Both GPUs were
idle together for 46% of the prefill.
Longer prompts, time to first token, text identical:
At 181,696 tokens the branch ran 22 passes, every one with the residual on the device, and neither
build logged a prefill retry.
Tight primary memory (a second process holds R9700 memory so 1540 or 2000 MiB stay free after the
warm-up), time to first token, main / branch, text identical in every case, no out-of-memory:
Same bits
state (raw, compressed and indexer KV, compressor states, HC state; 200 MB at 60K) hash
identical to main after every prefill call at 16,833 and 60,937 prompt tokens. At 60K main runs
passes of 16000 / 16000 / 16126 / 12680 rows and the branch 16000 / 13440+2560 / 10366+5760 /
12160+520.
at 16K and 60K. The previous version of this change regrouped bands after a split. There it ran,
inside a layer-major pass, a band that main runs alone as an ordinary chunk, and its first-token
logits and 50 of 55 state tensors differed from main at 16K. Splitting only inside main's passes
fixes that case.
prefill took 87 to 96 s with every pass on the device and the same passes for each request, and
each answer equals the same prompt sent alone (4 of 4). On the previous version, which splits
prompts this short the same way, 2 x 4K, 4 x 4K and 2 x 16K at once on a fresh server: 8 of 8
equal to alone.
test_layer_major_passes_fit_the_device: the fit rule against the old inequality, andthe pass split (no bound, two-band minimum, tail, equality, a pass whose first two bands do not
fit).
With the two-GPU overlap PR
Merged cleanly onto perf/ds4-split-overlap (#983). One interleaved pair, #983 against #983 with
this branch, 300-token answers identical to main at every size:
Not covered
Placements where parts already reach 512 rows see no change from (1).
does for parts of 512 rows or more.
build, not by memory pressure alone.
🤖 Generated with Claude Code