Skip to content

dsv41 metal: drafted decode reads the dense FP8 weights faster at 2-16 rows, same bits - #3376

Closed
ashhart wants to merge 6 commits into
mainfrom
lead/dsv41-fp8-rows-bw
Closed

ashhart wants to merge 6 commits into
mainfrom
lead/dsv41-fp8-rows-bw

Conversation

@ashhart

@ashhart ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

DeepSeek-V4.1 on Metal: drafted decode rounds read the dense FP8 weights faster. Every output bit stays the same.

What changes

  • Tile columns. The decode FP8 tile now gives 16 columns to any projection batch of 2048 or more columns. Before, only N of 16384 or more got 16, so wo_b, wo_a's eight groups and the shared expert ran 8 columns a threadgroup at 6-16 rows. Wide projections whose K isn't whole 1024s (wq_b, the index wq_b, w2) take the tile from 5 rows; wq_a takes it from 7. Projections under 1024 columns (wkv, the compressor) stay on the row kernel, which reads them up to twice as fast.
  • Row blocks e and f. These decode one weight word at a time where it is used, and read 8 bytes of each row's X at a time. Previously the kernel held sixteen decoded weights a column in registers, and its time grew with each row at 2-6 rows. NaN codes and scales past 2^120 still take the per-code path.

Same bits. The chains (k in order from zero), the group butterfly and the tile roots' tree are unchanged. The kernel contract gates both new blocks (f32 e, bf16 f, one launch each), and the row-invariance probe checks every kind.

Measured on an M5 Ultra

  • Dense FP8 row kernel: 5 to 21% faster at 2 to 6 rows (cold weights, back to back).
  • A release layer's 6-row decode: 2.6 to 3.8% less GPU time.
  • The whole decode stack this sits on, against main on the release checkpoint (16 prompts, 512 tokens; greedy, sampled and "draft": false): 48 of 48 replies equal; greedy 73.1 -> 91.8 tok/s, sampled 60.1 -> 74.8, "draft": false 46.4 -> 51.3 (main 2ba55ec vs this head 6cb04bf).

Tests: zig build test-dsv41-metal passes (1,158 checks), the lean check finds no new problems, and the kernel contract registrations cover the new blocks.

Stacked on #3296, which sits on #3292, #3288, #3287, #2983 and #2973. It lands after them in that order.

  • Synthena (Ash's Agent)

gilby and others added 6 commits November 22, 2026 01:09
…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).
… 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.
@ashhart
ashhart force-pushed the lead/dsv41-fp8-rows-bw branch from 49be4f7 to e61f8ab Compare November 22, 2026 01:12
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Closing this one: #3406 carries the same three files byte for byte, and the speedups described here are already on main.

  • 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