Skip to content

DeepSeek-V4.1 on Metal: the target's buffers stay resident in their own set - #3321

Merged
ashhart merged 3 commits into
mainfrom
lead/dsv41-target-resident
Nov 15, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/dsv41-target-resident

Conversation

@ashhart

@ashhart ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

DeepSeek-V4.1 on Metal: the target's own buffers were in no residency set. That covers the prompt scratch and buffers, each slot's KV regions, tails and taps, the forward buffers, the layer scratch and the RoPE tables. Only the weights (and, with #3296, the DSpark drafter) were held. macOS could unmap them between command buffers and map them again when the next one was submitted. With the GPU idle, a prompt chunk or the decoder pass then waited 50-830 ms between commit and its first GPU instruction, and a fresh server's first request waited about 1.9 s.

Target.init now puts them in one residency set on the engine's queue, requested resident at once. deinit removes it before the buffers go. No kernel or arithmetic changes, so replies are unchanged.

Measured on an M5 Ultra (512 GB), release weights, cold prompts over repo docs (a fresh nonce each), a fresh server per arm, arms alternated A B A B. Both arms carry #3318 (the Engram overlap) and a timing log of commit to GPU start:

prompt tokens without (two runs) with (two runs)
2,212 592 / 610 tok/s 632 / 630 tok/s
7,928 839 / 872 tok/s 919 / 916 tok/s
30,385 1,016 / 979 tok/s 1,064 / 1,063 tok/s
  • Commit to GPU start, for a buffer committed with the GPU idle: without the set 20-833 ms (sum over a 32K prompt 1.25-2.4 s); with it 0.7-4.5 ms. The first request after load: 1,935 / 1,734 ms without, 5.5 / 6.1 ms with.

  • The 16-prompt decode bench (greedy, seeded sampled, "draft": false): 48/48 reply hashes equal main's; decode tok/s unchanged on main's decode path.

  • One run with the decode bench first still showed 45-157 ms waits at some 32K chunks. Something else unmapped after decoding is still outside a set; not chased here.

  • zig build test-dsv41-metal passes on an M5 Max (1,135 checks). Lean: 0 new.

  • Synthena (Ash's Agent)

The prompt scratch and buffers, each slot's KV regions, tail and taps, the forward buffers, the layer scratch
and the RoPE tables were in no residency set, so macOS could unmap them between command buffers and map them
again when the next one was submitted. Target.init now holds them in one residency set on the engine's queue
(requested resident at once), and deinit removes it before the buffers go.
…ide its load limit

Review (D894): the target's own residency set bypassed the 70% wired budget the weights' Resident enforces. The
target now hands its buffers to that owner (Resident.tryAddNow), which refuses and logs a join past its limit, and
removes them from it before they are freed; boot passes the owner through serve.Parts.
@ashhart
ashhart force-pushed the lead/dsv41-target-resident branch from b4a23a7 to 3ab639d Compare November 15, 2026 11:14
@ashhart
ashhart merged commit 05c5d3c into main Nov 15, 2026
2 of 10 checks passed
@ashhart
ashhart deleted the lead/dsv41-target-resident branch November 15, 2026 11:14
ashhart added a commit that referenced this pull request Nov 15, 2026
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