Skip to content

DeepSeek-V4.1 on Metal: a cold prompt's first chunk reads its Engram rows while the GPU runs - #3318

Merged
ashhart merged 3 commits into
mainfrom
lead/dsv41-engram-overlap
Nov 15, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/dsv41-engram-overlap

Conversation

@ashhart

@ashhart ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

DeepSeek-V4.1 on Metal: a cold prompt's first chunk used to read both Engram layers' rows (layers 1 and 14) on the host before its command buffer started. On an M5 Ultra that read was about 0.25 ms a row, so 0.5 s at 2K tokens and ~1 s for a 4096-row chunk, with the GPU idle the whole time. Later chunks already fill while the chunk before them runs.

Now a chunk with nothing staged:

  • writes its ids and starts every Engram layer's reads (prefetch),
  • commits the layers before the first Engram layer,
  • reads that layer's rows while they run, then commits up to the next Engram layer, and so on.

So the chunk becomes up to three command buffers on one queue, each committed once the rows it reads are written. The buffers are hazard-tracked and on one queue, so each runs after the one before it. All of them are waited on and checked for failure. On an encode error the open buffer is dropped and the committed ones finish before the caller's buffers go. Chunks filled ahead still use one command buffer. 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, so no prompt cache), one request at a time, a fresh server per arm, the two arms run back to back:

prompt tokens main this branch
2,212 3.97 s (556 tok/s) 3.67 s (603 tok/s)
7,928 9.34 s (848 tok/s) 8.79 s (902 tok/s)
30,385 29.74 s (1,021 tok/s) 28.96 s (1,049 tok/s)
  • Encoder GPU time is the same in both arms (2,018 / 6,925 / 26,780 ms). The gain is host time that now overlaps it.
  • The 16-prompt decode bench (greedy, seeded sampled, "draft": false, 512 tokens): all 48 reply hashes equal main's. Every one of those prompts takes the late path.
  • zig build test-dsv41-metal passes on an M5 Max (1,135 checks, prompt vs decode rows, cached vs fresh, served replies). Lean: 0 new.

What's left on this path: layer 1's rows still wait for the first layer's GPU time only (about 90 ms at 2K), so roughly half the old fill is still serial.

  • Synthena (Ash's Agent)

…ayers before them run

A prompt chunk with nothing staged used to read both Engram layers' rows on the host before its command
buffer started. It now writes the ids, starts every Engram layer's reads, commits the layers before the
first Engram layer, reads that layer's rows while they run, and so on: the chunk becomes up to three command
buffers on one queue, each committed once the rows it reads are written. Chunks filled ahead keep one.
…reports a failure

Review (D894): Chunk.wait returned at the first failed buffer while later ones could still run when the caller
reused the input set or freed its buffers.
@ashhart
ashhart force-pushed the lead/dsv41-engram-overlap branch from 6f94cf3 to 2fb0d6a Compare November 15, 2026 11:13
@ashhart
ashhart merged commit 2866b13 into main Nov 15, 2026
2 of 10 checks passed
@ashhart
ashhart deleted the lead/dsv41-engram-overlap branch November 15, 2026 11:13
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