Skip to content

DeepSeek-V4.1 on Metal: draft depth priced from TF_DSV41_CALIB_FILE when set - #3365

Closed
ashhart wants to merge 6 commits into
mainfrom
lead/dsv41-metal-calib-file
Closed

ashhart wants to merge 6 commits into
mainfrom
lead/dsv41-metal-calib-file

Conversation

@ashhart

@ashhart ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

DeepSeek-V4.1 on Metal: the served model fixed its calibration knobs to the built-in cost table (.calib = .{ .mode = "default" }), so TF_DSV41_CALIB_FILE was ignored on Metal and draft depth was always priced from the built-in round model. That model is ~37 ms + 5 ms a row with a 5.6 ms drafter pass. On an M5 Ultra a one-row round measures 19.6 ms, each extra row 4.5-6 ms, and the FP8-head drafter pass 3.1 ms, so the built-in table treats extra verify rows as about half as expensive as they are.

Now, when TF_DSV41_CALIB_FILE names a file, Metal passes it to the existing cached path (calib_env.load -> readEntry: JSON with verify, each window's ms by its rows from 1, and draft). Unset, the built-in table as before. Pricing only picks how many drafts a round verifies, so tokens never change. #2952 (gilby) times a table at start; this only lets a measured file through. A docs/environment.md row is added.

On an M5 Ultra, five prose prompts at 512 tokens on the decode stack (#2973, #2983, #3287, #3288, #3292, #3296) plus the prefill PRs, with the default table vs a measured one (verify 19.6 / 25.3 / 31.0 / 35.0 / 39.5 / 46.1 ms at 1-6 rows, then +4.5 ms a row; draft 3.1), two pairs back to back:

default measured
greedy 70.1 / 70.0 tok/s 70.5 / 70.6
sampled 56.2 / 56.2 tok/s 57.6 / 57.5

All 48 reply hashes equal between the two tables on the 16-prompt bench. zig build test-dsv41-metal-serve passes; lean 0 new.

  • Synthena (Ash's Agent)

…ame launch

TF_DSV41_TREE=2..4 ended served replies after a few tokens on Metal: the
target refused every window whose parents were not one chain (TreeWindow)
and every keep that was not a prefix.

A tree window now splits into chains: one from row 0 and one from each row
that is not its parent's first child, with the path before it. Chain 0 runs
on the stream's slot; each other chain runs on a shadow slot that equals the
slot below the window (copied whole when first bound, then only the
positions committed since: window rows, pool and index-key rows, carries),
all in one launch. A row run again in front of a branch must choose as on
its own chain. A kept path in a shadow's chain trades the two slot states,
so the slot holds what the accepted chain would; the taps map points the
drafter's ingest at the kept rows. Shadows are made on the first tree window.

serve_lanes.Model gains `trees` so tests set the knobs without the
environment. New tests: the target test runs trees whose main chain, first
or second sibling, or a deeper branch wins, and checks every choice against
serial decode, every kept row's taps bit for bit against the path run as a
chain, and a cached turn after trees against a fresh one; served (g) runs
trees with one and two siblings, drafted == draft:false == serial.
…; kept branches copy into the slot

Review of #3326: the target held one tree state, so two streams' tree windows in one window call
(draft/lanes.zig sends every stream's window together and keeps each after) would overwrite each
other's chains and shadow, and the first stream's keep would fail with NotAPath.

Each slot now has its own tree window (Tree.open, made on the first tree), and all tree windows of a
call are prepared first, then their chains run together, R rows a launch. A chain's shadow is one no
pending tree holds (its slot's own first, then a free one, another slot's, or a new one), so trees of
one round never share a shadow.

A kept sibling no longer swaps slot states: its kept rows (window rows, pool and index-key rows),
carries, compressor inputs and taps rows are copied into the slot, so the slot's buffers never change
and stay the ones the target joined to the weights' residency owner. A new shadow joins that owner
when the target did (Resident.tryAddNow, refused past its load limit) and leaves it before it is freed.

Tests: the tree target test also runs two slots' trees in every window call (each choice == serial,
each kept row's taps == its chain's) and checks the shadows join and leave the residency owner (the
fixture can now open with one); served (h) runs two streams with trees on two slots, overlapping,
both buying trees, each == "draft": false == serial.
…urn and before a thinking prompt's <think>

A thinking prompt ends in <|Assistant|><think>, and the next turn renders that turn as <|Assistant|></think>..., so the
whole-prompt entry was never a prefix of a follow-up and every thinking turn read the whole conversation again. A new
conversation sharing the system prompt and tools found nothing either. Prefill now runs the prompt in up to three parts
and keeps a state at each cut (before the first <|User|> once the system part is 256 tokens or more, and before the final
<think>); the resume path is the one cached prompts already take.
Metal's served model fixed its calibration knobs to the built-in table, so a cost table measured on the serving
machine could not be used. It now passes TF_DSV41_CALIB_FILE through when set (the cached path that already reads
such a file); unset, the built-in table as before.
@ashhart
ashhart force-pushed the lead/dsv41-metal-calib-file branch from 21c0735 to 539634e Compare November 15, 2026 11:18
ashhart added a commit that referenced this pull request Nov 15, 2026
ashhart added a commit that referenced this pull request Nov 15, 2026
@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Landed on main with #3384, which was stacked on it: its commits are on main as 1e74464 and f8b0e60, and its files on main equal this PR's head. Closing as landed.

  • Synthena (Ash's Agent)

@ashhart ashhart closed this Nov 15, 2026
ashhart added a commit that referenced this pull request Nov 17, 2026
Seven duplicate entries go (a PR's own line beside its lines-file line), five outside authors are thanked, #1503 gets the line its close note promised, and eleven lines now match their PRs' code and receipts (#3129, #3194, #3258, #2696, #2921, #3365, #3345, #3384, #3679, #3682, #3699, #3393).
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