Skip to content

dsv41 metal: DSpark drafts over the whole vocabulary on the GPU, 7 after full windows, same replies - #3405

Merged
ashhart merged 27 commits into
mainfrom
lead/dsv41-gpu-round
Nov 21, 2026
Merged

ashhart merged 27 commits into
mainfrom
lead/dsv41-gpu-round

Conversation

@ashhart

@ashhart ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

DeepSeek-V4.1 on Metal: more DSpark drafts land per round, and less host time goes into each round. Every reply is unchanged.

Changes:

  • Drafts over the whole vocabulary, on the GPU (5d4219b). A DSpark pass's drafts now come from a chain on the GPU right behind the drafter's head. Each is drawn from the logits plus the Markov bias over the whole vocabulary, as the release adds it, for greedy and keyed rows. Before, the bias was applied only to 64 host candidates, and 52% of greedy draft rows had their full-vocabulary choice outside them. TF_DSV41_MARKOV_GPU=0 restores the host chain.
  • 7 drafts after a full window (486aad7, 0320cf7). A pass makes 7 drafts after a window that verified the checkpoint's whole block of 5, and 5 after any other. TF_DSV41_DSPARK_BLOCK, default 7; 0 keeps 5. The 5-draft pass is bit-identical to before. Seven drafts on every pass lost on prose.
  • Sampled windows queue their next pass behind the verify too (7682bc6). The window's keyed picks are raced over each row on the GPU, and the chain is kept when the host's commit matches. On prose, 1,258 of 1,258 keyed chains matched.
  • The drafter's candidate picks run one row per thread (0965dee). The host's finish of a pass drops from 0.20 to 0.15 ms.

Measured on an M5 Ultra on the release checkpoint (#3404's parent against this head, run base, tip, tip, base):

Before After
16 prompts, greedy 95.7 tok/s 101.7 tok/s (+6.3%)
16 prompts, sampled 80.2 tok/s 87.1 tok/s (+8.6%)
Prose, greedy 71.8 tok/s 77.7 tok/s (+8.2%)
Prose, sampled 62.8 tok/s 70.5 tok/s (+12.3%)
Prose tokens a round, greedy / sampled 2.27 / 2.03 2.56 / 2.37
A long coding prompt, greedy 4.91 tokens a round, 105.6 tok/s 5.64, 112.2 tok/s
A long coding prompt, sampled 4.62 tokens a round, 100.2 tok/s 5.23, 108.6 tok/s
  • Replies: 48/48 equal in every pair, and greedy equals "draft": false on 16/16 prompts in all four arms.
  • Host idle per round goes from about 0.56 ms (greedy) and 1.5 ms (sampled) to 0.33 ms.

Tests:

  • GPU keyed picks against the host's race.
  • The GPU chain against a host full-vocabulary reference at ranks 32 and 256.
  • The 5-draft pass bit-identical to a block-5 pass.
  • Served drafted == plain with forced misses for sampled chains, block 7, the GPU chain and the 5/7 switch; a planted bug fails the GPU-chain test.
  • test-dsv41-metal, test-dsv41-metal-serve and test-dsv41-draft pass. Lean finds nothing new.

Stacked on #3404 (drafts behind the verify), which sits on the decode stack.

  • Synthena (Ash's Agent)

ashhart and others added 23 commits November 21, 2026 17:36
…f its rows, bit-equal to one row a launch

The decode gate/up and down for an expert's slot of 2-16 rows ran Kimi's four-row passes: two rows
paid for four rows of arithmetic, five rows for two passes of four, each rereading the weights. The
new tf_dsv41_xp_upc_rows and tf_dsv41_xp_down_rows decode each 32-group of an expert's MXFP4
weights once per pass and apply it to every row in it (passes of 2, 4, 6 or 8 rows for gate/up, 2
or 4 for down, rows past the slot repeating its last row unwritten), reading the activations
straight from device memory. Each row's chain is the one-row kernel's: 32 products in k order from
zero, then its group's scale, then the same tree and epilogue, so a row's bits are the same alone
or with any other rows and routing. Slots of one row keep tf_dsv41_xp_upc_one/down_one unchanged.

Contract: registrations with every row on the same six experts (gate/up coded and down, gates 1-4
against the oracle), one planted control a kernel (rows reading their pass's first row, red at
shapes), gate-5 records for both launches, and a probe holding a launch's act, out and combine
output bit-equal to each row launched alone at 1-16 rows on the same, disjoint and random experts,
with NaN and Inf planted, plus its own control. Device test: the same equality at 2-16 rows.
…olumn a simdgroup for big K

The one-launch FP8 row kernel now issues every weight and scale load before its chains, and an output's
tile roots meet in one simdgroup's butterfly (lane k holds tile k's root, zero past the tiles), the same
zero-padded pair tree that one thread used to walk over 32 roots. A new block kind d takes one column a
simdgroup over 32-group tiles. kindOf picks d for K in whole 1024s with 2048 or more columns in the batch
at 1 and 3-5 rows, and b otherwise; c is no longer picked. The contract's row invariance covers every kind.

Bits unchanged: release layers 2 and 21 give main's output and KV hashes at 1 and 4 rows, 20 of 20
concurrent launches equal, and the float64 real-layer checks pass.

M5 Ultra, release layer 2, the 8 FP8 launches timed alone: 1 row 247 -> 215 us, 4 rows 325 -> 281 us,
5 rows 360 -> 316 us. x40 round: 1 row 25.1 -> 24.6 ms, 4 rows 41.9 -> 40.0 ms, 5 rows 47.5 -> 45.7 ms.
…pt between picks

The greedy argmax takes the first maximum in vector steps and keeps the scalar scan for a row holding a NaN, so it
picks the same id; a sampled pick reuses its float64 logits and its ids instead of allocating both every row.
…ord of codes at a time

tf_dsv41_route_gate_plan runs the router's matvec, the route and the experts' plan as one launch:
groups of 32 columns compute the gate logits (mv.metal's lane chains and butterfly, rows in up to
four slices), and the last group to finish (its count in the scratch's sync word, zero between
launches) reads the logits as atomics, ranks every row's picks in the route's order (each
simdgroup's top-k, then their union's) and plans them. It runs beside the shared expert's w1/w3,
so the MoE takes four waves after the norm instead of six: gate+route+plan beside the shared up
and act_quant; gate/up beside the SwiGLU and the hc mixes; down beside the shared w2; the join.

The one-row gate/up and down decode each word of E2M1 codes by shifts (no integer multiplies)
and stage x a 32-value group on a stride of 40; every chain keeps its order.

Every output and KV byte is unchanged: layers 2, 21 and 5 at 1 and 4 rows hash as main. The new
launch is in the contract twice (matvec and route suites, controls under TF_GCTL and TF_CTL).
…a propose launch in one concurrent encoder

With drafts on, the drafter's weights now carry an FP8 copy of the vocabulary head (E4M3 codes, E8M0
scales a 32x32 block, the release's own weight format), quantized from the bf16 head at load in 16
workers (0.2 s, 0.67 GB). The drafter's head runs it on the FP8 rows kernels; the target keeps the bf16
head, so every output token is unchanged and only proposals can move. The propose launch now runs in a
concurrent encoder, with a barrier wherever a step reads the one before (wq_a beside the key's wkv,
q_norm beside the key's ring write). A new test holds a launch in a concurrent encoder byte-equal to the
same launch in a serial one; dropping one barrier makes it fail.

M5 Ultra, release checkpoint, five prose prompts, one stream: propose GPU 3.73 -> 3.06 ms a round
(FP8 head 3.29, plus the concurrent encoder 3.06); accepted drafts and every reply's hash unchanged.
About 20 ingests a run (of 2,400) waited 40-570 ms between commit and their first GPU instruction, on
an idle queue (the target's window had already waited for its own command buffers), while their GPU
work took under 1 ms; target command buffers never waited. The drafter's buffers were in no residency
set, so macOS let them go between passes and a pass waited while they were made resident again. Pass.init
now holds every buffer a pass binds (the drafter's weights and FP8 head, rings, act_quant rows, plan and
working buffers, 8 GiB) in one residency set on the engine's queue, released at deinit.

M5 Ultra, five prose prompts, one stream: ingest wall 1.9-2.9 -> 0.50 ms mean (GPU 0.26), no waits past
20 ms; greedy 57.1-58.5 -> 59.7-59.9 tok/s, sampled 48.6-49.8 -> 51.6-51.7 tok/s; accepted drafts and
every reply's hash unchanged.
…s, wq_b and w2 from 5 rows, narrow ones never

The tile's form gave 16 columns only to N of 16384 or more, so wo_b, wo_a's eight groups and the shared w1, w3 and w2
ran 8 columns a threadgroup at 6-16 rows, 30-60% slower than with 16. The form now counts a batch's columns (2048 or
more take 16); projections of 2048 or more columns with K not in whole 1024s (wq_b, the index wq_b, w2) take the tile
from 5 rows, the others from 6; projections of 1024-2047 columns (wq_a) from 7; and those under 1024 (wkv, the
compressor) stay on the row kernel at every row count, where it reads them up to twice as fast. The decode Engram
projection takes the tile at the rows it does instead of the row kernel. Every row's bits are the row kernel's, as
the tile's contract registrations already prove.
… and read X 8 bytes at a time

At 2-6 rows the one-launch row kernel spent its registers on tf_dsv41_w16's sixteen decoded weights a column and on
two 16-byte X reads a row, and its time grew with each row. Block e (split 1, two columns a lane) and block f (split 4,
four columns a simdgroup) decode one word at a time and read 8 bytes of each row's X where they are used; a lane with a
NaN code or a scale past 2^120 takes tf_dsv41_w16's per-code path as before. The chains (k in order from zero), the
group butterfly and the tile roots' tree are the whole kernel's, so every output's bits are. Projections with K in
whole 1024s and 2048 or more columns take e at 1-5 rows and d above (on cold weights back to back, d was faster than b
at 2 rows here too); the others take f at 2-6 rows and b otherwise. The contract gates both blocks (one launch, f32
e and bf16 f) besides the row-invariance probe's every-kind check.
… one line each, as the lean rule asks

Four comments (fp8_rows.metal's lean kernel, fp8_rows.zig's Kind, fp8_tile.zig's minRows and the rows contract's
Variant) each ran over two lines. The block columns move to their fields and minRows' reasons to its branches; no code
changes.
…yer runs, each layer's rows written just before the command buffer that reads it, and the next window's first row's reads start after the picks
Follow main f9df8bf (the Metal lane target and native server) and e19cf91 (the pick.zig split). Keep the current prompt geometry admission assertion when taking the threaded sampled-row delta; leave the split pick helpers and every caller in their maintained modules.
…d its verify (picks, acceptance, ingest and pass on the GPU) and kept when the host's commit matches; an ingest made before its window's commit is put back where the commit cuts it
…yers, keyed picks on threads, the drafter's candidates
After main e19cf91 (pick.zig split) and 9951a5e (vision prompt rows as u32), remove thirteen blank lines from the target after retaining the incoming Engram, threaded picks and queued-draft additions. Keep every main assertion/caller and the original argmax test; source tokens are unchanged.
… verify too, its keyed picks raced over the row on the GPU and the chain kept only when the host's commit matches
…s past the checkpoint's block, the cost depth's default cap following it
…nd its head, the Markov bias over the whole vocabulary as the release adds it (greedy, and keyed rows the host races); TF_DSV41_MARKOV_GPU=0 keeps the host's chain over each row's 64 best
…d the checkpoint's whole block of 5 and 5 after any other (TF_DSV41_DSPARK_BLOCK, default 7), the narrow pass the same as the checkpoint's
The Linux host test links more than 256 KiB of static TLS. A 64 KiB
pthread stack makes thread creation return EINVAL before the row runs.
Use the 1 MiB reservation already used by the window-pick workers.
Candidate selection, row ordering and the serial fallback stay unchanged.
@ashhart
ashhart force-pushed the lead/dsv41-gpu-round branch from 5b5ba16 to 74e72f7 Compare November 21, 2026 17:36
@ashhart
ashhart merged commit 1093b79 into main Nov 21, 2026
2 of 12 checks passed
@ashhart
ashhart deleted the lead/dsv41-gpu-round branch November 21, 2026 17:37
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner Author

Thank you @gilby. This is merged into main with your commits under your own name, so you're credited as a TensorFold contributor.

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