Skip to content

dsv41 metal: TF_DSV41_CHUNK_SOLO solo prompt chunk widening (stacked on #2950) - #3671

Draft
gilby wants to merge 21 commits into
ashhart:mainfrom
gilby:dsv41-metal-opt/chunk-solo
Draft

gilby wants to merge 21 commits into
ashhart:mainfrom
gilby:dsv41-metal-opt/chunk-solo

Conversation

@gilby

@gilby gilby commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What this changes

Adds opt-in TF_DSV41_CHUNK_SOLO (0, 4096, 8192; default 0 = disabled) on top of #2950's chunked prompt scheduler so a single active prefill slot without waiters can widen its prompt chunk to 4096 or 8192 tokens, shrinking per-layer overhead at very long prompts (131K) while immediately returning to base chunking when another slot arrives.

  • Issue: Refs DeepSeek-V4.1 on Metal: decode and prompt speed on M3 Ultra and M5 Ultra, token-exact (gate and order for the drafts) #2984 (prompt scheduling follow-up stacked on #2950).
  • Stacked on: #2950 (49a92da019c77163c5608b3ada65b57a16493667); adds 1 commit 6243fbcfeb05a782a726056ebee8e310f1e70ae2. GitHub base is main while #2950 is open (Draft).
  • atc overlap --json: Run at 2026-11-17T08:07:39Z against #2950 (49a92da01). Targeted --pulls 2950,2951,2952,2954,3278,3374,3404,3405,3459 returns conflict: "clean" against #2950 and #2954, and file overlaps on the remaining unmerged dsv41 stack PRs (2951, 2952, 3278, 3374, 3404, 3405, 3459).

Checks on this head

  • Head commit: 6243fbcfeb05a782a726056ebee8e310f1e70ae2
  • Lean checker, python3 tools/zig/lean_check.py, on the base (49a92da01) and on this head: 345 and 345, 0 new (python3 tools/pr_check.py --base 49a92da019c77163c5608b3ada65b57a16493667: 0 error(s), 1 warning(s), max touched source file lanes.zig 578 lines). zig fmt --check build.zig zig and git diff --check 49a92da01..HEAD pass.
  • Tests run, with the command and pass, fail and skip counts:
    • Apple M5 Max: zig build test-dsv41-metal-all --summary all -> 9/9 steps succeeded; 48/48 tests passed (30 + 18, including (e) solo_chunk 128 -> busy 64 -> solo 128: 0 state bytes differ, tokens equal); zig build test-environment-host --summary all -> 3/3 steps succeeded. Planted negative controls: removing TF_DSV41_CHUNK_SOLO from environment.zig fails test-environment-host, and disabling soloSlot widening in target.zig fails test-dsv41-metal-serve. zig build test test-golden --summary all reported 833/835 steps succeeded (1 failed); 406/420 tests passed (13 skipped, 1 failed) on 'dashboard_test.test.dashboard page polls the public stats snapshot without private details', which is identical to the base #2950 commit 49a92da01 (833/835 steps succeeded (1 failed); 13011/13120 tests passed (108 skipped, 1 failed) on both trees without --summary all).
    • Apple M5 Ultra: zig build test-dsv41-metal-all --summary all -> 9/9 steps succeeded; 48/48 tests passed; zig build test-environment-host --summary all -> 3/3 steps succeeded.
    • Apple M3 Ultra: zig build test-dsv41-metal-all and zig build test-environment-host -> exited 0.
  • CI: Not run yet (opening Draft PR stacked on #2950).
  • Not run, and why: Kernel contract unchanged (no .metal files modified); M1–M4, CUDA, HIP, Windows, and mobile targets were not run.

Receipt

  • Main against branch: Two-chip A-B-B-A receipts comparing #2950 (49a92da01) vs 6243fbcfe (both default unset 0 and opt-in TF_DSV41_CHUNK_SOLO=8192) are in the public Gist.
    • M5 Ultra (Nominal on all cells): decode SLOWER: 0/20; MISMATCHES: 0 (0.999–1.002x across all 20 cells).
    • M3 Ultra (all decode cells ended Heavy FLAGGED H!,H!,H!,H! after 6.5 h continuous load): s4-solo1 matched #2950 across all 20 cells, while s4-solo2 dipped near the tail producing SLOWER: 1/20 on conc N=3 T=0.0 chat (68.9,68.8 vs 68.6,66.2, ratio 0.979); MISMATCHES: 0 (EQUAL bad=0 everywhere; decode prompts are 14–25 tokens so chunk widening is inactive in decode anyway).
    • Cold prefill TTFT (bench_cache 2k/8k/32k; single cold request 131072):
Prompt Chip #2950 mean (s) Unset (0) mean (s) / ratio SOLO=8192 mean (s) / ratio token_sha256
2048 M3 Ultra 7.6931 7.6333 (1.0078x) 7.7046 (0.9985x) EQUAL (330cd07dd3cf)
8192 M3 Ultra 15.8451 15.8595 (0.9991x) 17.2943 (0.9162x) EQUAL (b2da1b2b327d)
32768 M3 Ultra 44.0524 44.0873 (0.9992x) 44.9428 (0.9802x) EQUAL (0e3f2ebade35)
131072 M3 Ultra 168.5474 — 166.3784 (1.0130x) EQUAL (1e2921aaf094)
2048 M5 Ultra 5.3843 5.3580 (1.0049x) 5.4532 (0.9874x) EQUAL (330cd07dd3cf)
8192 M5 Ultra 11.8500 11.9935 (0.9880x) 12.3203 (0.9618x) EQUAL (b2da1b2b327d)
32768 M5 Ultra 34.3305 33.9323 (1.0117x) 33.6145 (1.0213x) EQUAL (0e3f2ebade35)
131072 M5 Ultra 127.2367 — 123.5320 (1.0300x) EQUAL (1e2921aaf094)
  • Boxes it reaches: deepseek_v41 draft/serve lane chunk scheduler and Metal target/prompt step loop (serve_lanes.zig, draft/lanes.zig, metal/target.zig, metal/prompt.zig).
  • New switch? Default, accepted values, profile row: TF_DSV41_CHUNK_SOLO; default 0 (off), accepted values 0, 4096, 8192; documented in docs/environment.md and validated via platform/environment.zig (not a .profile switch).
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: base and head SHAs recorded per arm; deepseek-ai/DeepSeek-V4.1-Flash-1017 Hugging Face revision 1bae0e1088993b9b82de08f59de5be5a34e42170 (config.json sha256 8be45ce0476004a3f529fd896115a4a2e800a129ad2d3ec05b16050f52e21879); Zig 0.17.0; Apple M3 Ultra, 512 GB (macOS 26.6.2, Xcode 27.2 / 27B52, Metal 32023.922); Apple M5 Ultra, 512 GB (macOS 27.2.1, Xcode 27.2 / 27B52, Metal 32023.922); Apple M5 Max, 48 GB (macOS 27.0.1, Xcode 27.1 / 27A9275, Metal 32023.921); drafter: checkpoint built-in DSpark + copies (--context 1048576 --parallel 4 --prompt-cache-gib 0 --vision).
  • Paths and platforms the change reaches, which I ran and which I could not: Metal prompt scheduler across M3 Ultra, M5 Ultra, and M5 Max (ran); Metal M1/M2/M4 and non-Metal backends (not run).
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: 0 failed, 0 --alone unequal, 0 --serial unequal across all cells on both M3 Ultra and M5 Ultra; token_sha256 identical across all decode and cold prefill cells (330cd07dd3cf, b2da1b2b327d, 0e3f2ebade35, 1e2921aaf094) and multi-turn steps_test (solo_chunk 128 -> busy 64 -> solo 128).
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): Posted above against #2950 (49a92da01) and in Gist.
  • Decode speed before and after, from tools/bench_openai.py: M5 Ultra 0.999–1.002x (0/20 SLOWER); M3 Ultra s4-solo1 matched base (54.6, 43.8, 50.5, 44.1), while s4-solo2 dipped under Heavy FLAGGED (0.972–0.977x).
  • Prompt speed before and after: the cold first request's ttft_s from tools/bench_cache.py --require-cold on a long prompt, or "n/a" with the reason when the change cannot reach prompt processing: Default (0) matches #2950 (0.988–1.012x); opt-in TF_DSV41_CHUNK_SOLO=8192 speeds up 131072 cold prefill on both chips (1.0130x M3 Ultra, 1.0300x M5 Ultra) while slowing 8192 (0.9162x M3, 0.9618x M5) due to single-chunk scratch sizing below #2950's multi-chunk regime.
  • Licence of any new weights or drafter, or "n/a": n/a — uses existing release weights and built-in drafter.

Checklist

  • The title and description match the head commit, including the receipt and the stack.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency.

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.

  • No precision traded for speed. If the bits change, the description says which sums change and why.

  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled

gilby added 21 commits November 11, 2026 22:56
…over Metal

target.zig is the lanes' verify target: a slot's prompt, its windows of rows for several slots in one launch,
keeps and rewinds, and kept prompt states (the prompt cache) whose resumed rows the reply reports as cached_tokens.
boot.zig loads a release checkpoint folder and entry.zig serves it as tensorfold-dsv41 (dsv41-metal-serve).
Tests serve the tiny model through LaneHost: concurrent equals solo equals serial, drafted equals draft:false,
cache hits equal fresh runs, seeds and cancels.
…for the next

A shared round with the plain switch at it asked no drafts and ran no head
pass (core Rule.plain_streams, threaded from the family's resolved setting:
0 on CUDA, so its rounds are unchanged), and the family's speculation no
longer launches a pass for a round that wide (armSpec/speculate plainRound).
…in / piece / finish)

The Metal target implements the lane core's chunked hooks over its whole-prompt path:
`begin` clears the slot or restores a kept state, each `piece` runs encoder chunks from
the slot's tail position, and `finish` runs the rows the pieces left, the decoder's cone
once over the prompt's end, and the choice and keep exactly as `prefill` does. An
`encode` that stops short of the prompt's end prepares the next call's first chunk
(keyed by the slot's tail and rows), so a lone prompt in pieces of the chunk size runs
the same chunks, inputs and host overlap as one call.

A mid-prompt state is never kept: a released, cancelled or failed prompt is abandoned
(nothing saved, the prepared chunk dropped) and the slot's next prompt starts cleared.

The lanes backend fills prompts a step at a time (Backend.prefill_step over the
pieces, draft/lane_steps.zig) only when Options.steps is set; serve_lanes turns it on
for Metal with TF_DSV41_PREFILL_PIECES=1, TENSORFOLD_PREFILL_ORDER=srpt or a LaneHost
prompt policy, share or budget. With none of them set prompts run whole at admission,
as before; the CUDA backend never sets it.

Tests: pieces of 1, 7, 64, 100 and 300 rows equal the whole prompt (every state byte,
the first choice and 8 greedy tokens) with a decode stream running between pieces; two
prompts' pieces taking turns at the same positions; refused and released mid-prompt
prefills; kept prompts resumed in pieces; served replies in steps equal serial; a short
request during a long prompt gets its first token first in steps (after it as whole
prompts); a cancel mid-prompt keeps nothing; host tests over a stepped CPU twin for the
step adapter, its failure and cancel paths and the switch.
…pt's steps

With prompts in steps the lane host ran one decode round after each 4,096-row piece,
so a reply beside a long prompt drew one token a piece. The DeepSeek served lanes now
use LaneHost's own share: `--decode-share` reaches LaneHost (its share and, while
replies decode, its row cap on a step), else TENSORFOLD_PREFILL_SHARE, else replies
get 0.25 of wall time beside a prompt in steps. A step taken while a reply decodes owes
it a third of the step's time in rounds before the next step; with no reply decoding
nothing is owed, so a lone prompt runs as before. `--decode-share` on Metal turns
steps on. With steps off the share stays the host's default (whole prompts).

The target counts the most launches between two of a prompt's pieces (Stats).
Tests: on the device, a share of 0.75 gives a decoding reply at least 3 rounds between
two pieces (37 here) where a share of 0 gives at most 1, replies equal serial; host
tests of the same over the stepped twin and of which share applies (flag, env,
default, whole prompts).
…refused by name, docs

`serve_lanes.stepsFor` takes --decode-share: above 0 it turns prompt steps on (its
share then reaches LaneHost), outside [0, 1) it is refused, and otherwise the
environment decides as before. The Metal entry reports either refusal by name at open:
the flag's range, or TF_DSV41_PREFILL_PIECES's expected forms when its text is
malformed (blank keeps the default).

Docs: TF_DSV41_PREFILL_PIECES's row in environment.md names what it does on each
backend; api.md lists DeepSeek-V4.1 on Metal among the servers that apply
--decode-share; profiles.md notes the Metal reader; the optimization ledger's
DeepSeek cell for prompt chunk interleaving is open on Metal.

Test: --decode-share 0.5 with no environment turns steps on at that share (and the
row cap); 0 and unset keep whole prompts; 1, 1.5, -0.1 and NaN are refused; a blank
switch keeps its default and malformed text fails.
…nk at its own size

When a step stopped short of the prompt's end, `encode` prepared the next full chunk.
Under a capped step (TENSORFOLD_PREFILL_POLICY=fcfs with _TOKENS, or the row cap
beside replies with --decode-share) the next call asks for fewer rows, so that stage
never matched and the call read its inputs again. The stage now takes the rows the
next call will ask for when it repeats this one's size, which is the next full chunk
for an uncapped step (the same as before) and for the rows a finish has left.

`Prompt.stage_hits` counts calls that start on a staged chunk. Tests: on the device,
pieces of 1, 7, 64, 100 and 300 rows each start every later call on a staged chunk
(1 and 7 rows found one before this change) with state equal to the whole prompt; a
served fcfs prompt in 128- and 100-row steps beside a decoding reply starts its steps
on staged chunks (8 of 8 and 10 of 10; 1 before) and replies equal serial.
…hare in steps, as unset does

applyShare skipped the steps default whenever TENSORFOLD_PREFILL_SHARE was present, blank included,
while the lane host reads a blank value as unset and so as its own default share of 1: with steps on
and the variable blank, a prompt kept all the time and replies were back to one round a step. A
blank value now counts as unset here too. The share test gains the blank case (it read 1 before).
@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The opt-in switch with 0 / 4096 / 8192, immediate return to base chunking when another slot arrives, and the state-bytes-equal test are all what we want; the negative controls are a good touch. The one failing golden test in the wide run is the dashboard stats test, and it fails identically on the base commit, so it is not yours.

Where it stands:

  1. This stacks on the chunked prompt scheduler, which is still a draft; we will review that first, and this stays a draft until it lands. We'll keep it rebased as the parent moves.
  2. The overlap run lists shared files with the rest of the unmerged stack; we will sequence the order on our side. We'll check that the solo widening touches only the scheduler's row choice, not the encoder's chunk layout.

We will run the device check on our side on M3 Ultra and M5 Ultra with DeepSeek V4.1 Metal: a long solo prompt at 4096 and 8192 against the default, token hashes and state bytes equal, and a second slot arriving mid-prompt to confirm the return to base chunking.

  • Synthena

This branch has not been deployed

No deployments
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.

2 participants