Repository navigation
feat(engine): run verify and decode projections on a small-row simdgroup kernel - #155
Merged
Merged
Conversation
) #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
engine: spike — the projection kernel without the attention tile on M1–M4 (M2 microbench first)
#158
Closed
Closed
This was referenced Oct 4, 2026
engine: spike — tensor-unit verify attention over GQA-packed rows at 57K, with bf16 and int8 KV
#132
Closed
Closed
Closed
engine: greedy vs sampled default — the greedy DFlash path needs sampler=None, not temperature=0
#87
Closed
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>
This was referenced Oct 5, 2026
Closed
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>
This was referenced Oct 7, 2026
Closed
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 targetcall 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.
[model].projection_kernel;falseruns today's paths.model with no drafter or a DFlash one;
unavailablewith its reason everywhere else, wherenothing changes.
[model].speculative_block_sizenow resolves to 5 where the kernel is active and to 4elsewhere; an explicit value always wins, and 0 keeps its meaning.
where the kernel is active (measured below).
projection_kernel=(withprojection_kernel_probe_s=when active)and
draft_block=, and/sous/statusaprojection_kernelblock anddraft_block.sous tunekeys suite rows by the setting, pins each block arm's block explicitly, and marksthe current arm by the block the engine would resolve.
Fork store. Landing this cold-starts every on-disk fork store once, including stores with the
kernel off: the fork key gains
proj, andprojkernel.pyjoins the engine epoch.Configs with an explicit block. A config that sets
speculative_block_size = 4(thedocumented 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:
speculative_verify_dflash_hiddenis refused with a warning rather thanat 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 anddecode reach the hooks.
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.pyitself prints FAILfor 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
Port equals spike: real 27B weights, every dispatch key, T = 1..8
Path (process totals per branch run)
Speed, primary: 4v against 5k drawn per round in one branch process, two sampled seeds
Speed, secondary: sampled ABBA on the 64 turns, each tree at its default
Per bucket (pooled decode tok/s; turns / output tokens):
tokens/round tile − main: 0.339 (95% CI 0.209..0.499)
peak memory_gb over these turns: tile 37.90, main 37.89
Drafter off, sampled ABBA on the first 16 turns
pairs br-nd1/main-nd1, br-nd2/main-nd2: 32 turn pairs
Parity: drafter on against off, greedy, 69 turns to 228,630 tokens
projection_kernel = false against main, greedy, 64 turns
Tool-loop suite: 8 tasks x 6 prompts, paired by prompt
Suite: failing diffs, branch imperfect runs against main on the same prompt
loadasCONFIG_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.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.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
M2 Air (9B + DFlash, the #143 task set)
scripts/api_smoke.py: M5PASS: a tool_use block came back, M2PASS: a tool_use block came back.🤖 Generated with Claude Code