Skip to content

dsv41 metal: exact cold prompts faster (Engram reads beside the first rows, bigger row cache, busy keepalive probe) - #3459

Merged
ashhart merged 9 commits into
mainfrom
lead/dsv41-prompt-short
Nov 21, 2026
Merged

ashhart merged 9 commits into
mainfrom
lead/dsv41-prompt-short

Conversation

@ashhart

@ashhart ashhart commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

DeepSeek-V4.1 on Metal: faster cold prompts on the exact path (prompt bits equal decode bits): 2K 868 → 909 tok/s, 8K 1,112 → 1,310, 32K 1,224 → 1,491.

What was slow (exact path, cold, M5 Ultra; TF_DSV41_PROMPT_PROF, extended in 1b8855f with per-Engram-layer rows, waits and late command-buffer starts):

  • Engram layer 1: at 2K the GPU idled 218 ms waiting for layer 1's rows, 45K unique rows read at the SSD's ~187K random reads/s; more threads didn't help.
  • macOS re-wiring the weights mid-request: at 8K a decoder pass started ~740 ms after its commit, and a 30K prompt's encoder sat idle 4.5 s.

Changes:

  • Engram decode (18cdb4c). Records decode on up to 8 threads (about 15 → 2.6 ms a layer at 2K), and finished reads are filed into the cache without holding the readers' lock.
  • Cold chunks in two runs (d7dbe6d). A cold chunk runs layers 1-13 in two runs. The first 30% of rows have their layer-1 rows read first and go through those layers while the rest are read. Row ids are hashed once, and layer 14's reads start after the first commit. At 2K the encoder idle drops from 218 to 29 ms.
  • Engram row cache (2889730). Default raised to 4M records a layer, about 1.2 GiB a layer, from 65,536. After 32 varied 2K prompts, 29-32% of new prompts' layer-1 rows hit.
  • Busy keepalive probe (66ae970). The keepalive also probes the residency set every 400 ms while a request runs, as the Qwen3.8-27B server already does. The 8K decoder now starts 0.2 ms after its commit.

Exactness. Chunks split in two runs match one run and decode with 0 differences: 900-row chunks split 270/9/450, 64-row chunks 19/45, and the prompt-then-decode check with every chunk in two runs. The Engram cache and keepalive change no math. No new kernels.

Measured on an M5 Ultra (cold prompts):

Prompt Before After
1K 716 tok/s 741 tok/s
2K 868 tok/s 909 tok/s
8K 1,112 tok/s 1,310 tok/s
32K 1,224 tok/s 1,491 tok/s

The 32K row came from builds with the same code as this head (the head adds only an issue-order fix). On the exact head (66ae970 vs #3360's ab9c2ee, two rounds alternating head and base, cold prompts):

Prompt Base Head Change
1K 714 tok/s 740 tok/s +3.6%
2K 866 tok/s 912 tok/s +5.3%
8K 1,103 tok/s 1,315 tok/s +19%

Decode on the exact head: 48/48 replies equal to base (16 prompts, 512 tokens; greedy, sampled and "draft": false), drafted greedy == "draft": false on 16/16, speed unchanged (greedy 73.6 vs 73.7, sampled 60.5 vs 60.6, plain 46.4 vs 46.3 tok/s).

Checks: test-dsv41-shared, env-host, test-dsv41-metal and test-dsv41-metal-serve pass (the served keepalive test runs the probe). Lean finds nothing new.

What's left: at 2K the exact path's GPU time alone is ~2.34 s, so it tops out near 945 tok/s. Dense FP8 projections are ~42% of each layer. The exact tensor-unit trick used for the experts doesn't carry over, because the dense FP8 weights span a median 10 bits within a group.

Stacked on #3360.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Final-head check done (head 66ae970, base #3360 ab9c2ee, M5 Ultra, two rounds alternating):

  • Cold prompts: 1K 714 -> 740 tok/s (+3.6%), 2K 866 -> 912 (+5.3%), 8K 1,103 -> 1,315 (+19%).
  • Decode: 48/48 replies equal to base; drafted greedy == "draft": false on 16/16; speed unchanged.

The description's table now carries these. Ready to land after #3360.

  • Synthena (Ash's Agent)

…tched to 64 rows

tf_attn_lo and tf_attn_hi widen through the bfloat type (the same values), so the
decode kernel's dots and sums spend fewer instructions a key; the prompt kernel's
own widening copy goes. With that, loading each step's keys a step ahead wins at
every row count measured, so decode launches take the prefetch pipeline up to 64
rows. A 72-row decode shape keeps the plain pipeline under the contract. Bits equal
main's.
… origin, the first commit, the decoder's time and late buffer starts
…ows, the first run's rows read first

The chunk's Engram row ids are hashed once for every layer. Before the first commit only the first run's layer-1 rows are queued; the second run's and layer 14's queue behind them once the GPU has layer 0. The first run (30% of the chunk's rows, chunks of 512 rows or more) goes through layers 1-13 as soon as its rows are in, the second as a later chunk would, from its first row's keys; layer 14 on runs all rows. Prompt tests compare chunks of 900 rows in two runs of 270, 9 and 450 rows, chunks of 64 in runs of 19 and 45, and every cold chunk in the prompt-then-decode check, against one run and against decode: 0 values differ.
At 65536 records a prompt's reads (more than a quarter of the cache) were read through, never kept. At 4M a 4096-row chunk's batches are kept, and the rows of common n-grams stay cached across requests.
The target gave the server's ticker only its idle tick. With the busy probe (as the Qwen3.8-27B server has) a tiny command buffer on the ticker's own queue uses the weights' set every interval of a request, under the owner's hold, so macOS keeps the layers a long prompt is not using wired. The served keepalive test runs the probe beside its ticks.
Main's stepped path starts the profile clock and times the decoder cone, so its first-commit and decoder rows are right.
No change in behavior. Keeps prompt.zig within the 600-line cap with main's image rows and staged chunks.
@ashhart
ashhart force-pushed the lead/dsv41-prompt-short branch from 8afbc9c to ca427d9 Compare November 21, 2026 23:35
@ashhart
ashhart merged commit a4ea27a into main Nov 21, 2026
10 of 12 checks passed
@ashhart
ashhart deleted the lead/dsv41-prompt-short branch November 21, 2026 23:35
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