Skip to content

feat(engine): run verify and decode projections on a small-row simdgroup kernel - #155

Merged
krcm0209 merged 22 commits into
mainfrom
feat/projection-kernel
Oct 4, 2026
Merged

krcm0209 merged 22 commits into
mainfrom
feat/projection-kernel

Conversation

@krcm0209

@krcm0209 krcm0209 commented Oct 4, 2026

Copy link
Copy Markdown
Owner

What and why

The default 27B's small-row quantized projections now run through a simdgroup MMA kernel ported
from the Splash spike (src/sous/engine/projkernel.py,
src/sous/engine/kernels/projection_mma.{h,metal}): every DFlash verify forward, and every target
call of up to 8 rows outside the verifier, decode included. mlx-vlm's exact verifier keeps each
row bitwise equal to one-row decode, but its projection cost climbs with rows; the kernel's stays
nearly flat from 1 to 8 rows, which makes verify block 5 pay. Its rows are bitwise independent of
the row count and of which linears share a dispatch, so a verify row equals the decode of the same
token, and greedy output with the DFlash2 drafter stays identical to output without it.

  • On by default through [model].projection_kernel; false runs today's paths.
  • Active only where the attention tile is active (the M5 Pro), on the default dense qwen3_5 4-bit
    model with no drafter or a DFlash one; unavailable with its reason everywhere else, where
    nothing changes.
  • An unset [model].speculative_block_size now resolves to 5 where the kernel is active and to 4
    elsewhere; an explicit value always wins, and 0 keeps its meaning.
  • The cost: decode without a drafter must take the kernel too, for greedy parity, and runs slower
    where the kernel is active (measured below).
  • The model-load line gains projection_kernel= (with projection_kernel_probe_s= when active)
    and draft_block=, and /sous/status a projection_kernel block and draft_block.
  • sous tune keys suite rows by the setting, pins each block arm's block explicitly, and marks
    the current arm by the block the engine would resolve.
  • THIRD_PARTY_NOTICES.md gains a Splash section (Apache-2.0).

Fork store. Landing this cold-starts every on-disk fork store once, including stores with the
kernel off: the fork key gains proj, and projkernel.py joins the engine epoch.

Configs with an explicit block. A config that sets speculative_block_size = 4 (the
documented example used to) keeps block 4; remove the line to let the engine choose 5.

Departures from the spec, decided during review and the gate:

  • A target that grows speculative_verify_dflash_hidden is refused with a warning rather than
    at INFO: on qwen3_5 with a DFlash drafter it can only come from an mlx-vlm change, which is the
    kind of drift the refusal rules say must warn. The pins also cover _dflash_rounds,
    Qwen3_5DecoderLayer.__call__ and the verifier's _layer, which decide that greedy verify and
    decode reach the hooks.
  • Kernel timings: one cell of 96 fell outside the ±3% band, k/v at T = 1, with the in-tree
    kernel 3.0% faster than the spike (A/A 0.1%; outputs bitwise equal; every per-forward row
    within ±2%). It was read one-sided, as engine: spike — tensor-unit verify attention over GQA-packed rows at 57K, with bf16 and int8 KV #132's gate read its tile timings: the band guards the
    port against running slower than the speed evidence it inherits. ktime.py itself prints FAIL
    for it below.

Spec: docs/superpowers/specs/2026-10-03-projection-kernel-design.md. Plan:
docs/superpowers/plans/2026-10-03-projection-kernel.md.

Issue: #148. Still open and out of scope: block 6, and the suite's per-arm project paths (#149).

Merge gate (M5 Pro, 20 GPU cores)

Load

sous.engine: model_load seconds=3.8 model=mlx-community/Qwen3.8-27B-4bit positions=engine verify_attention=active verify_attention_probe_s=0.48 draft_context=active draft_context_window=2047 attention_tile=active attention_tile_splits=20 attention_tile_probe_s=0.16 projection_kernel=active projection_kernel_probe_s=0.19 draft_block=5
sous.engine: model_load seconds=2.7 model=mlx-community/Qwen3.8-27B-4bit positions=engine verify_attention=off draft_context=off attention_tile=active attention_tile_splits=20 attention_tile_probe_s=0.2 projection_kernel=active projection_kernel_probe_s=0.18
sous.engine: model_load seconds=2.9 model=mlx-community/Qwen3.8-27B-4bit positions=engine verify_attention=active verify_attention_probe_s=0.48 draft_context=active draft_context_window=2047 attention_tile=active attention_tile_splits=20 attention_tile_probe_s=0.15 projection_kernel=off draft_block=4
sous.engine: model_load seconds=4.3 model=mlx-community/Qwen3.8-27B-4bit positions=engine verify_attention=active verify_attention_probe_s=0.49 draft_context=active draft_context_window=2047 attention_tile=active attention_tile_splits=20 attention_tile_probe_s=0.16
loadtime mode=plain enable_s=5.158 state=active reason=None probe_s=5.15 draft_block=5 load_s=9.70
loadtime mode=off enable_s=0.000 state=off reason=None probe_s=None draft_block=4 load_s=3.22
loadtime mode=cold enable_s=3.424 state=active reason=None probe_s=3.42 draft_block=5 load_s=6.29
loadtime mode=warm enable_s=0.195 state=active reason=None probe_s=0.19 draft_block=5 load_s=3.00
added by the kernel: cold 3.42 s (bound 10), warm 0.20 s (bound 1), first load after install 5.16 s (bound 10)
loadtime: PASS

Port equals spike: real 27B weights, every dispatch key, T = 1..8

applegpu_g17s mlx 0.32.2
q+k+v        layer  3 q_proj+k_proj+v_proj                     T=1..8 = = = = = = = =
q+k+v        layer 63 q_proj+k_proj+v_proj                     T=1..8 = = = = = = = =
gate+up      layer  3 gate_proj+up_proj                        T=1..8 = = = = = = = =
gate+up      layer 62 gate_proj+up_proj                        T=1..8 = = = = = = = =
qkv+z+b+a    layer  0 in_proj_qkv+in_proj_z+in_proj_b+in_proj_a T=1..8 = = = = = = = =
qkv+z+b+a    layer 62 in_proj_qkv+in_proj_z+in_proj_b+in_proj_a T=1..8 = = = = = = = =
o/out_proj   layer  3 o_proj                                   T=1..8 = = = = = = = =
o/out_proj   layer 63 o_proj                                   T=1..8 = = = = = = = =
o/out_proj   layer  0 out_proj                                 T=1..8 = = = = = = = =
o/out_proj   layer 62 out_proj                                 T=1..8 = = = = = = = =
down         layer  3 down_proj                                T=1..8 = = = = = = = =
down         layer 62 down_proj                                T=1..8 = = = = = = = =
lm_head      layer  - lm_head                                  T=1..8 = = = = = = = =
q            layer  3 q_proj                                   T=1..8 = = = = = = = =
q            layer 63 q_proj                                   T=1..8 = = = = = = = =
k/v          layer  3 k_proj                                   T=1..8 = = = = = = = =
k/v          layer  3 v_proj                                   T=1..8 = = = = = = = =
k/v          layer 63 k_proj                                   T=1..8 = = = = = = = =
k/v          layer 63 v_proj                                   T=1..8 = = = = = = = =
gate/up      layer  3 gate_proj                                T=1..8 = = = = = = = =
gate/up      layer  3 up_proj                                  T=1..8 = = = = = = = =
gate/up      layer 62 gate_proj                                T=1..8 = = = = = = = =
gate/up      layer 62 up_proj                                  T=1..8 = = = = = = = =
in_proj_qkv  layer  0 in_proj_qkv                              T=1..8 = = = = = = = =
in_proj_qkv  layer 62 in_proj_qkv                              T=1..8 = = = = = = = =
z            layer  0 in_proj_z                                T=1..8 = = = = = = = =
z            layer 62 in_proj_z                                T=1..8 = = = = = = = =
b/a          layer  0 in_proj_b                                T=1..8 = = = = = = = =
b/a          layer  0 in_proj_a                                T=1..8 = = = = = = = =
b/a          layer 62 in_proj_b                                T=1..8 = = = = = = = =
b/a          layer 62 in_proj_a                                T=1..8 = = = = = = = =
31 dispatches x T = 1..8
PORT == SPIKE
synthetic weights, each variant forced: PORT == SPIKE, bitwise

Path (process totals per branch run)

br-s1 (drafted): ok state=active {'verify_kernel': 744786, 'verify_split': 0, 'plain_kernel': 100807, 'declined': 0}
br-s2 (drafted): ok state=active {'verify_kernel': 685419, 'verify_split': 0, 'plain_kernel': 100576, 'declined': 0}
arms-1 (drafted): ok state=active {'verify_kernel': 398607, 'verify_split': 0, 'plain_kernel': 99460, 'declined': 0}
arms-2 (drafted): ok state=active {'verify_kernel': 398607, 'verify_split': 0, 'plain_kernel': 99460, 'declined': 0}
br-nd1 (nodraft): ok state=active {'verify_kernel': 0, 'verify_split': 0, 'plain_kernel': 864780, 'declined': 0}
br-nd2 (nodraft): ok state=active {'verify_kernel': 0, 'verify_split': 0, 'plain_kernel': 1129184, 'declined': 0}
t-d-g (drafted): ok state=active {'verify_kernel': 507832, 'verify_split': 0, 'plain_kernel': 105861, 'declined': 0}
t-nd-g (nodraft): ok state=active {'verify_kernel': 0, 'verify_split': 0, 'plain_kernel': 3763781, 'declined': 0}
off-g256 (off): ok state=off {'verify_kernel': 0, 'verify_split': 0, 'plain_kernel': 0, 'declined': 0}
path: PASS

Speed, primary: 4v against 5k drawn per round in one branch process, two sampled seeds

PRIMARY (pre-registered; sampled; tok/s (dt-attr, strat) vs block 4v, 95% bootstrap CI over 64 distinct turns, files paired by turn, 4000 resamples)
  5k/4v: 1.1091 [1.0814, 1.1438]
  best block (argmax of the point estimate): 5k  (28.99 tok/s adjusted)

DECISION (rule fixed before the run)
  speed bar (sampled): 5k/4v 1.1091 [1.0814, 1.1438] vs >= 1.05 with CI lower > 1.00 -> PASS
5k/4v 1.1091 [1.0814, 1.1438]: pass at >= 1.05 with the CI's lower bound > 1.00
arms: PASS

Speed, secondary: sampled ABBA on the 64 turns, each tree at its default

run temp turns out tok decode tok/s tok/round accepted/drafted prefill tok/s prefilled misses pressure peak mem GB total s draft_context min..max tile counters
main-s1 0.7 64 8997 26.15 3.067 6047/8778 = 0.689 296.6 257235 2 1 37.86 1223 121..2047 -
br-s1 0.7 64 9727 27.18 3.350 6811/11592 = 0.588 290.0 257235 2 1 37.85 1256 121..2047 decode_tile=2128 verify_calls=46368 verify_rows_tile=231840 verify_launches=46656 verify_straddles=288 verify_t5=46368 proj_verify_kernel=744786 proj_plain_kernel=100807
br-s2 0.7 64 9027 27.26 3.380 6348/10668 = 0.595 289.1 257235 2 0 37.90 1232 121..2047 decode_tile=2128 verify_calls=42672 verify_rows_tile=213360 verify_launches=42992 verify_straddles=320 verify_t5=42672 proj_verify_kernel=685419 proj_plain_kernel=100576
main-s2 0.7 64 9127 24.87 2.987 6049/9135 = 0.662 289.6 257814 2 1 37.89 1269 121..2047 -
main-nd1 0.7 16 1684 13.48 - 0/0 = - 316.6 60753 1 0 32.98 322 0..0 -
br-nd1 0.7 16 1690 10.56 - 0/0 = - 319.1 60753 1 0 33.04 355 0..0 decode_tile=27584 proj_plain_kernel=864780
br-nd2 0.7 16 2222 10.64 - 0/0 = - 325.8 60753 1 0 32.96 400 0..0 decode_tile=36096 proj_plain_kernel=1129184
main-nd2 0.7 16 1722 13.47 - 0/0 = - 323.0 60753 1 0 32.98 320 0..0 -

Per bucket (pooled decode tok/s; turns / output tokens):

run <32K 32-64K 64-128K >=128K
main-s1 - 26.36 (48 / 6520; tpr 3.06) 25.59 (16 / 2477; tpr 3.08) -
br-s1 - 27.28 (48 / 7444; tpr 3.33) 26.86 (16 / 2283; tpr 3.42) -
br-s2 - 27.70 (48 / 6453; tpr 3.40) 26.21 (16 / 2574; tpr 3.34) -
main-s2 - 25.00 (48 / 7270; tpr 2.97) 24.37 (16 / 1857; tpr 3.05) -
main-nd1 - 13.48 (16 / 1684; tpr -) - -
br-nd1 - 10.56 (16 / 1690; tpr -) - -
br-nd2 - 10.64 (16 / 2222; tpr -) - -
main-nd2 - 13.47 (16 / 1722; tpr -) - -
pairs br-s1/main-s1, br-s2/main-s2: 128 turn pairs
bucket turn pairs tile out / decode s main out / decode s tile tok/s
--- --- --- --- ---
all 128 18754 / 689.1 18124 / 711.1 27.22
>=32K 128 18754 / 689.1 18124 / 711.1 27.22
<32K 0
32-64K 96 13897 / 505.9 13790 / 538.1 27.47
64-128K 32 4857 / 183.2 4334 / 173.0 26.51
>=128K 0

tokens/round tile − main: 0.339 (95% CI 0.209..0.499)
peak memory_gb over these turns: tile 37.90, main 37.89

all: branch/main 1.068 (95% CI 1.029-1.113); bar >= 1.00
prefill 289.5 vs 293.1 tok/s (-1.2%; bound ±3%), peak memory 37.90 vs 37.89 GB (bound ±0.2)
abba: PASS
greedy, identical-output turns with >= 50 tokens: 45 of 64, 4688 tokens: t-d-g 30.66 tok/s, main-g256 27.82 tok/s, 1.102x

Drafter off, sampled ABBA on the first 16 turns

pairs br-nd1/main-nd1, br-nd2/main-nd2: 32 turn pairs

bucket turn pairs tile out / decode s main out / decode s tile tok/s main tok/s ratio 95% CI (turn bootstrap) median per-turn ratio (turns >= 50 tok both) tile tok/round main tok/round tile acc rate main acc rate tile prefill tok/s main prefill tok/s
all 32 3912 / 368.8 3406 / 252.7 10.61 13.48 0.787 0.779–0.795 0.791 (n=30) - - - - 322.4 319.8
>=32K 32 3912 / 368.8 3406 / 252.7 10.61 13.48 0.787 0.779–0.795 0.791 (n=30) - - - - 322.4 319.8
<32K 0
32-64K 32 3912 / 368.8 3406 / 252.7 10.61 13.48 0.787 0.779–0.795 0.791 (n=30) - - - - 322.4 319.8
64-128K 0
>=128K 0
all: branch/main 0.787 (95% CI 0.779-0.795); bar >= 0.75
abba: PASS

Parity: drafter on against off, greedy, 69 turns to 228,630 tokens

equivalence t-d-g vs t-nd-g: 69/69 identical; cache histories equal on 69/69
gap: 0 differing turns of 69

projection_kernel = false against main, greedy, 64 turns

equivalence off-g256 vs main-g256: 64/64 identical; cache histories equal on 64/64
off-g256: load line draft_block=4, configured block [4], 2061 rounds, most drafted in one round 3, turn lines over 3 drafted per round: none
off: PASS

Tool-loop suite: 8 tasks x 6 prompts, paired by prompt

main: 48 runs, mean grade 0.975, perfect 44/48, blocks ['4'], task seconds 1169
branch: 48 runs, mean grade 0.985, perfect 45/48, blocks ['5'], task seconds 1068
branch runs on the kernel (verify and plain calls, none declined): 48/48; main runs with kernel calls: 0
per task (perfect runs):
  cli_flag                 main 3/6  branch 6/6
  dataclass_from_schema    main 6/6  branch 6/6
  docstring_sweep          main 6/6  branch 6/6
  fix_intervals            main 6/6  branch 6/6
  implement_rpn            main 6/6  branch 6/6
  migrate_config           main 6/6  branch 5/6
  rename_symbol            main 6/6  branch 6/6
  tests_for_slugify        main 5/6  branch 4/6
branch vs main over 48 (task, prompt) pairs: main-perfect/branch-not 2, branch-perfect/main-not 3; one-sided exact McNemar p = 0.8125 -> no harm detected

Suite: failing diffs, branch imperfect runs against main on the same prompt

  • migrate_config, seed 5005: branch 0.67 (failed test_load_reads_the_json_not_the_ini) - wrote all three JSON files correctly but rewrote load as CONFIG_DIR.open(f"{name}.json"), which passes the file name as Path.open's mode argument, so every load raises; its one check command was denied by the allowlist and it finished unverified. Main on the same prompt: 1.00 (3/3), json.loads((CONFIG_DIR / f"{name}.json").read_text()), no failure.
  • tests_for_slugify, seed 5000: branch 0.80 (caught 4/5 mutants; missed "a dash the cut leaves is kept") - its trailing-dash test slugify("abc de", max_length=5) == "abc-d" cuts on a letter, so no dash is ever left to remove and the test is vacuous. Main on the same prompt: 1.00 (5/5), slugify("Hello World", max_length=6) == "hello" cuts on the dash.
  • tests_for_slugify, seed 5004: branch 0.80 (caught 4/5 mutants; missed "a dash the cut leaves is kept") - its trailing-dash test slugify("abcde fghij", max_length=5) == "abcde" cuts just before the dash, so the test is vacuous. Main on the same prompt: 0.80 (4/5), the same mutant missed for the same reason: slugify("ab " * 30, max_length=40) cuts on a letter ("...ab-a").

Kernel timings: in-tree against the spike, ms per call and per forward

key T tree ms spike ms A/A gap tree / spike band tree == spike cell
q+k+v 1 0.2358 0.2360 0.2% 0.999 ±3.0% True ok
q+k+v 2 0.2445 0.2417 0.9% 1.012 ±3.0% True ok
q+k+v 3 0.2431 0.2437 0.7% 0.998 ±3.0% True ok
q+k+v 4 0.2441 0.2428 0.2% 1.005 ±3.0% True ok
q+k+v 5 0.2456 0.2464 0.6% 0.997 ±3.0% True ok
q+k+v 6 0.2431 0.2449 0.1% 0.993 ±3.0% True ok
q+k+v 7 0.2422 0.2412 0.5% 1.004 ±3.0% True ok
q+k+v 8 0.2428 0.2442 0.1% 0.994 ±3.0% True ok
gate+up 1 0.4629 0.4635 0.1% 0.999 ±3.0% True ok
gate+up 2 0.4817 0.4816 0.1% 1.000 ±3.0% True ok
gate+up 3 0.4842 0.4846 0.9% 0.999 ±3.0% True ok
gate+up 4 0.4851 0.4849 0.1% 1.000 ±3.0% True ok
gate+up 5 0.4856 0.4874 0.2% 0.996 ±3.0% True ok
gate+up 6 0.4864 0.4858 0.1% 1.001 ±3.0% True ok
gate+up 7 0.4800 0.4793 0.1% 1.001 ±3.0% True ok
gate+up 8 0.4790 0.4784 0.3% 1.001 ±3.0% True ok
qkv+z+b+a 1 0.2565 0.2566 0.2% 0.999 ±3.0% True ok
qkv+z+b+a 2 0.2658 0.2654 0.1% 1.002 ±3.0% True ok
qkv+z+b+a 3 0.2686 0.2672 0.3% 1.005 ±3.0% True ok
qkv+z+b+a 4 0.2692 0.2686 0.1% 1.002 ±3.0% True ok
qkv+z+b+a 5 0.2698 0.2687 0.0% 1.004 ±3.0% True ok
qkv+z+b+a 6 0.2712 0.2702 0.3% 1.004 ±3.0% True ok
qkv+z+b+a 7 0.2670 0.2658 0.7% 1.004 ±3.0% True ok
qkv+z+b+a 8 0.2684 0.2681 0.2% 1.001 ±3.0% True ok
o/out_proj 1 0.0922 0.0925 0.2% 0.996 ±3.0% True ok
o/out_proj 2 0.0953 0.0964 0.6% 0.988 ±3.0% True ok
o/out_proj 3 0.0964 0.0965 0.3% 0.999 ±3.0% True ok
o/out_proj 4 0.0965 0.0965 0.1% 1.000 ±3.0% True ok
o/out_proj 5 0.0967 0.0967 0.6% 0.999 ±3.0% True ok
o/out_proj 6 0.0970 0.0967 0.2% 1.003 ±3.0% True ok
o/out_proj 7 0.0950 0.0963 0.3% 0.986 ±3.0% True ok
o/out_proj 8 0.0957 0.0955 0.1% 1.002 ±3.0% True ok
down 1 0.2454 0.2456 0.6% 0.999 ±3.0% True ok
down 2 0.2533 0.2539 0.1% 0.998 ±3.0% True ok
down 3 0.2542 0.2549 0.3% 0.997 ±3.0% True ok
down 4 0.2551 0.2548 0.3% 1.001 ±3.0% True ok
down 5 0.2550 0.2552 0.5% 0.999 ±3.0% True ok
down 6 0.2562 0.2560 0.4% 1.001 ±3.0% True ok
down 7 0.2531 0.2541 0.2% 0.996 ±3.0% True ok
down 8 0.2525 0.2530 0.3% 0.998 ±3.0% True ok
lm_head 1 2.8904 2.8867 0.2% 1.001 ±3.0% True ok
lm_head 2 2.9661 3.0261 0.0% 0.980 ±3.0% True ok
lm_head 3 2.9841 3.0124 0.0% 0.991 ±3.0% True ok
lm_head 4 2.9572 2.9605 0.2% 0.999 ±3.0% True ok
lm_head 5 2.9579 2.9594 0.1% 1.000 ±3.0% True ok
lm_head 6 2.9636 2.9611 0.3% 1.001 ±3.0% True ok
lm_head 7 2.9394 2.9299 0.1% 1.003 ±3.0% True ok
lm_head 8 2.9097 2.9086 0.1% 1.000 ±3.0% True ok
q 1 0.1955 0.1965 1.1% 0.995 ±3.0% True ok
q 2 0.2035 0.2028 0.3% 1.004 ±3.0% True ok
q 3 0.2024 0.2029 0.2% 0.998 ±3.0% True ok
q 4 0.2040 0.2028 0.0% 1.006 ±3.0% True ok
q 5 0.2054 0.2053 0.5% 1.001 ±3.0% True ok
q 6 0.2053 0.2057 0.4% 0.998 ±3.0% True ok
q 7 0.2032 0.2037 0.4% 0.998 ±3.0% True ok
q 8 0.2035 0.2040 0.2% 0.997 ±3.0% True ok
k/v 1 0.0243 0.0251 0.1% 0.970 ±3.0% True FAIL
k/v 2 0.0249 0.0257 0.3% 0.970 ±3.0% True ok
k/v 3 0.0251 0.0258 0.3% 0.973 ±3.0% True ok
k/v 4 0.0251 0.0258 0.1% 0.975 ±3.0% True ok
k/v 5 0.0252 0.0259 0.2% 0.975 ±3.0% True ok
k/v 6 0.0253 0.0259 0.2% 0.976 ±3.0% True ok
k/v 7 0.0249 0.0256 0.1% 0.976 ±3.0% True ok
k/v 8 0.0251 0.0257 0.3% 0.975 ±3.0% True ok
gate/up 1 0.2606 0.2608 0.0% 0.999 ±3.0% True ok
gate/up 2 0.2694 0.2702 0.0% 0.997 ±3.0% True ok
gate/up 3 0.2710 0.2718 0.1% 0.997 ±3.0% True ok
gate/up 4 0.2716 0.2714 0.1% 1.001 ±3.0% True ok
gate/up 5 0.2722 0.2725 0.0% 0.999 ±3.0% True ok
gate/up 6 0.2734 0.2735 0.3% 1.000 ±3.0% True ok
gate/up 7 0.2690 0.2690 0.0% 1.000 ±3.0% True ok
gate/up 8 0.2714 0.2727 0.2% 0.995 ±3.0% True ok
in_proj_qkv 1 0.1694 0.1697 0.5% 0.998 ±3.0% True ok
in_proj_qkv 2 0.1720 0.1737 1.0% 0.990 ±3.0% True ok
in_proj_qkv 3 0.1715 0.1716 0.2% 1.000 ±3.0% True ok
in_proj_qkv 4 0.1737 0.1753 0.2% 0.991 ±3.0% True ok
in_proj_qkv 5 0.1768 0.1765 0.4% 1.002 ±3.0% True ok
in_proj_qkv 6 0.1750 0.1761 0.1% 0.994 ±3.0% True ok
in_proj_qkv 7 0.1751 0.1754 0.2% 0.998 ±3.0% True ok
in_proj_qkv 8 0.1754 0.1753 0.4% 1.001 ±3.0% True ok
z 1 0.1071 0.1074 0.1% 0.998 ±3.0% True ok
z 2 0.1078 0.1086 0.1% 0.992 ±3.0% True ok
z 3 0.1106 0.1105 0.0% 1.001 ±3.0% True ok
z 4 0.1102 0.1106 0.1% 0.996 ±3.0% True ok
z 5 0.1106 0.1112 0.2% 0.995 ±3.0% True ok
z 6 0.1104 0.1106 0.2% 0.998 ±3.0% True ok
z 7 0.1096 0.1098 0.0% 0.998 ±3.0% True ok
z 8 0.1088 0.1093 0.0% 0.995 ±3.0% True ok
b/a 1 0.0205 0.0210 0.5% 0.975 ±3.0% True ok
b/a 2 0.0216 0.0219 0.1% 0.988 ±3.0% True ok
b/a 3 0.0219 0.0223 0.1% 0.979 ±3.0% True ok
b/a 4 0.0225 0.0228 0.2% 0.987 ±3.0% True ok
b/a 5 0.0226 0.0231 0.4% 0.982 ±3.0% True ok
b/a 6 0.0228 0.0232 0.4% 0.982 ±3.0% True ok
b/a 7 0.0225 0.0228 0.2% 0.986 ±3.0% True ok
b/a 8 0.0231 0.0236 0.0% 0.976 ±3.0% True ok
T tree ms / forward spike ms / forward #133 tree / #133 tree / spike forward
--- --- --- --- --- --- ---
1 75.18 75.47 75.00 1.002 0.996 ok
2 77.95 77.95 77.16 1.010 1.000 ok
3 79.62 78.30 78.55 1.014 1.017 ok
4 78.74 78.19 78.12 1.008 1.007 ok
5 78.63 78.71 78.22 1.005 0.999 ok
6 78.46 78.47 77.24 1.016 1.000 ok
7 77.74 77.61 78.20 0.994 1.002 ok
8 78.44 78.49 78.92 0.994 0.999 ok
ktime FAIL {'cells': 1}

M2 Air (9B + DFlash, the #143 task set)

HTTP errors: 0
greedy replies identical on 12/12 turns
branch load line: sous.engine: model_load seconds=11.5 model=mlx-community/Qwen3.5-9B-MLX-4bit positions=engine verify_attention=active verify_attention_probe_s=0.26 draft_context=active draft_context_window=4095 attention_tile=unavailable projection_kernel=unavailable draft_block=4
branch projection_kernel: {'state': 'unavailable', 'reason': 'macOS 15.5 < 26.2'}; attention_tile: {'state': 'unavailable', 'reason': 'macOS 15.5 < 26.2'}
branch turns over 3 drafted per round: none
m2: PASS

scripts/api_smoke.py: M5 PASS: a tool_use block came back, M2 PASS: a tool_use block came back.

🤖 Generated with Claude Code

krcm0209 and others added 22 commits October 3, 2026 20:06
)

#148's spike found that routing the 27B's small-row projections through
the Splash-port simdgroup MMA kernel makes verify block 5 pay: +10.3%
sampled decode on #131's real subagent turns, greedy parity 64/64 under
design (b), and no quality harm on a path-neutral paired suite. This
spec brings it in-tree: a tag-gated hook pair (the verifier's
_linear/_linears and nn.QuantizedLinear.__call__), gated on the
attention tile, with an engine-resolved block default of 5 where the
kernel is active and 4 elsewhere.

Co-Authored-By: Claude <noreply@anthropic.com>
Eleven tasks implementing the approved design:
- int8's wrappers keep their wrapped methods visible;
- the kernel port and its entries;
- the two tag-gated hooks;
- the gates and probe;
- the mlx-vlm contract tests;
- config, engine wiring and the block default;
- load line, status and fork key;
- sous tune;
- notices and docs;
- the real-model test;
- the M5 Pro merge gate.

Tasks 1-9 were dry-run as written in a scratch worktree (full CI set
2022 passed, 39 skipped), and the fixes it found are folded in.

Co-Authored-By: Claude <noreply@anthropic.com>
int8 prefill replaces nn.QuantizedLinear.__call__ and the qwen3_5 MLP and
GatedDeltaNet __call__ with plain closures. A source pin hashes
inspect.getsource of a method, which follows __wrapped__ and nothing else,
so with int8 active the pin hashed int8's wrapper and read as mlx or
mlx-vlm having changed the method. functools.wraps sets __wrapped__ and
copies the wrapped function's __dict__, so a mark on a hook int8 wraps
later stays readable too. The MIN_ROWS comment also undercounted verify
rows: a drafted block reaches 16 under the drafter's own policy.

Co-Authored-By: Claude <noreply@anthropic.com>
mlx-vlm's exact verifier keeps each verify row equal to one-row decode,
but its projections cost more with every row: 76 ms per 27B forward at 4
rows, 99 at 5, 179 at 8. A simdgroup MMA over exact half weights and fp32
activations, with a fixed-order K split and per-group epilogue, stays at
75-79 ms from 1 to 8 rows, and a row's bits depend on neither the row count
nor the linears sharing the dispatch, so verify rows and decode can share
it exactly. Three variants (plain, staged, staged with presummed
activations) agree bitwise and are chosen by shape for speed only.
kernel_available() compiles and checks every variant, so the arithmetic
tests skip on a GPU whose MMA lane map differs instead of failing.

Co-Authored-By: Claude <noreply@anthropic.com>
…ag-gated hooks

Two call sites reach the projection kernel. The exact verifier's _linear
and _linears are wrapped on the class, because its projections reach
mlx-vlm's ops through names imported into its own module, and
nn.QuantizedLinear.__call__ is wrapped for decode, short prefill tails and
the one-row forward that ends each prefill segment. Both serve only
modules tagged on the loaded target, and only while the flag is set, so
installing them changes nothing until the kernel is enabled. The other
families whose verifiers inherit the wrap stay stock for the same reason.

A verify of more than eight rows is cut into runs, which is exact because
the kernel's rows do not depend on the rows beside them. functools.wraps
and a mark mean that a second install, or int8's wrapper on top, neither
wraps twice nor hides the originals' source from the pins. The counters
show which path each call took.

Co-Authored-By: Claude <noreply@anthropic.com>
The kernel serves every target projection of up to eight rows on the
loaded model, so a load must prove it may before the flag is raised. It
rides on the attention tile, takes only the qwen3_5 target with every
projection affine 4-bit gs64 and bf16 activations, and refuses a target
whose greedy verify would take its tokens outside the hooks. Thirteen
source pins cover every mlx and mlx-vlm function that decides a
projection reaches a hook, and follow __wrapped__ so a second load, or
int8's wrappers, never read as drift.

The warm-up compiles every dispatch key at T = 1..8 before any tag, so a
toolchain that rejects the kernel refuses the load rather than a turn.
The probe then runs the verifier's feed-forward through hook 1 against
the plain MLP through hook 2 and requires identical rows, and checks
T-invariance, grouping, closeness to stock and NaN isolation on the real
weights of one layer of each kind and the head. A refusal that only says
the kernel does not apply is an INFO line; drift, a build failure or a
failed probe warns. static_reason lets sous tune resolve the block an
unset size runs at without loading a model.

Co-Authored-By: Claude <noreply@anthropic.com>
…al paths

The unit tests prove the kernel entries, the hooks and the gates in
isolation. These pin the property the kernel exists for through mlx-vlm's
own code, on a tiny qwen3_5 model quantized as the 27B is. Every verify
row through the exact verifier's _linear and _linears equals one-row
decode through nn.QuantizedLinear.__call__, a verify above eight rows is
split and still equals decode, and the real generate_step reaches the
kernel on a short prefill tail, on the step that ends every prefill and on
decode. This holds with the stand-in on any GPU and with the real kernel
wherever it compiles, and enable() itself installs hooks that do all of
it.

Co-Authored-By: Claude <noreply@anthropic.com>
…lock at load

With the kernel, a 5-row verify round's projections cost about what a
4-row round's do, so block 5 pays only where the kernel is active: 1.10x
sampled decode over block 4 without it, on real subagent turns. An unset
[model].speculative_block_size therefore resolves at load, to 5 where the
kernel is active and to 4 elsewhere. An explicit value always wins, a
clamped one included, and the drafter's block is pinned only after the
resolution.

[model].projection_kernel switches the kernel off. A non-bool value means
false, as the other numeric switches do. The engine constructors keep the
stock projections and the block they are given, so tests and scripts that
build an engine directly are unaffected. An unload clears the kernel's flag
beside the tile's, before anything there can raise.

Co-Authored-By: Claude <noreply@anthropic.com>
…e load line

An unset block now resolves at load from the kernel's state, so the
config alone no longer says which block runs. The model-load line names
projection_kernel=, with its probe time when active, and draft_block=
whenever a drafter loaded, 0 included. The status document's engine block
carries projection_kernel {state, reason} and draft_block, which is null
while the VLM backend runs without a drafter. Fakes and backends without
the attributes stay silent, as they do for the tile.

Co-Authored-By: Claude <noreply@anthropic.com>
The kernel serves the one-row forward that ends every prefill segment and
any prefill tail of up to 8 rows, so a fork written with it holds
different bits than one written without it. The key records proj as
active or off, unavailable sharing off's key since it runs off's numerics,
and projkernel.py joins the engine epoch; the kernel's .metal and .h files
were already hashed by the kernels directory scan.

The kernel routes a prefill the same with a drafter loaded or without one,
so the drafter stays out of the key.

Landing this cold-starts every fork store once, because both the key and
the engine epoch change.

Co-Authored-By: Claude <noreply@anthropic.com>
…he projection kernel

An unset speculative_block_size now resolves at load to 5 where the
projection kernel is active. dataclasses.replace copied the user's unset
flag onto every arm, so each drafter arm on such a Mac would have measured
block 5 whatever its label said; _arm now pins the block it names. The
current-arm mark and every proposal compare against the block the daemon
would run, resolved once without a load by the kernel's static check over
the checkpoints the tune already described, with the drafter's kind read
through mlx-vlm's own resolver. A winner with another model or drafter
writes its block, since an unset one could resolve differently for it.

The kernel changes output, so suite rows are keyed by it as by the
attention tile; rows from before it existed ran stock projections and read
as false. An engine that cannot run it prints a notice and runs stock, as
the daemon would.

Co-Authored-By: Claude <noreply@anthropic.com>
…and the resolved block

The kernel keeps greedy parity only through its arithmetic contract, two
tag-scoped hooks, a plain-int flag and a load-time probe, and every one of
them is a trap for whoever next edits the kernel or bumps mlx or mlx-vlm,
so CLAUDE.md records them beside the tile's, with the argmax residual the
probe cannot cover and the rule that a kernel edit re-runs the exactness
tests and the timing check. A line-by-line comparison with Splash and its
Apple7/8 port settled what the kernel derives from them, and the notice
names exactly that. The user docs say what [model].projection_kernel does
and costs without a drafter, that an unset block is 5 where it is active,
what the load line and the status document report, and how sous tune finds
the configured arm.

Co-Authored-By: Claude <noreply@anthropic.com>
…odel

The unit and contract tests prove the kernel and its hooks on synthetic
weights; this holds the real 27B to the property the kernel's design
exists for. With the kernel active, greedy output with the DFlash2 drafter
equals output without it at block 5, at 8 and 12 set on the engine (12
verifies more than 8 rows, which the verify hook splits into runs) and at
block 0, the drafter's own policy. It also pins the engine-resolved block,
5 with the kernel and 4 without, and that an engine with the kernel off,
built after kernel engines ran in the process, reproduces one built before
them.

Co-Authored-By: Claude <noreply@anthropic.com>
The arithmetic tests skip whenever kernel_available() is False, and its
probe answers False for wrong numbers as well as for a missing GPU, so a
kernel regression turned the suite into skips while CI stayed green. One
unconditional test now asserts availability wherever Metal is, with
SOUS_TEST_SKIP_KERNEL_CHECK=1 as the opt-out for an unprobed GPU; the
tautological test_the_real_probe_passes goes.

Random inputs leave a reordered fp32 sum one bf16 rounding away from the
same bits, so the bitwise variant and row-count tests could not see the
K partials or the group sums added in another order, which breaks greedy
parity when decode and verify serve one projection on different variants.
Two cancelling layouts (the first K quarter against the last, and inside
every quant group) now run beside the random inputs; each catches its
reordering mutation, which the random inputs pass.

Co-Authored-By: Claude <noreply@anthropic.com>
…y-verify drift

Three mlx-vlm functions decide routing without being pinned: the DFlash
round loop picks which verify call a round makes and takes its tokens
from that call's logits, the decoder layer reaches the attention, linear
attention and MLP as module calls, and the verifier's _layer dispatches
to the hooked methods. A newer mlx-vlm reworking any of them could leave
verify or decode stock while the kernel reads active, so drafter-on
greedy output would silently stop equalling drafter-off. Each body was
re-read on mlx-vlm 0.7.2 against both hooks before its digest went in.

A qwen3_5 target gains speculative_verify_dflash_hidden only through
mlx-vlm drift, yet it was refused at INFO with the drafter's kind, the
class reserved for "the kernel does not apply here". It is now its own
gate after the drafter's kind and before the pins, and it warns.

Co-Authored-By: Claude <noreply@anthropic.com>
…hat paid

The clamp warning and the SPECULATIVE_BLOCK_MAX comment still called 5 the
largest verify block that had paid, though block 6 has measured faster
than 5 with the projection kernel in an out-of-tree spike: 5 is the largest
sous has validated in-tree. The greedy speculation figure of 2.0x is block
4 without the kernel; with it, block 5 ran about 2.3x.

Configs copied from the earlier documented example carry an explicit
speculative_block_size = 4, which always wins over the engine's choice of
5, so the configuration page now says to remove it. Bench rows are keyed
by model, drafter, block and window only, so the tuning page says a
--resume across an upgrade or a flip of attention_tile or
projection_kernel reuses stale timings.

Co-Authored-By: Claude <noreply@anthropic.com>
resolve_block resolved an unset block to 5 for a target on the mlx-lm
backend, or with a drafter drafter_compatible refuses, though the daemon
runs either pair undrafted; main then printed that the configured arm is
block 5 while quick_arms marked the drafterless arm current. Both cases
now leave the configuration as it is.

drafter_kind called mlx-vlm's private _expected_drafter_kind catching only
ImportError, so a changed signature in a newer mlx-vlm aborted the whole
tune over a check that only advises. Any exception from it now reads as an
unresolved kind.

Co-Authored-By: Claude <noreply@anthropic.com>
…el's gain

The merge gate measured decode on the M5 Pro's 64 real subagent turns with
the branch against main, each at its default, sampled, in ABBA order, and
the 32-64K bucket's ratio cleared 1.00. The 57K figure and the gap to
Splash at 51-57K scale with that ratio; the 2K figure and the short-context
gap stay, since no gate run measured short context.

Co-Authored-By: Claude <noreply@anthropic.com>
mlx hands a metal_kernel input of fewer than eight elements in the
constant address space, and the projection bodies read every input
through device pointers. A one-column linear at K < 512 has four to
seven scales, so the kernel failed in the Metal compiler for it:
eligible() took the projection, the warm-up failed, and the load warned
that the kernel should have run. eligible() and linears() now refuse it,
so such a load reports an expected refusal and linears() keeps its
ValueError contract. No projection of the default model is that small.

Co-Authored-By: Claude <noreply@anthropic.com>
… shape

Every projection call rebuilt its template, tile layout, output shapes
and kernel names, and a decoded token makes one call per projection
(497 on the default 27B). What T, K and the linears' N fix is now cached
per shape, and each variant's names and source per linear count: the
hook's graph-build cost fell from 9.4 to 8.1 us per call on an M2,
against 3.6 us for the raw kernel call. The launch and its bits are
unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
…s in the probe

projkernel carried a copy of tileattn._rel_rms, and its probe and
warm-up spelled out the verifier's module path and the weight triple
that _verifier_class() and _weights() already hold for the hooks. One
definition each, so the probe cannot drift from the hooks it proves.

Co-Authored-By: Claude <noreply@anthropic.com>
… kernel checks

_check_proj was _check_tile with one attribute and one noun changed.
Both now hand their status to one helper, so the notice for an
inherited setting the engine reports unavailable is written once.

Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Oct 4, 2026
krcm0209 added a commit that referenced this pull request Oct 4, 2026
## What and why

#147 moved the default verify block from 3 to 4 on every Mac, from
measurements on the M5 Pro only (#118). On the M2 that is a 3.8x decode
loss: mlx-vlm's exact verifier collapses there from 4 rows, where on the
M5 Pro its knee is at 6 (#156).

An unset `[model].speculative_block_size` now resolves at load by what
is active:
- **5** where the projection kernel is active (unchanged from #155);
- **4** where only the attention tile is active, which is the M5 Pro
with `projection_kernel = false`, where #118 measured block 4;
- **3** everywhere else: M1–M4, older macOS and other models. This was
the default before #147.

An explicit value, 0 included, keeps winning.

- `config.SPECULATIVE_BLOCK_DEFAULT` is now 3. `SPECULATIVE_BLOCK_TILE =
4` sits beside `SPECULATIVE_BLOCK_KERNEL = 5`.
- `tileattn.static_reason()` holds the tile's static half: the switch,
the platform rule, the core count's split target, the model type, the
attention shape and the drafter kind. `projkernel.static_reason()` calls
it and adds its own checks, with its messages unchanged.
- `sous tune`'s `arms.resolve_block` marks the current arm at 5, 4 or 3
by the same rule, and its printed line names the tile case.
- Docs: `CLAUDE.md`, `docs/configuration.md`, `docs/tuning.md` and
`docs/observability.md`.

No release carries #147; it landed after v0.7.0, so this fixes it before
one does.

## Measured

**M2 Air** (8-core GPU, macOS 15.5). The task set is #143's M2 one:
Qwen3.5-9B 4-bit with its DFlash drafter, 12 real turns, greedy,
max_tokens 512. Same harness throughout.

| tree | block | wall clock | decode tok/s | replies |
|---|---|---|---|---|
| main a9fa677 | 4 (default) | 1,083 s | 3.56 | — |
| main a9fa677 | 3 (explicit) | 391 s | 13.46 | 12/12 identical to block
4 |
| this branch | 3 (default; load line `draft_block=3`) | 400 s | 13.05 |
12/12 identical to both |

Each run emitted the same 3,311 tokens. Replies are compared with
tool-use ids stripped.

**M5 Pro**, the branch's load timings (the daemon stayed idle
throughout):

~~~
loadtime mode=plain enable_s=0.194 state=active reason=None probe_s=0.19
draft_block=5 load_s=2.94
loadtime mode=off enable_s=0.000 state=off reason=None probe_s=None
draft_block=4 load_s=2.21
loadtime mode=cold enable_s=3.402 state=active reason=None probe_s=3.4
draft_block=5 load_s=5.62
loadtime mode=warm enable_s=0.192 state=active reason=None probe_s=0.18
draft_block=5 load_s=2.46
~~~

The kernel still gives block 5. With `projection_kernel = false` the
tile gives block 4.

**Tests.** On the M2, `uv run pytest -m "not model"` gives 2095 passed,
39 skipped; ruff, ty and the lockfile are clean. New tests cover:
- the engine's three-way resolution, with explicit values winning and
no-drafter loads untouched;
- the config default and its fallback for an invalid value;
- `tileattn.static_reason`'s refusals;
- `resolve_block`'s tile case.

Closes #156.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
krcm0209 added a commit that referenced this pull request Oct 6, 2026
…same bits (#161)

## What and why

#155's parity design sends one-row projection calls through the
simdgroup projection kernel, so greedy output with the drafter on equals
output without it. That covers decode, the 1-row prefill tail and the
first token. But the MMA kernel's one-row call costs 1.24x qmv on the M5
Pro, so decode without a drafter ran 0.787x stock.

This adds a one-row kernel whose output equals the MMA kernel's **bit
for bit**, at about qmv's cost (#160).

- **`kernels/projection_row.metal`** (sous's own):
- One simdgroup per column, four simdgroups. Lane l takes quant groups
l, l+32, …, with coalesced loads.
  - Each group's dot is added in the MMA's own k order, from +0.
- Each quarter's epilogue `fma(dot, scale, acc); fma(sum_x, bias, acc)`
is folded in group order, and the quarters are added ((a0+a1)+a2)+a3.
- **`projkernel.linears()`** sends every one-row call there, one
dispatch per linear. Calls of 2–8 rows stay on the MMA kernel. The
hooks, the `mma` seam and the variant logic are unchanged.
- **Load-time safety.**
  - `warm_up` compiles the one-row kernel for every key the model uses.
- The probe asserts its rows equal the MMA path's bitwise on every key,
on random inputs and on five cancelling layouts. Each layout makes one
summation step's order visible in bf16. A mismatch makes the whole
kernel `unavailable` with a warning, since parity rests on it.
- `kernel_available()` runs the same check, so CI fails rather than
skips.
- `projkernel.calls` gains `one_row`.

Landing this cold-starts every on-disk fork store once (the engine epoch
hashes the kernel sources). Stored KV is unchanged bit for bit.

## Stage 1 (out of tree, pre-registered)

- **Order.** A CPU emulation reproduced the in-tree kernel's one-row
output bitwise on the 9B's real weights (1,534,464 / 1,534,464 outputs).
That pinned the exact order.
- **MMA order on both Macs.** The MMA adds its products in sequence on
both the M2 and the M5 Pro (4,096 / 4,096 tiles).

| | M2 Air, 9B | M5 Pro, 27B |
|---|---|---|
| one-row kernel bitwise equal to `projkernel.linears` at T = 1 |
10,051,584 / 10,051,584 | 24,913,920 / 24,913,920 |
| one-row cost per forward vs qmv | 1.046x | 1.012x |
| the MMA kernel's one-row call, same runs | 1.823x | 1.244x |

## Merge gate (M5 Pro, pre-registered; this branch against main 8b8ab62)

| criterion | result |
|---|---|
| Load | `projection_kernel=active draft_block=5`. Warm-up plus probe:
0.29 s warm (bound 1 s), 3.54 s cold (bound 10 s), 1.07 s first load
after install |
| Suites | M5 non-model: 2303 passed, 0 projection-kernel or tile tests
skipped. Model tests: projkernel, tileattn and verifyattn each `1
passed` |
| Decode without a drafter (sampled ABBA, first 16 turns) | **1.315x**
main (95% CI 1.300–1.327), 13.38 against 10.17 tok/s. Bar ≥ 1.10 |
| Drafted decode, each tree at its default (bar: point within 0.98–1.02)
| Sampled ABBA on 64 turns: **0.977** (CI 0.934–1.020), a miss by 0.003.
Greedy re-test: **0.991** (CI 0.984–0.997), pass. See below |
| Greedy parity, drafter on vs off, 69 turns to 229K tokens | 69/69
identical, cache histories equal on 69/69 |
| Path | `one_row` > 0 in every branch run, `declined` = 0 |
| `scripts/api_smoke.py` | passes on the M5 Pro and the M2 |

**The drafted-decode miss.**
- **The sampled runs compared different texts.** Sampled text differs
from run to run even within one tree: main's own two runs were identical
on only 10 of 64 turns and decoded at 25.30 and 27.44 tok/s, an 8.5%
spread. The branch's runs happened to generate longer, lower-acceptance
text: 3.32 against 3.55 tokens per round. Their rounds were shorter, not
slower: 127–131 against 129–141 ms.
- **The re-test removed that variable.** The maintainer ruled to re-test
this criterion greedy, with the same bar, decided before the runs. All
four greedy runs produced identical replies on 64/64 turns, with
identical tokens per round (3.658) and acceptance (0.665). That shows
end to end that this branch serves the same tokens as main.
- **The pass, and its slant.** The greedy ratio is 0.991. By pair, the
first pair (main first) gave 0.981 and the second 1.001, which points to
run-order drift on the machine rather than the kernel. One-row calls are
about two forwards per turn during drafted decode.

Docs: `CLAUDE.md` (the projection-kernel bullet),
`docs/configuration.md` and the `projection_kernel` comment in
`config.py` now give decode without a drafter its measured speed.

Closes #160. A follow-up can now revisit #158 (the kernel on M1–M4): its
blocker was this one-row cost.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
krcm0209 added a commit that referenced this pull request Oct 11, 2026
Stage 1 of #167: move mlx to 0.32.3 and validate the exact paths on it.
mlx-vlm main already requires mlx 0.32.3, so the mlx-vlm release that
carries the packed gated-delta prefill kernel (Neywa-Labs/mlx-vlm#2442,
stage 2) will need this first. mlx-vlm stays at 0.7.2.

## Change

- `verifyattn.VALIDATED_MLX` gains 0.32.3. 0.32.2 stays in the set, so a
tool environment still on it keeps the exact paths.
- `pyproject.toml` pins `mlx==0.32.3`, and the lock moves mlx and
mlx-metal to 0.32.3.
- Comments and docs refer to the releases in `VALIDATED_MLX` instead of
naming them, so the next bump has one set to extend, and one test name
no longer names a version. The bump checklist (the comment on
`VALIDATED_MLX` and CLAUDE.md) now names all three mirrors to re-read:
the SDPA dispatch `plan()` follows, `is_nax_available()` (mirrored by
`nax.py`) and `BaseNAXFrag::get_coord()` (mirrored by `kernels/nax.h`).
Some of these comments sit in `projkernel.py`, `tileattn.py`,
`int8prefill.py` and `kernels/nax.h`, which the fork store hashes;
editing them costs nothing, because the mlx version is already in the
fork key.

## Re-read, v0.32.2 → v0.32.3

- **`scaled_dot_product_attention.cpp`.** For head dim 256, GQA 6 and
1–8 rows, everything `plan()` mirrors is unchanged:
  - `has_fused_kernel` and the tail of `use_fallback`;
- the one-pass/two-pass rule and the two-pass block table (`s`, `d` and
the rest);
  - 65536 keys as the last threshold;
  - how `MLX_SDPA_BLOCKS` is read.

The new paths need head dim 512, the asymmetric (96, 64) head-dim pair,
more than 8 query rows (prefill only), or the two-pass GQA kernels:
factor 8 at head dims 64 and 128 (renamed, with a batch-index fix) and
new factors 12 and 16 at head dim 128. None of them is reachable at head
dim 256 and GQA 6 with 1–8 rows.
- **`sdpa_vector.h`.** Lines 1–324 are byte-identical. The one hunk is
inside `sdpa_vector_2pass_1_gqa`, which head dim 256 never reaches.
- **NAX mirrors.** `is_nax_available()` and `BaseNAXFrag::get_coord()`
are unchanged, so `nax.py` and `kernels/nax.h` still mirror them.
- **Custom kernels.** `custom_kernel.cpp` and the `metal_kernel` binding
are unchanged. `mlx/fast.cpp` only adds `gated_delta_update`, which
neither sous nor mlx-vlm 0.7.2 calls.
- **Projection-kernel pin.** `nn.QuantizedLinear.__call__` hashes the
same, so the pin holds.
- **Thread-local streams.**
- A fresh thread still gets its default stream lazily.
ml-explore/mlx#4514 only stops `eval` and the compile-cache lookup from
creating one when they don't need it; its other changes are CUDA-only.
  - `clear_streams` clears the same state, and now releases the GIL.
  - ml-explore/mlx#4462 and #4576 can't be reached from sous's threads.

## What moves anyway

- **Prefill attention changed on both GPU families**:
ml-explore/mlx#4487 on NAX GPUs, and on the others the fused path of
ml-explore/mlx#4505 for causal calls with qL == kL ≥ 2048.
- **Fused silu and swiglu change bits.** Sigmoid inside a fused compiled
kernel now uses precise exp (ml-explore/mlx#4461), and mlx compiles
`nn.silu` internally, so every silu and swiglu runs the changed kernel.
A lone `mx.sigmoid`, compiled or not, is bit-identical. Measured on the
M2 over a 2^20-point grid, silu's bits change on 546 bf16 values (about
0.05%) and 441,565 fp32 values; lone sigmoid's change on none.
- **Greedy text differs from 0.32.2** on 34 of #155's 64 real turns.
Each release agrees with itself on 64/64.
- **Every fork store starts cold once.**

## Gate (M5 Pro unless noted)

The rule was written down before any M5 run. Each speed comparison ran
main, branch, branch, main, each run in its own process; the decode,
parity and daemon runs each used their own isolated daemon (own config,
data directory and fork store), never the maintainer's. A harness defect
was fixed only by re-running that job; no threshold moved.

| # | Criterion | Result |
|---|---|---|
| 1 | Load | **PASS.** Every drafted branch load line has
`verify_attention=active`, `attention_tile=active`,
`projection_kernel=active`, `positions=engine` and `draft_block=5`, and
routes 336 int8 projections. The drafter-off parity run has the same
tile, kernel and positions, with `verify_attention=off` and no
`draft_block`, as expected without a drafter. The projection kernel's
warm-up and probe take 3.76 s cold (bar 10) and 0.32 s warm (bar 1). |
| 2 | Suites | **PASS.** Non-model tests: 2316 passed on both trees on
the M5, and on the M2 2277 passed and 39 skipped, the same skips as
main. Model tests on the branch, each file in its own process:
`test_engine_vlm` (24), `test_verifyattn_model`, `test_tileattn_model`,
`test_projkernel_model`, `test_int8prefill_model` (2), `test_api_model`
(3) and `test_engine_lm` (8) all passed. |
| 3 | Kernel timings | **Projection kernel: PASS.** Per-forward sum is
0.974–1.000x main at T = 1..8 (bar ≤ 1.02). **Attention tile: 14 of 15
cells pass (bar ≤ 1.03); ruled a pass.** The cell at 131072 keys and T =
3 came in at 1.065x. See below. |
| 4 | Prefill (16K, 64K) | **PASS.** 16384 tokens: 1.022x main (95% CI
1.003–1.043). 65536 tokens: 1.002x (0.987–1.018). Bar: CI lower end ≥
0.98. Peak memory is the same, 19.93 and 23.41 GiB. |
| 5 | Decode | **PASS.** Greedy, drafter on, #155's 64 turns: pooled
1.048x main (95% CI 1.015–1.086; bar: lower end ≥ 0.98). The median
per-turn ratio is 1.000. The pooled gain comes from the 64–128K turns,
where the two releases wrote different text and the branch's drafted
better (3.61 tokens per round against 3.44 overall). Read it as "not
slower", not as a speedup. |
| 6 | Parity | **PASS.** Greedy, drafter on vs off, 69 turns: 69/69
identical, with cache histories equal on 69/69. The one-row kernel
served every turn and declined nothing. |
| 7 | Daemon (M5 and M2) | **PASS on both.** `scripts/api_smoke.py`,
plus a run through the daemon's main mlx threads (endpoint pool,
session, model load, preload, idle sweep, status and unload): two turns
of one conversation, idle unload then reload, `/sous/unload` twice, a
`/sous/hold` preload, a decode under `/sous/status` polled at 10 Hz, two
`sous stop`s, and fork restores from disk in both daemon lives. One pid
per life; no stream, thread or crash errors. `count_tokens`,
`/sous/events` and a stalled-session retirement were not exercised. |

**The tile cell.** In one gate run, `kt-tile-br1`, that cell was slow
for every variant in the process: the tile at 37.76 ms, the stock
grouped baseline at 105.2 ms against 73–89 in the other runs. The other
branch run was the fastest of all four, at 30.16 ms. T = 1 and T = 8 ran
at normal speed in every one of these processes.

Two report-only repeats at 131072 keys:
- Three main/branch pairs. Two of the three branch runs hit the slow
mode (32.05 ms with an 88.0 ms baseline, and 37.00 ms with 107.2); none
of the main runs did.
- Ten interleaved pairs on a quiet machine. The branch measured 30.39 ms
(mean) against main's 30.57, so 0.994x. The slow mode hit main once and
the branch never.

Counting a process as slow when its stock baseline reached 88 ms, the
slow mode hit the branch in 3 of 15 processes and main in 2 of 15. The
maintainer ruled criterion 3 a pass on these repeats.

**Report only.**
- On the M2 (Qwen3.5-9B with its DFlash drafter), a prefill comparison
at 4K and 16K was dominated by run-to-run drift: every run was slower
than the one before, and main ran 103 tok/s in its first run and 89 in
its last. That fits thermal throttling on the fanless M2, though no
temperature was recorded. Peak memory was the same on both releases.
- The M2's first cold turn hits a Metal out-of-memory error inside the
drafter-context capture on main too. The error is caught and the turn is
served. It's the 16 GB M2's capacity, not this change.

## After merge

Reinstall the M5 tool environment with `uv tool install --reinstall`
(the pins carry 0.32.3). Expect one cold rebuild of each fork store.
#167 stays open for stage 2.

Refs #167

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
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