Skip to content

dsv41 metal: the DSpark drafter on an FP8 head, a concurrent propose and resident buffers - #3296

Closed
ashhart wants to merge 7 commits into
mainfrom
lead/dsv41-dspark-head
Closed

ashhart wants to merge 7 commits into
mainfrom
lead/dsv41-dspark-head

Conversation

@ashhart

@ashhart ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Two changes to DeepSeek-V4.1's DSpark drafter on Metal. Neither touches the target, so every reply is unchanged: drafted still equals "draft": false.

  • FP8 draft head.
    • With drafts on, the drafter's weights include an FP8 copy of the vocabulary head, made from the bf16 head at load: E4M3 codes with E8M0 scales in 32x32 blocks, the release's own weight format. That's 0.67 GB more memory, quantized in about 0.2 s (dspark_head.zig).
    • The drafter's head runs it on the FP8 row kernels; the target's head stays bf16.
    • The drafter keeps its top 64 candidates, and accepted drafts were unchanged in the runs below.
  • Concurrent propose. The propose launch encodes in a concurrent encoder, with a barrier wherever a step reads the one before. A new test holds a launch byte-equal to the same launch in a serial encoder; removing one barrier makes it fail (241,076 bytes differ).
  • Residency.
    • None of the drafter's buffers were in a residency set, and macOS let them go between passes. About 20 drafter command buffers a run waited 40-570 ms between commit and their first GPU instruction while it made them resident again. The target's buffers never waited in the same runs.
    • Pass.init now holds everything a pass binds in one residency set on the engine's queue: weights, the FP8 head, rings, act_quant rows, plan and working buffers, about 8 GiB. deinit releases it.
    • Holding the weights alone still left 14 waits.

Measured on an M5 Ultra (512 GB), release weights, five prose prompts of tools/bench_prompts.json at 512 tokens, one stream, with #3287's FP8 rows underneath. TF_DSV41_ROUND_PROF (#2951) was used for the timings only.

Before FP8 head + concurrent + residency set
propose GPU, ms a round 3.73 3.06 3.03
ingest wall, ms 0.5 1.86-2.61 0.50
greedy tok/s 56.4-57.5 57.1-58.5 59.7-59.9
sampled tok/s 47.4-48.1 48.6-49.8 51.6-51.7
  • Accepted drafts are unchanged (greedy about 1412/2510, sampled 1296/2675), and all 10 reply hashes are identical in every arm.

  • The drafter head alone at 1 / 5 / 10 / 15 rows: bf16 1339 / 1410 / 2985 / 3176 µs, FP8 647 / 958 / 2153 / 2993 µs. Those use dsv41 metal: FP8 decode rows load first and meet tile roots in one simdgroup, same bits #3287's kind d; on main alone the head takes the existing kind b.

  • zig build test-dsv41-metal -Dcpu=apple_m1 and test-dsv41-metal-serve pass on this branch on main, on an M5 Max. The serve suite covers drafted vs "draft": false, concurrent vs solo and seeded repeats. check_dspark.zig checks the drafter's logits against the FP8 head. Lean: 0 new.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main 2ba55ec as part of the decode stack. It now sits on @gilby's #2973 and #2983 (#3292 needs #2983's expert rows) and lands after them in order: #2973, #2983, #3287, #3288, #3292, #3296, #3376. Measured on an M5 Ultra on the release checkpoint, the whole decode stack (#2973, #2983, #3287, #3288, #3292, #3296, #3376) against main 2ba55ec: 48 of 48 replies equal (greedy, sampled and "draft": false; 16 prompts, 512 tokens). Greedy 73.1 -> 91.8 tok/s, sampled 60.1 -> 74.8, "draft": false 46.4 -> 51.3. test-dsv41-metal passes and the lean check finds nothing new.

  • Synthena (Ash's Agent)

gilby and others added 7 commits November 18, 2026 19:31
…x tile, bit-equal to the row kernel

Launches of 6 to 16 rows run the dense FP8 projections on fp8_tile.metal: 8 or 16 columns a
threadgroup, K split over up to 16 simdgroups in aligned power-of-two runs of groups, each 32-wide
group summed from zero in four 8-wide MMA steps in k order (the prompt tile's group root), the
groups' roots and the slices' roots in the same zero-padded pair tree the row kernel uses. Every
row's bits are the row kernel's one row a launch; 1-5 rows keep the row kernel (chosen by row
count only), since below 6 rows it reads the weights faster.

Contract: six registrations (f32, bf16, a forced 16-column form, one simdgroup, the row kernel one
row a launch as replaced baseline, the release wkv fixture), four planted controls, gate-5 records
with M1/M2 limits, and an equality probe over every model FP8 shape at 1-16 rows, every form, the
16/17 seam and a batch with NaN and Inf planted. Device tests: the layer's kernel by row count, and
four slots of two rows each in one launch against each alone.
…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.
@ashhart
ashhart force-pushed the lead/dsv41-dspark-head branch from 9758e3a to 7959dff Compare November 18, 2026 19:33
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

All seven commits here are already on main, as 866be20, 7c76765, 71bc694, cb21608, 82bcc6c, 7481914 and e02c9ca, so there is nothing left to land. Closing.

  • Synthena

@ashhart ashhart closed this Nov 23, 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.

2 participants