Skip to content

perf(inkling2): Inkling 2 Mini prompt speedups, 8-bit trunk at load, stored round ladder, thinking-off fix - #1330

Closed
davidtai wants to merge 47 commits into
ddalcu:mainfrom
davidtai:inkling2/mini-speed
Closed

davidtai wants to merge 47 commits into
ddalcu:mainfrom
davidtai:inkling2/mini-speed

Conversation

@davidtai

@davidtai davidtai commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What changed / why

Merge order: this PR should merge after #1256. #1256 deletes core's nax_tiles.metal and nax_attention.metal, which this PR's relative_attention_nax.metal includes. Once #1256 lands, I repoint those includes at TurboNAX's copies in this PR (no numbers change).

This PR makes Inkling 2 Mini read prompts faster on Apple GPUs. From 4K-token prompts up, prefill is 8.5% to 16.6%
higher than main on the M5 Max and the M5 Ultra, with spec decode on and off. Time to first token (TTFT) is lower than
main's at every prompt size. At 1K and 2K, greedy prefill is 4% to 14% higher, and the first request a fresh server gets is
also faster than main's first request (M5 Ultra). Decode is level with main: at 1905d995, on the same text, this PR was within 0.1% of
main with spec on and with spec off, and a step benchmark on the same input gave the same forward time. At the head (48f90fb0), the step
benchmark on the same input gives 10.669 ms per one-row forward against main c3390fd85's 10.680, and 18.909 against 18.878 at 8 rows. Decode speed work goes in a separate PR.

The new tensor-unit prompt kernel had a race, found during this PR, that made greedy text change between fresh
servers. The PR fixes it, and every greedy sweep cell now writes one text on 4 fresh servers.

The head is 48f90fb0: 1905d995 with main c3390fd85 merged in (b6b5b6a7), and two commits on top.
b194d93ae removes the eight prompt switches. The MLX allocator fill hook and its pool-fill test have moved to their own
change, #1407, so this PR does not patch MLX. Main already has thinking on by default and the faster multi-user DFlash2 rounds. Each run below names the
commit it built. 1905d995 has the same tree as 211b5490, which its runs built. The sweeps, the first-prompt runs,
EvalPlus and PPL ran at a3a94835 on main 0d117e4fd. 211b5490 differs from a3a94835 only in per-launch
bookkeeping, with identical output. Greedy is temperature 0; card is temperature 1.0 and top_p 1.0, with no top_k sent. The prompt speedups have
no switches. Each path runs wherever its code gate allows: prompt rows only, the NAX device check, the shape and the bank
layout. Main's path runs everywhere else. TRUNK_Q8, MARKOV_Q8 and MLX_SERVE_GREEDY_SOLO_ROUNDS stay opt-in.

Area Change Default
SDK A last-row prompt ask returns the last row of the all-rows head, so its bytes match an all-rows ask (this also reaches the Ling 3.1 streaming pack). Always
Chat With thinking off and no tools, the Inkling render ends with the text message's open tags (<|message_model|><|content_text|>), so the model answers instead of thinking. Always
Engine, rounds The stored round ladder: each drafter's round timings are saved under a key (build, chip, RAM, model folder, MLX_ settings) and read back after a restart (MLX_SERVE_ROUNDS_LADDER=0 turns it off). MLX_SERVE_GREEDY_SOLO_ROUNDS=1 makes a greedy or seeded request round alone. On; solo rounds opt-in
Engine, first prompt A load that read a stored ladder serves one warm prompt inside the load, before the server listens: the rounds' context plus 3 tokens, and one generated token. Without it, a user's first prompt was the process's first prefill. A --warmup-full load is unchanged. On with a stored ladder
Prompt, tensor units only relnax: the prompt rows' attention through Stéphane Busso's relative_attention_nax.metal. gather_rowmap and gu_act: the experts' gate_up through a row map, with a SwiGLU epilogue in the SDK's NAX gather. Where the code gates allow; no switch
Prompt, where NAX is available (M5) prep_strided: prep reads a joined projection's parts in place, by row strides. gate_mm: a prompt's message gates run on the matrix units. stream_row: the norm gives each prompt row one threadgroup. prefill_async: a prompt's eval points run async. Each of the four needs verifyQmmNaxAvailable(), the device check the tensor-unit paths use. M1-M4 serve main's path for a prompt, byte for byte. A decode step's norm and prep launch main's kernels (norm_step.metal and prep_step.metal hold main's bytes). The row norm and the strided prep run only for a prompt's rows. Where the code gates allow; no switch
Load, Metal only PIPELINES_AT_LOAD: a record of first-launch pipelines, built again at the next load. The record takes first launches only before ready (the replay, the eager warm-up, the rounds' timing or the warm prompt) and closes at ready. After ready, a launch tests one bool for it. TRUNK_Q8=1 quantizes a bf16 trunk at load to the converter's 8-bit bytes (the same bytes as the 8-bit pack). Pipelines on; TRUNK_Q8 opt-in, so the release serves its bf16 trunk
Plugin ABI A new optional trailing ModelTable field, ready. The engine calls it once per load, after the load's own requests and before it marks the server ready. Inkling 2 closes its pipeline record in it. A table built before the field (an outside plugin on the previous kit) still loads, and readyOf reads the hook as absent. Additive
Config The eight prompt switches (NAX_PREFILL, BIAS_IN_ATTN, GATE_MM, GATHER_ROWMAP, GU_ACT, PREP_STRIDED, STREAM_ROW, PREFILL_ASYNC) are gone from env.zig. A served build reads each remaining MLX_SERVE_INKLING2_* switch and MLX_SERVE_GREEDY_SOLO_ROUNDS once per process; a test build reads them live, so the env.override tests hold. Tests that compare a whole forward against main's path use a test-only seam (kernels.test_main), which is false at compile time in a served build. Always
Engine, repeatable prompts A plugin that declares Caps.repeatable_prefill (Inkling 2) pins its prompt chunk from the machine's ceiling and the pack's bill, never live memory. A greedy or seeded prompt that does not fit keeps its width, waits up to 10 s for room, and then the engine refuses it with PrefillDoesNotFit. Every prompt logs one [repro] line (engines/mlx/repro.zig: a digest of the build, OS build, machine, pack and MLX_ set, and one of the plan). Always (Inkling 2)
Bundled MTP head MARKOV_Q8, an int8 fold, from #1323 (credit CerebralCoding). It acts only on a pack without a DFlash2 drafter/. Opt-in
Log, contract The load names the drafter that serves (drafter: dflash2 or drafter: the bundled mtp head). Kernel contract cases for the round kernels, relsplit_nax, relsplit_lanes, gate's prompt arm, gate_mm, prep's strided reads, both norm kernels, relative_attention_nax and MARKOV_Q8's two kernels.

The kernel rules (root AGENTS.md "A kernel serves every GPU family, KV layout and load"; engines/mlx AGENTS.md "A
kernel change is checked beyond its speed")

Rule How this PR meets it Evidence
Portable M1-M4 path, NAX tile behind the device check The tensor-unit read has one gate, relnaxTakes (tensor units, bf16, head dim 128, 16 relative dims). Every prompt it does not take reads main's relattn_nax. The row map and its epilogue need verifyQmmNaxAvailable(), and so do the strided prep, the row norm, the tiled gates and the async eval points: M1-M4 serve main's path for a prompt. inkling2 kernels: a prompt read the tensor-unit read does not take is main's relattn_nax, bit for bit; inkling2 proof: off NAX a prompt takes main's path, byte for byte (the GPU-family fallback forced: none of the prompt paths engages, and the logits are main's path's bytes)
Every load Each prompt path asks kernels.Load. Decode, verify, grouped verify and batched slots run main's path, and each path logs [inkling2] <path> engaged once. ...a verify's or batched slots' rows take main's gate, norm and prep; ...a verify's rows past 64 keep MLX's gather; inkling2 proof: batched slots and a grouped verify take main's path
One-row decode not slower A decode step's norm and prep launch main's kernels. A step benchmark on the same input (M5 Ultra, 23,040 tokens of context) gives 10.666 ms per one-row forward at 1905d995 against main's 10.671, and 18.877 against 18.890 at 8 rows; at the head: At the head 48f90fb0 against main c3390fd85: 10.669 against 10.680 ms (one row), 18.909 against 18.878 ms (8 rows). The pipeline record closes at ready, so after ready its cost is one bool test per launch. At 1905d995, with the prompt switches at 0 so that both arms write the same text, decode was 103.60 tok/s on main and 103.52 with spec off (-0.08%), and 194.77 and 194.64 with DFlash2 (-0.07%). inkling2 kernels: a step's norm launches main's kernel, a prompt's rows the row kernel; ...the norm kernel writes main's norm bytes at every load; ...the prep kernel writes main's prep bytes on contiguous projections; ...the pipeline record takes first launches before ready and none after; ...a launch does no pipeline-record work once the record is off or complete
Parity with the old path (not a text diff) The tests measure the tensor-unit read and gate_mm against float64 beside the paths they replace, each with a planted control. ...the tensor-unit prompt read is no farther from float64 than main's relattn_nax; ...a prompt's message gates on the matrix units are in the projected arm's precision class
bf16 and 8-bit KV Through the cache's kv-off view, the reads write the bytes they write on contiguous K and V. Through the 8-bit view, the tensor-unit read is no farther from float64 than main's read. ...a prompt's reads of an 8-bit cache's view are no farther from float64 than main's read
A gate asks the kernel's own layout check; a declined layout is named The row map asks gather_qmm_nax.bankLayoutOk. Other banks keep MLX's gather and log [inkling2] gather_rowmap declined: <layout> once. ...the row map takes the expert layouts its kernel decodes and declines the others by name; segmented NAX sorted gather: a bank layout the mapped kernels do not decode is not taken
NAX-only tests skip off NAX Proofs skip through verifyQmmNaxAvailable(), and so does each test that asserts a prompt path engages. The contract counts its .nax cases as skipped, and checks the tiled gates' and the row norm's wrappers only on NAX. The test runs below
CUDA still builds TRUNK_Q8, async prompt eval points and the pipeline record need a Metal build. Elsewhere the trunk stays dense and eval points stay synchronous. inkling2 config: the 8-bit trunk is opt-in and made on a Metal build only; inkling2: a prompt's eval points run async on Metal only, and never for a step; CI cuda jobs on this push
M1/M2 limits The offline check's inkling2 lines at a3a94835 (the head's kernel code) are 46 PASS, 8 FAIL and 15 INCONCLUSIVE, with no FAIL on a relnax, relsplit or relslots line and none on a q8 line. Main's relsplit and relslots records stated 1024, and they now record what M1 and M2 compile (576 and 832). The 8 FAIL lines are all main's dflash_attn bf16 record (1024, where M1 and M2 compile 512), which this PR does not touch; a drafter loads on M3 and later. The INCONCLUSIVE lines are the round kernels dflash_edges, dflash_tree and top16_shard, which this PR does not change. relsplit_lanes' tree read at 5 rows of 4 lanes compiles for 64 threads under a 96-thread launch; it serves only a drafter's verify, and a drafter loads on M3 and later. Kernel contract, offline (MLX_SERVE_KERNEL_CONTRACT_OFFLINE)
Speculation off and each drafter The sweeps and the same-text cells run DFlash2 and spec off. The bundled MTP head (a pack without drafter/) is not measured at this head. Tables below
Admission bill and peak Server peak, planned total and admission bill per size, for this PR and main, are in the memory tables. Tables below
A non-NAX Mac measures it Not measured. I have no M1-M4 Mac and asked for a run in a comment. The prompt paths run only where NAX is available, so M1-M4 serve main's path for a prompt. Not measured

Determinism

This PR had a bug that main does not have. On a fresh server, greedy text at prompts of 16K tokens and more changed from
run to run, with speculation off too, on the M5 Max and the M5 Ultra. The first token's logprobs differed between
servers, so the cause is in the prompt path. It followed the tensor-unit read in a prompt chunk that reads keys an
earlier chunk wrote. An 8K prompt in two 4,096-row chunks gave different first-token logprobs on fresh servers, and one
16,384-row chunk did not. With the tensor-unit read switched off (the NAX_PREFILL=0 switch of that time), 16K
repeated, and with async eval points also off, 32K too.

The cause was a race in relative_attention_nax.metal. Each SIMD group stages its block's bias tile in threadgroup
memory, and lanes then read values other lanes wrote. Only SIMD-group barriers inside a branch ordered that exchange.
A sliding read behind earlier keys stages on every visible block. On random repeats, 8 rows of one head came out
different: rows 8-15 of a group's 16, the last rows each lane writes. The fix puts a threadgroup barrier before and
after the staging, and every SIMD group reaches both barriers on a block that group 0 stages. Repeating the same read 24
times in one process gave different bytes in 3 of 3 processes before the fix and in none after it. Blocks that stage no
bias tile (far and plain blocks) keep the old code. With the barriers on every block, prefill fell behind past 32K
(-3.2% at 64K and -7.8% at 256K, spec on).

The tests below check that a request's bytes depend only on what its [repro] line names. The pool-fill test (T1, every
buffer MLX's allocator hands out starting as NaN or as a finite pattern) needs an MLX patch and lives in #1407 with it;
the runs below that name T1 ran with it at 48f90fb0.

Test What it holds
T1 (#1407) inkling2 pack: a prompt's logits and cache are the same bytes whatever the buffer pool held (INKLING2_RELEASE) Three 8,192-row chunks and a 17-row tail, two chunks past the packs' log-scaling floor. The plain pool, NaN fill and finite fill give byte-equal first-token logprobs, cache rows and conv states. On a difference it names the visit, the chunk and the path.
T2 inkling2 pack: a prompt's async eval points leave the bytes synchronous ones leave (INKLING2_RELEASE) Async and synchronous prompt eval points give byte-equal bytes with the pool as it is (the run under the fill moves to #1407).
inkling2 kernels: the tensor-unit prompt read behind an earlier chunk's keys repeats bit for bit relative_attention_nax behind 4,096 and 8,192 keys at ragged and whole row and key counts, global and sliding 1,024, 24 runs per case: every run equals the first. Red at the kernel before the fix in 3 of 3 processes.
Fresh servers M5 Ultra: an 8K prompt in two 4,096-row chunks, spec off, on 4 fresh servers gives one text, one first-token logprob set and one [repro] plan at a3a94835, and the same text at the head. Sweeps on both boxes (1K-512K, 4 fresh servers per cell, this PR and main): every greedy cell has one text, and every card cell has one text per seed.

How I verified it (M5 Max 128 GB and M5 Ultra 512 GB, macOS 27.2.1)

Main 0d117e4fd is the control in every comparison. Packs: ddalcu/Inkling-2-Mini-MLX-8bit (8-bit trunk, its DFlash2 drafter/) and the release
thinkingmachines/Inkling-2-Mini with the same drafter/ (bf16 trunk, no switch). Spec off is
MLX_SERVE_DSV4_DSPARK=0 (the engine's switch for native drafters). Card sends no top_k because
generation_config.json names none. Thinking is on as served (on by default since main 8dfc6126).

Main moved to c3390fd85 during the final runs (#1365 memory ceiling owner, #1385 Inkling 2 GGUFs, #1350, #1384, #1346, #1335, b5ed47a). The merge commit b6b5b6a7 brings main in on top of 1905d995. With #1365, the repeatable prompt's chunk pin reads main's single context-ceiling owner (--gpu-ceiling-gib / --memory-preset), still never live memory. Checks of b6b5b6a7 on the M5 Ultra against main c3390fd85:

Check Result
Inkling 2 unit tests (-Dtest-filter=inkling2, main's four -Dunits binaries) 378 passed / 13 skipped / 0 failed in all; the plugin binary 196 / 10 / 0
ABI tests 417 / 0 / 0
Targeted filters for the files the merge touched (abi, prefill_chunk, admission, warm, served_context, inkling2, load) All pass except two load tests in test-media, lm_head mxfp8: a dense head loads ... and EmbeddingGemma 2: a checkpoint missing its head ..., which fail the same way on main c3390fd85
An 8K prompt in two 4,096-row chunks, 4 fresh servers The same text and first-token logprobs as 1905d995, chunk width 4,096
Same text, prompt switches at 0 (since removed), spec off / spec on decode 103.60 → 103.53 (-0.07%) / 194.66 → 194.82 (+0.08%)
Standard cell as served, greedy (A main, B this PR) prefill 6,699.8 → 7,574.1 (+13.1%), TTFT 3.40 → 3.02 s, decode 194.85 → 215.46 on different text (not a speed result), chunk width 8,192 on every server; card prefill +12.5%

Gates:

Gate a3a94835 1905d995 (built as 211b5490)
zig build test, full suite with INKLING2_RELEASE, passed / skipped / failed M5 Ultra: 5,802 / 437 / 2. Both failures also fail on main 0d117e4fd on the same box: the deepseek_v41 DSpark-rounds test (3 of 3 runs on main) and disk_tier volumeSpace. M5 Max: 5,823 / 419 / 0
zig build test -Dtest-filter=inkling2 with INKLING2_RELEASE (T1 and T2 included), passed / skipped / failed M5 Ultra: 201 / 10 / 0 M5 Ultra: 201 / 10 / 0
ABI tests Not run M5 Ultra: 139 of 139 passed
zig build test -Dtest-filter="kernel contract" M5 Ultra: 125 / 1 / 0 (the skip is the offline record case) Not run; no kernel changed
The repeat-test binary (-Dtest-filter="repeats bit for bit", the tensor-unit read repeat test included), 3 fresh processes M5 Ultra: 63 of 63 tests passed in each Not run; no kernel changed
An 8K prompt in two 4,096-row chunks, spec off, 4 fresh servers M5 Ultra: one text, one first-token set, one [repro] plan M5 Ultra: the same text as a3a94835
Kernel contract, offline M1/M2: inkling2 PASS / FAIL / INCONCLUSIVE M5 Max: 46 / 8 / 15 (see the M1/M2 rules row) Not run; no kernel changed
PPL, 8,184 next-token predictions: 8-bit trunk (TRUNK_Q8=1 on the release) / bf16 trunk M5 Max: 8.3303 / 8.3319 Not run; identical output
CI (lint, CUDA) Runs on this push

PPL references on the same corpus: ddalcu main's bf16 trunk gave 8.3381, and mlx-lm PR 2086 gives 8.3318 on the
release.

Prefill. The context sweep below gives this comparison. Each point is the mean of 4 fresh servers, 8-bit pack, greedy;
card's change against main is within 2 percentage points of greedy's at every size.

prefill vs main

Prompt M5 Ultra, spec on: main / this PR Change M5 Ultra, spec off: main / this PR Change M5 Max, spec on: main / this PR Change M5 Max, spec off: main / this PR Change
1K 4,726 / 4,930 +4.3% 3,599 / 4,111 +14.2% 2,857 / 3,073 +7.5% 2,523 / 2,814 +11.5%
2K 5,935 / 6,247 +5.3% 5,046 / 5,390 +6.8% 3,428 / 3,759 +9.7% 3,170 / 3,562 +12.4%
4K 6,637 / 7,342 +10.6% 6,050 / 6,709 +10.9% 3,722 / 4,132 +11.0% 3,570 / 4,013 +12.4%
8K 7,003 / 7,928 +13.2% 6,583 / 7,646 +16.2% 3,843 / 4,304 +12.0% 3,730 / 4,239 +13.6%
16K 6,872 / 7,763 +13.0% 6,658 / 7,599 +14.1% 3,756 / 4,218 +12.3% 3,705 / 4,180 +12.8%
32K 6,488 / 7,349 +13.3% 6,397 / 7,313 +14.3% 3,499 / 3,911 +11.8% 3,489 / 3,896 +11.7%
64K 5,770 / 6,641 +15.1% 5,735 / 6,627 +15.6% 2,970 / 3,262 +9.8% 2,962 / 3,253 +9.8%
128K 4,732 / 5,504 +16.3% 4,710 / 5,491 +16.6% 2,270 / 2,476 +9.1% 2,268 / 2,474 +9.1%
256K 3,519 / 4,057 +15.3% 3,511 / 4,055 +15.5% 1,543 / 1,688 +9.4% 1,542 / 1,687 +9.5%
512K 2,323 / 2,610 +12.4% 2,318 / 2,611 +12.6% 937 / 1,017 +8.5% not run not run

At 512K, greedy prefill (main / this PR) on the M5 Ultra is 2,323 / 2,610 tok/s with spec on (+12.4%) and 2,318 / 2,611 with spec off
(+12.6%), and TTFT is 225.9 / 201.1 s. On the M5 Max it is 937 / 1,017 tok/s (+8.5%), TTFT 559.8 / 515.9 s. The M5 Max
512K point ran with spec on only, so its spec-off cells read "not run".

Greedy TTFT is 6% to 51% lower than main's at every size on both boxes, spec on and off. The largest drops are at 1K-8K with
spec on, on the M5 Ultra, where main's TTFT is 0.2-0.3 s longer than its prompt time.

TTFT, this PR vs main (s, 8-bit pack, greedy, mean of 4 fresh servers)
Prompt M5 Ultra, spec on: main / this PR Change M5 Ultra, spec off: main / this PR Change M5 Max, spec on: main / this PR Change M5 Max, spec off: main / this PR Change
1K 0.51 / 0.25 -50.7% 0.33 / 0.29 -10.8% 0.43 / 0.37 -13.4% 0.46 / 0.41 -9.3%
2K 0.57 / 0.37 -35.7% 0.45 / 0.42 -6.1% 0.64 / 0.58 -9.0% 0.70 / 0.63 -10.0%
4K 0.88 / 0.60 -31.4% 0.72 / 0.65 -9.4% 1.14 / 1.03 -9.8% 1.20 / 1.08 -10.0%
8K 1.44 / 1.07 -25.6% 1.29 / 1.12 -13.2% 2.18 / 1.94 -10.7% 2.25 / 1.99 -11.8%
16K 2.59 / 2.15 -17.0% 2.51 / 2.21 -12.2% 4.41 / 3.93 -10.9% 4.49 / 3.98 -11.2%
32K 5.24 / 4.53 -13.5% 5.18 / 4.54 -12.4% 9.46 / 8.47 -10.5% 9.47 / 8.48 -10.4%
64K 11.45 / 9.95 -13.0% 11.50 / 9.96 -13.4% 22.17 / 20.20 -8.9% 22.22 / 20.24 -8.9%
128K 27.80 / 23.92 -14.0% 27.92 / 23.97 -14.2% 57.88 / 53.05 -8.3% 57.91 / 53.11 -8.3%
256K 74.63 / 64.76 -13.2% 74.81 / 64.80 -13.4% 170.11 / 155.47 -8.6% 170.24 / 155.55 -8.6%
512K 225.91 / 201.08 -11.0% 226.40 / 201.06 -11.2% 559.84 / 515.86 -7.9% not run not run

The first request on a fresh server. M5 Ultra, a3a94835, 8-bit pack with DFlash2, 4 fresh servers per arm and
size, two measured requests per server (the prompt and 32 output tokens). Prefill tok/s, the median of the 4 servers:

Prompt main: request 1 / 2 This PR, rounds timed after ready: request 1 / 2 This PR, stored ladder (as served and swept): request 1 / 2
1,024 5,401 / 5,489 6,024 (+11.5%) / 6,064 (+10.5%) 5,671 (+5.0%) / 6,075 (+10.7%)
2,048 6,523 / 6,541 7,156 (+9.7%) / 7,164 (+9.5%) 6,866 (+5.3%) / 7,170 (+9.6%)

Main times its drafter's rounds after ready with a 1,280-token request in every boot, so its first measured request is
not the process's first prefill. A server of this PR that read a stored ladder now serves a 1,283-token warm prompt
inside its load. Its first request is 5% faster than main's first request, and its second is level with the other PR
arm. These requests are shorter than the sweep's, so compare them only within this table.

Decode on the same text, at the earlier heads. M5 Ultra, greedy, the standard cell's procedure (below), with this
PR's eight prompt switches at 0. These cells ran at 1905d995 and a3a94835, where the switches still existed;
b194d93ae removes them, so the head cannot repeat these cells. The prompt paths act only on prompt rows: a decode
step takes main's path with them on, as the tests in the kernel rules table check. With the switches at 0, both arms
wrote the same text, so the drafter accepted the same tokens in both arms. A = main 0d117e4fd, B = this PR:

Head, config Decode tok/s A / B Change Prefill tok/s A / B Tokens/round A / B Same text (of 3)
1905d995, 8-bit, spec off 103.60 / 103.52 -0.08% 6,556.5 / 6,614.9 - 3
1905d995, 8-bit, DFlash2 194.77 / 194.64 -0.07% 6,671.3 / 6,674.8 4.29 / 4.29 3
a3a94835, 8-bit, spec off 103.50 / 103.47 -0.03% 6,555.3 / 6,618.9 - 3
a3a94835, 8-bit, DFlash2 194.75 / 194.03 -0.37% 6,695.2 / 6,691.1 4.29 / 4.29 3

On a3a94835 the pipeline record stayed open through every measured decode, and each plugin launch paid a hash and a
short scan for it. a3a94835 measured -0.37% with DFlash2. The head, which closes the record at ready, measures
-0.07%. The spec-off sweeps agree. There, decode is within 1% of main at every size on
both boxes (-0.72% to +0.99%), although the texts differ; at 512K on the M5 Ultra it is 30.48 on main and 30.43 on this PR, greedy.
With spec on, sweep decode moves -10.0% to +21.6% against main. At 512K greedy, the drafter accepts 4.27 tokens a
round on this PR's text and 4.74 on main's, and decode is 106.96 on main and 96.25 on this PR (M5 Ultra), on different text. The two arms write
different text, and the drafter accepts different amounts of it, so these are not speed results.

Every same-text run, 1905d99 (M5 Ultra, greedy)
Config Run Arm Prompt Prefill tok/s Decode tok/s TTFT s Wall s Hit % Tokens/round Peak GB Text
8-bit, spec off 1 A p01 6,569.0 103.32 3.56 13.46 - - 30.5 ae33b5261716
8-bit, spec off 2 B p01 6,606.6 103.14 3.54 13.46 - - 30.5 ae33b5261716
8-bit, spec off 3 B p14 6,617.2 103.66 3.43 13.30 - - 30.4 4399b81bb6fb
8-bit, spec off 4 A p14 6,557.0 103.41 3.46 13.35 - - 30.4 4399b81bb6fb
8-bit, spec off 5 A p21 6,543.5 104.08 3.38 13.21 - - 30.4 5c75fa07c49c
8-bit, spec off 6 B p21 6,620.9 103.77 3.34 13.20 - - 30.4 5c75fa07c49c
8-bit, DFlash2 1 A p01 6,694.8 174.37 3.51 9.38 40.7 3.85 31.0 475059729f7d
8-bit, DFlash2 2 B p01 6,692.9 174.58 3.52 9.38 40.7 3.85 31.1 475059729f7d
8-bit, DFlash2 3 B p14 6,704.4 165.84 3.40 9.57 37.8 3.64 31.0 b98734df21d1
8-bit, DFlash2 4 A p14 6,625.0 166.03 3.44 9.60 37.8 3.64 31.0 b98734df21d1
8-bit, DFlash2 5 A p21 6,694.1 243.90 3.31 7.50 63.0 5.39 31.0 42524ece4882
8-bit, DFlash2 6 B p21 6,627.0 243.49 3.34 7.54 63.0 5.39 31.0 42524ece4882

Decode on the same input. A step benchmark gives each arm the same input, so it does not depend on the text. This
is the decode check for the head: main c3390fd85 against the head 48f90fb0 as served: one row 10.680 / 10.669 ms (-0.10%), 8 rows 18.878 / 18.909 ms (+0.16%), medians of 4 runs. The table below is the
same benchmark at 1905d995. M5 Ultra, spec off, 23,040 tokens of context, 400 decode forwards per run, 4 runs per
arm, median ms per forward (lower is better):

Arm 8 rows 1 row
main 0d117e4fd 18.890 10.671
1905d995 as served 18.877 (-0.07%) 10.666 (-0.04%)
1905d995, prompt switches at 0 18.918 (+0.15%) 10.660 (-0.09%)

At 1905d995 the prompt paths cost nothing in decode: every arm is within 0.15% of main at 1 row and at 8 rows.

Every step-benchmark run (ms per forward)
Rows Arm Run 1 Run 2 Run 3 Run 4 Median
8 main 18.891 18.889 18.871 18.925 18.890
8 1905d995 as served 18.909 18.827 18.866 18.887 18.877
8 1905d995, switches at 0 18.916 18.916 18.919 18.952 18.918
1 main 10.677 10.679 10.632 10.664 10.671
1 1905d995 as served 10.641 10.676 10.656 10.723 10.666
1 1905d995, switches at 0 10.656 10.646 10.665 10.682 10.660

The standard cell, as served. At the head 48f90fb0 against main c3390fd85, greedy: prefill 6,699.8 / 7,567.3 tok/s (+12.9%), TTFT 3.40 / 3.03 s, decode 194.80 / 215.45 on different text (not a speed result), chunk width 8,192 on every server; card prefill +13.5%. Its texts, tokens per round and ms per round equal the merge head b6b5b6a7's within 0.01 ms. The cell below ran at 1905d995 (built as
211b5490). M5 Ultra, 8-bit pack with DFlash2, against main 0d117e4fd: prompts
p01, p14 and p21 (23,077, 22,366 and 21,816 tokens), 1,024 output tokens, seed 1234, A B B A A B with a fresh server
per run, a pre-warm per arm on each prompt, a 40 C cool gate. A = main, B = this PR. Each cell is the arm's mean over
the three prompts. Every server of this PR read its stored round ladder and pipeline record, as served.

Prefill is 12.85% higher than main greedy and 12.18% higher with card settings. With the prompt paths on, the two arms
write different text on all 3 prompts, so decode here (+10.6% greedy, +2.8% card) is not a speed result. The drafts
differ, and greedy this PR accepts 4.79 tokens a round against main's 4.29. Per round, this PR takes 22.30, 21.99 and
22.27 ms on p01, p14 and p21, and main takes 22.04, 21.89 and 22.08 ms. The step benchmark above gives both builds the
same forward cost, so that difference also comes from the different text and drafts.

Greedy:

Config Prefill tok/s A / B Decode tok/s A / B TTFT s A / B Wall s A / B Hit % A / B Tokens/round A / B ms per round A / B Peak GB A / B Same text (of 3)
8-bit, DFlash2, M5 Ultra 6,697.8 / 7,558.3 194.90 / 215.63 3.41 / 3.03 8.81 / 7.82 47.2 / 54.3 4.29 / 4.79 22.00 / 22.19 31.0 / 30.4 0

Card settings, same order:

Config Prefill tok/s A / B Decode tok/s A / B TTFT s A / B Wall s A / B Hit % A / B Tokens/round A / B ms per round A / B Peak GB A / B Same text (of 3)
8-bit, DFlash2, M5 Ultra 6,699.2 / 7,515.3 169.87 / 174.60 3.41 / 3.06 9.51 / 8.93 50.1 / 52.1 3.50 / 3.61 - 31.0 / 30.3 0
Greedy Card
standard cell, greedy standard cell, card
Every standard-cell run, greedy (1905d99, then a3a9483 with spec on and off)
Head Config Run Arm Prompt Prefill tok/s Decode tok/s TTFT s Wall s Hit % Tokens/round ms per round Peak GB Text
1905d99 8-bit, DFlash2 1 A p01 6,692.9 174.53 3.52 9.38 40.7 3.85 22.04 31.0 475059729f7d
1905d99 8-bit, DFlash2 2 B p01 7,529.2 191.17 3.13 8.49 46.7 4.27 22.30 30.3 32aa21ad93ea
1905d99 8-bit, DFlash2 3 B p14 7,607.5 211.42 3.01 7.85 52.2 4.65 21.99 30.5 3610a8b82f75
1905d99 8-bit, DFlash2 4 A p14 6,702.4 166.34 3.40 9.55 37.8 3.64 21.89 31.0 b98734df21d1
1905d99 8-bit, DFlash2 5 A p21 6,698.2 243.83 3.30 7.50 63.0 5.39 22.08 31.0 42524ece4882
1905d99 8-bit, DFlash2 6 B p21 7,538.4 244.29 2.94 7.13 63.9 5.45 22.27 30.3 d31e986eedcd
a3a9483 8-bit, DFlash2 1 A p01 6,692.9 174.42 3.52 9.38 40.7 3.85 22.05 31.0 475059729f7d
a3a9483 8-bit, DFlash2 2 B p01 7,539.0 191.35 3.13 8.47 46.7 4.27 22.28 30.3 32aa21ad93ea
a3a9483 8-bit, DFlash2 3 B p14 7,540.8 209.88 3.03 7.91 52.2 4.65 22.16 30.3 3610a8b82f75
a3a9483 8-bit, DFlash2 4 A p14 6,698.4 165.95 3.41 9.57 37.8 3.64 21.94 31.0 b98734df21d1
a3a9483 8-bit, DFlash2 5 A p21 6,690.0 243.59 3.31 7.51 63.0 5.39 22.10 31.0 42524ece4882
a3a9483 8-bit, DFlash2 6 B p21 7,458.5 242.94 2.97 7.18 63.9 5.45 22.40 30.3 d31e986eedcd
a3a9483 8-bit, spec off 1 A p01 6,550.4 103.05 3.57 13.50 - - - 30.5 ae33b5261716
a3a9483 8-bit, spec off 2 B p01 7,502.3 103.21 3.13 13.04 - - - 29.8 d31b0f3b5690
a3a9483 8-bit, spec off 3 B p14 7,455.3 103.47 3.05 12.94 - - - 29.7 8bfc78e77f90
a3a9483 8-bit, spec off 4 A p14 6,551.3 103.74 3.46 13.32 - - - 30.4 4399b81bb6fb
a3a9483 8-bit, spec off 5 A p21 6,545.5 103.83 3.38 13.23 - - - 30.4 5c75fa07c49c
a3a9483 8-bit, spec off 6 B p21 7,435.6 103.49 2.98 12.87 - - - 29.7 f8aad2742c00
Every standard-cell run, card (1905d99, then a3a9483 with spec on and off)
Head Config Run Arm Prompt Prefill tok/s Decode tok/s TTFT s Wall s Hit % Tokens/round ms per round Peak GB Text
1905d99 8-bit, DFlash2 1 A p01 6,696.7 164.88 3.51 9.72 48.5 3.42 - 31.0 82c16c6f1986
1905d99 8-bit, DFlash2 2 B p01 7,539.0 169.49 3.13 9.16 50.1 3.51 - 30.4 d1458c623e83
1905d99 8-bit, DFlash2 3 B p14 7,381.5 185.78 3.11 8.62 57.0 3.85 - 30.3 f3f4c1bfb434
1905d99 8-bit, DFlash2 4 A p14 6,698.4 195.40 3.40 8.64 60.9 4.05 - 31.0 8c904018f332
1905d99 8-bit, DFlash2 5 A p21 6,702.3 149.32 3.32 10.17 40.9 3.04 - 31.0 61fdda39b378
1905d99 8-bit, DFlash2 6 B p21 7,625.3 168.53 2.93 9.00 49.2 3.46 - 30.3 447b242cc35c
a3a9483 8-bit, DFlash2 1 A p01 6,696.7 164.69 3.51 9.72 48.5 3.42 - 31.0 82c16c6f1986
a3a9483 8-bit, DFlash2 2 B p01 7,531.7 168.71 3.13 9.19 50.1 3.51 - 30.4 d1458c623e83
a3a9483 8-bit, DFlash2 3 B p14 7,530.6 184.84 3.03 8.57 57.0 3.85 - 30.4 f3f4c1bfb434
a3a9483 8-bit, DFlash2 4 A p14 6,700.4 195.22 3.40 8.64 60.9 4.05 - 31.0 8c904018f332
a3a9483 8-bit, DFlash2 5 A p21 6,694.1 149.32 3.32 10.18 40.9 3.04 - 31.0 61fdda39b378
a3a9483 8-bit, DFlash2 6 B p21 7,612.0 167.74 2.93 9.03 49.2 3.46 - 30.3 447b242cc35c
a3a9483 8-bit, spec off 1 A p01 6,569.0 102.48 3.56 13.54 - - - 30.5 6c7f20d868fd
a3a9483 8-bit, spec off 2 B p01 7,502.3 102.23 3.13 13.13 - - - 29.8 793704ad0802
a3a9483 8-bit, spec off 3 B p14 7,452.8 102.65 3.05 13.02 - - - 29.7 7325444442b4
a3a9483 8-bit, spec off 4 A p14 6,560.9 103.01 3.46 13.39 - - - 30.4 b0a0fd50345b
a3a9483 8-bit, spec off 5 A p21 6,529.8 103.46 3.39 13.28 - - - 30.4 b2bb2a1681cd
a3a9483 8-bit, spec off 6 B p21 7,360.3 103.20 3.01 12.93 - - - 29.7 23714711548d

Context sweep, 1K to 512K. The coding task built to each size, 1,024 output tokens, --ctx-size N + 16,384, 4 fresh
servers per point (seeds 1234, 1234, 4321, 4321), greedy and card, at a3a94835 and main 0d117e4fd. On the M5
Ultra, 4 unmeasured requests stored this PR's round ladder and pipeline record before the measured runs; main runs at
its defaults. In these charts and tables, decode follows the text each arm writes, so it is not a decode
comparison with main. The 512K point ran with the 8-bit pack only, for this PR and main: spec on and off on the M5
Ultra, spec on on the M5 Max. The release-pack (bf16 trunk) sweep ends at 256K on both boxes, and so does the M5 Max's
spec-off sweep; those 512K cells read "not run".

M5 Ultra:

Prefill and decode, greedy Prefill and decode, card
M5 Ultra sweep, greedy M5 Ultra sweep, card
M5 Ultra TTFT and wall, greedy M5 Ultra hit rate

M5 Max:

Prefill and decode, greedy Prefill and decode, card
M5 Max sweep, greedy M5 Max sweep, card
M5 Max TTFT and wall, greedy M5 Max hit rate
Sweep means, M5 Ultra: decode / prefill tok/s
Prompt 8-bit, spec on, greedy 8-bit, spec on, card 8-bit, spec off, greedy 8-bit, spec off, card bf16, spec on, greedy bf16, spec on, card main, spec on, greedy main, spec on, card main, spec off, greedy main, spec off, card
1K 216.9 / 4,930.1 194.9 / 4,902.9 116.0 / 4,110.9 115.4 / 4,104.9 188.7 / 4,836.1 166.9 / 4,810.1 216.8 / 4,726.5 196.0 / 4,755.5 116.1 / 3,599.1 115.3 / 3,599.6
2K 258.9 / 6,246.9 178.2 / 6,267.7 115.6 / 5,390.4 114.6 / 5,344.9 201.2 / 6,184.5 161.7 / 6,145.6 256.3 / 5,934.9 185.6 / 5,979.1 115.2 / 5,045.7 114.8 / 5,094.8
4K 260.5 / 7,341.6 203.3 / 7,258.8 112.3 / 6,709.0 111.8 / 6,615.6 240.9 / 7,373.3 173.8 / 7,289.0 214.3 / 6,637.2 199.0 / 6,653.3 112.7 / 6,050.3 112.0 / 6,044.2
8K 217.6 / 7,927.7 175.2 / 7,917.1 111.5 / 7,646.3 110.6 / 7,645.5 188.9 / 7,941.1 171.5 / 7,937.6 225.7 / 7,003.2 183.7 / 6,987.5 111.3 / 6,582.9 110.8 / 6,596.6
16K 214.4 / 7,763.4 175.4 / 7,791.4 106.8 / 7,598.8 105.9 / 7,625.7 193.9 / 7,763.8 161.7 / 7,743.2 219.7 / 6,871.5 191.7 / 6,865.9 106.8 / 6,657.9 106.0 / 6,659.0
32K 192.4 / 7,348.6 173.2 / 7,369.5 98.6 / 7,312.7 98.0 / 7,300.5 187.1 / 7,377.1 153.9 / 7,396.2 193.2 / 6,488.4 161.3 / 6,487.2 98.7 / 6,397.4 98.1 / 6,390.4
64K 185.6 / 6,641.2 156.9 / 6,645.5 86.1 / 6,626.6 85.9 / 6,609.9 167.4 / 6,626.7 128.7 / 6,647.4 179.8 / 5,769.6 158.3 / 5,772.2 86.3 / 5,734.7 86.0 / 5,726.9
128K 163.9 / 5,504.1 136.8 / 5,510.1 68.5 / 5,490.5 68.5 / 5,485.9 155.4 / 5,493.7 130.2 / 5,501.7 160.7 / 4,731.9 133.0 / 4,729.0 69.0 / 4,710.2 68.6 / 4,708.2
256K 135.5 / 4,057.2 114.1 / 4,057.4 48.6 / 4,055.0 47.7 / 4,058.9 136.6 / 4,054.1 102.6 / 4,056.0 141.1 / 3,519.5 100.8 / 3,520.9 48.3 / 3,510.9 47.8 / 3,512.1
512K 96.3 / 2,610.3 81.4 / 2,610.8 30.4 / 2,610.9 30.3 / 2,610.2 not run not run 107.0 / 2,323.2 85.6 / 2,322.1 30.5 / 2,318.3 30.3 / 2,319.4
Sweep means, M5 Max: decode / prefill tok/s
Prompt 8-bit, spec on, greedy 8-bit, spec on, card 8-bit, spec off, greedy 8-bit, spec off, card bf16, spec on, greedy bf16, spec on, card main, spec on, greedy main, spec on, card main, spec off, greedy main, spec off, card
1K 168.1 / 3,072.6 155.1 / 3,065.4 91.2 / 2,813.8 90.9 / 2,815.3 142.8 / 3,034.1 128.7 / 3,037.0 167.7 / 2,856.9 155.5 / 2,856.7 91.5 / 2,523.2 91.0 / 2,536.3
2K 199.9 / 3,758.6 141.7 / 3,752.7 90.2 / 3,562.3 89.8 / 3,527.5 151.8 / 3,738.2 124.8 / 3,733.3 197.5 / 3,427.8 147.2 / 3,426.8 90.5 / 3,170.0 90.0 / 3,170.6
4K 200.5 / 4,131.8 161.6 / 4,129.4 88.1 / 4,013.2 87.6 / 4,012.7 181.8 / 4,151.6 134.1 / 4,150.4 165.4 / 3,721.6 157.4 / 3,727.0 88.2 / 3,570.0 87.9 / 3,571.8
8K 166.8 / 4,304.1 137.7 / 4,306.3 86.4 / 4,238.9 86.0 / 4,240.5 141.6 / 4,319.4 131.0 / 4,321.1 172.1 / 3,842.8 144.0 / 3,843.1 86.5 / 3,730.1 86.1 / 3,735.9
16K 163.1 / 4,218.3 136.8 / 4,216.5 81.6 / 4,180.4 81.2 / 4,178.1 144.2 / 4,234.5 122.6 / 4,233.9 166.5 / 3,756.4 148.9 / 3,756.1 81.7 / 3,705.3 81.3 / 3,704.7
32K 146.2 / 3,910.7 134.8 / 3,916.8 73.3 / 3,896.1 72.9 / 3,889.1 139.2 / 3,924.6 116.3 / 3,918.7 146.8 / 3,498.8 125.3 / 3,505.5 73.4 / 3,488.8 73.1 / 3,478.7
64K 138.5 / 3,261.6 120.9 / 3,264.5 60.9 / 3,252.6 60.5 / 3,255.1 120.1 / 3,265.9 95.6 / 3,264.8 133.6 / 2,970.2 121.7 / 2,964.5 60.7 / 2,962.1 60.3 / 2,960.7
128K 116.7 / 2,476.4 100.2 / 2,478.0 44.9 / 2,473.6 45.2 / 2,477.0 108.2 / 2,479.6 92.2 / 2,481.7 114.0 / 2,269.6 97.1 / 2,270.8 45.1 / 2,268.3 45.1 / 2,266.7
256K 91.4 / 1,688.0 78.2 / 1,688.0 28.7 / 1,687.5 28.7 / 1,688.3 90.4 / 1,689.6 69.2 / 1,688.1 95.0 / 1,542.6 68.9 / 1,542.7 28.4 / 1,541.7 28.4 / 1,541.9
512K 56.1 / 1,016.9 47.3 / 1,019.6 not run not run not run not run 62.0 / 937.0 49.8 / 936.9 not run not run

Every sweep run (arm, spec, size, mode, seed, the six columns, tokens per round, output tokens and a text digest) is in
sweep_runs_m5u.md and
sweep_runs_m5max.md.

Memory, spec on. The server's peak footprint (the max of the 8 runs per size, the mlx-serve process, not the whole
box), the engine's planned total, and the [admission] request bill. The planned total and the bill are main's at
every size. With the 8-bit pack, server peak differs from main's by -0.9 to +1.4 GB (at 512K, main / this PR: 47.5 / 47.1 GB on
the M5 Ultra and 47.4 / 47.4 on the M5 Max). No bf16 sweep ran at 512K.

M5 Ultra 1K 2K 4K 8K 16K 32K 64K 128K 256K 512K
this PR, 8-bit, server peak GB 21.7 22.7 24.8 28.2 32.0 30.9 32.0 34.2 38.5 47.1
this PR, 8-bit, planned total GB 20.20 21.37 23.38 27.41 28.16 28.83 30.18 32.86 38.23 48.97
this PR, 8-bit, admission bill MB 2,012 3,124 5,044 8,884 9,604 10,244 11,524 14,084 19,204 29,444
this PR, bf16, server peak GB 25.1 25.1 26.5 29.6 33.0 32.0 33.0 35.2 39.5 not run
this PR, bf16, planned total GB 21.64 22.65 24.66 28.69 29.44 30.11 31.46 34.14 39.51 not run
this PR, bf16, admission bill MB 2,012 2,972 4,892 8,732 9,452 10,092 11,372 13,932 19,052 not run
main, 8-bit, server peak GB 21.9 22.8 24.6 28.9 31.4 31.8 32.4 34.6 38.9 47.5
main, 8-bit, planned total GB 20.20 21.37 23.38 27.41 28.16 28.83 30.18 32.86 38.23 48.97
main, 8-bit, admission bill MB 2,012 3,124 5,044 8,884 9,604 10,244 11,524 14,084 19,204 29,444
M5 Max 1K 2K 4K 8K 16K 32K 64K 128K 256K 512K
this PR, 8-bit, server peak GB 23.0 23.0 24.6 27.9 31.8 31.1 32.2 34.4 38.7 47.4
this PR, 8-bit, admission bill MB 2,012 3,124 5,044 8,884 9,604 10,244 11,524 14,084 19,204 29,444
this PR, bf16, server peak GB 27.0 27.0 27.0 29.2 32.7 31.9 33.0 35.2 39.5 not run
this PR, bf16, admission bill MB 2,012 2,972 4,892 8,732 9,452 10,092 11,372 13,932 19,052 not run
main, 8-bit, server peak GB 21.6 22.6 24.3 28.6 30.8 31.2 32.3 34.4 38.7 47.4
main, 8-bit, admission bill MB 2,012 3,124 5,044 8,884 9,604 10,244 11,524 14,084 19,204 29,444

M5 Ultra memory

Code evals. EvalPlus, pass@1, M5 Max, a3a94835, greedy, DFlash2 as served, thinking on, max_tokens 16,384:

Trunk HumanEval HumanEval+ MBPP MBPP+
bf16 (release) 156/164 152/164 352/378 288/378
8-bit 154/164 150/164 348/378 284/378

Each trunk hit the 16,384-token cap on 1 HumanEval and 5 MBPP problems. Between the trunks, the 8-bit trunk passes 5
HumanEval problems that bf16 fails and fails 7 that bf16 passes. The counts are 4 and 6 on HumanEval+, 8 and 12 on
MBPP, and 12 and 16 on MBPP+.

Known limits:

  • TRUNK_Q8 is lossy against the release's bf16 trunk. It is opt-in, and the PPL row above gives both trunks.

  • MARKOV_Q8 is opt-in, and no run above sets it.

  • A user who set one of the eight removed prompt switches now gets the default path. The engaged and declined log
    lines name paths (relnax, gate_mm, stream_row, prep_strided, gather_rowmap, gu_act, prefill_async),
    not switches.

  • The rebase onto 0d117e4fd dropped group_contract.zig, so the offline check prints 14 fewer PASS lines than before
    the rebase. Its f16, f32 and tree relsplit contract coverage is owed.

  • The pipeline record holds only launches that a before-ready request reaches. A launch that none reaches (sampled
    rounds, batched slots, a longer context's lanes) builds its pipeline in the first request that needs it, in every
    process.

  • A greedy or seeded prompt whose pinned chunk does not fit waits up to 10 s for room, and then the engine refuses it
    with PrefillDoesNotFit. A chunk sized from live memory would change the prompt's bytes.

  • No M1-M4 Mac has run this PR. The prompt paths (prep_strided, gate_mm, stream_row, prefill_async, and the tensor-unit paths) run only where NAX is available (M5), so M1-M4 serve main's path for a prompt, byte for byte (inkling2 proof: off NAX a prompt takes main's path, byte for byte, under the forced GPU-family fallback). Before this gate, an M5 Ultra with MLX_SERVE_DIAG=force-gpu-family-fallback=1 ran the four portable paths off NAX (MLX's own kernels may still use the tensor units): the inkling2 lane passed 368 / 23 / 0, and the standard cell's prefill was +1.6% (greedy) and +1.5% (card) against main, with ms per spec round level (see the comment of 2026-11-30). With the gate, that diag takes main's prompt path. No run at this head measures the bundled MTP head (a pack without drafter/).

  • No test runs a whole release-pack prompt through the row norm (stream_row) against main's path. The whole-forward test was dropped as slow; the norm kernel's byte tests at the release's widths (1/8/16/512 rows, D 2304, routed or not, f32 and bf16), the kernel contract's row-norm entry and the pipeline-record test cover the kernel.

  • The release-pack tests share one load per load configuration (inkling2/test_loads.zig); a test that changes the loaded model or reads load-time counts keeps its own load.

  • Without MLX_SERVE_GREEDY_SOLO_ROUNDS=1, a greedy request that shares rounds can get other text than it gets alone
    (docs/known-issues.md).

  • The host's sidecar line "the drafter ... served without it" means only that the host's own drafter loader steps aside
    for the plugin's. The drafter: dflash2 line says what serves.

  • Searched open and closed issues, open PRs and recent commits; linked the existing thread if there is one

  • Built and ran this tree on a real Apple Silicon Mac in this session

  • No comments that restate code, carry history, or cite audit/review items

  • No source-scan tests; every test checks behaviour

  • One fix or feature; description under ~15 lines (it carries the work above)

@davidtai davidtai changed the title perf(inkling2): faster prefill and drafted decode, 8-bit dense trunk perf(inkling2): one PR for Inkling 2 speed (#1331, #1323, #1320 merged in) Nov 26, 2026
@davidtai davidtai changed the title perf(inkling2): one PR for Inkling 2 speed (#1331, #1323, #1320 merged in) perf(inkling2): Inkling 2 Mini speed on main: #1330 kernels and 8-bit trunk, #1323 8-bit drafter, #1331 review fixes Nov 26, 2026
@davidtai
davidtai force-pushed the inkling2/mini-speed branch from 4397128 to 5e55677 Compare November 27, 2026 00:55
@davidtai davidtai changed the title perf(inkling2): Inkling 2 Mini speed on main: #1330 kernels and 8-bit trunk, #1323 8-bit drafter, #1331 review fixes perf(inkling2): Inkling 2 Mini prompt speedups, 8-bit trunk at load, stored round ladder, thinking-off fix Nov 27, 2026
@cowboycoderhq

Copy link
Copy Markdown
Contributor

Built and tested head 5e556773 on an Apple M5 Max (128 GB, macOS 27.2.1, Zig 0.17.0, lib/mlx built for patch=613a4be4d66a, libllama b12110):

  • zig build test (7 shards): 5,730 passed, 425 skipped, 1 failed (lint-test, unit-closure, and build-kit-test 8/8 all passed). All Inkling 2 unit tests and Metal kernel-contract tests passed with their planted controls red.
    • The sole failure in the 7-shard run was sdk.quant.native.test.quant nvfp4: ModelOpt's weight_scale_2 reaches MLX as amax / (448 * 6) (src/sdk/quant/native.zig:401), which hit a macOS memory-pressure abort inside modelopt_pack.adapt while 7 GPU shards ran in parallel. Re-running it solo (zig build test -Dtest-filter="weight_scale_2") passed with 0 failures and 0 leaks.
  • Release build (zig build -Doptimize=ReleaseFast -Dunits=true): built cleanly.
  • Live integration (tests/test_inkling.sh) on the official thinkingmachines/Inkling-2-Mini weights: 14 passed, 0 failed (raw greedy prefix, thinking-off fix, thinking-on, streaming, tool call, and tool round-trip).
    • Confirmed in server logs: trunk_q8 (178 dense tensors, 8-bit affine g64), drafter: the bundled mtp head, MLX_SERVE_INKLING2_NAX_PREFILL, gather-nax interleaved soft-capped SwiGLU, and stored round-ladder write + read-back across restart (plain step 11.6 ms, 7 drafts).

(Scope note: did not run the 1K–256K context sweep, HumanEval/MBPP, or a pack with an embedded DFlash2 drafter/ dir.)

@cowboycoderhq

Copy link
Copy Markdown
Contributor

Follow-up on 5e556773 (Apple M5 Max 128 GB, macOS 27.0.1, official thinkingmachines/Inkling-2-Mini release weights with incoai/Inkling-2-Mini-DFlash2 linked as drafter/, trunk_q8 engaged on 178 dense tensors, drafter: dflash2):

1K–256K Context Sweep (llmprobe v0.6.18 --bench-only, 1 run/rung)

  • 1k–128k run: --ctx-size 262144 --max-concurrent 4 — solo decode 154.4 tok/s (sustained 154.4 → 155.2 tok/s over 3m 40s), TTFT 187 ms, 8.8K prefill 3,631.2 tok/s (3,106.4 tok/s unseen), prefix cache 23.2× (3.6 s → 157 ms, 9,892/9,923 cached), concurrency decode totals (2 / 4 / 6 / 8 users): 179.4 / 205.8 / 241.8 / 238.7 tok/s.
  • 256k rung (~270.7k tokens): re-run with --ctx-size 280000 --max-concurrent 1 (at --ctx-size 262144 / 270000 the 270,376-token prompt exceeded the manual cap).
Context rung Decode Prefill TTFT Speculation
~1k 120.6 tok/s 2,162 tok/s 476 ms 3.43 tok/step
~4.1k 168.7 tok/s 2,720 tok/s 1.5 s 4.92 tok/step
~16.5k 144.7 tok/s 3,135 tok/s 5.3 s 4.36 tok/step
~32.8k 137.2 tok/s 2,878 tok/s 11.4 s 8.00 tok/step
~65.5k 117.8 tok/s 2,584 tok/s 25.3 s 4.27 tok/step
~131.2k 120.6 tok/s 2,038 tok/s 64.4 s 4.47 tok/step
~270.7k 91.2 tok/s 1,327 tok/s 204.0 s 4.47 tok/step

HumanEval + MBPP (llmprobe --eval-only --eval-suite code --concurrency 4 --reasoning off, T=0, 58 s)

Suite Score
Overall 78/100 (78%)
HumanEval 46/50 (92%)
MBPP 32/50 (64%)

davidtai and others added 22 commits November 28, 2026 19:09
Run.finish and the KDA hybrid's finish ran a one-slot `.last_row` prompt's head over its last 32 rows
(`head_tail`). MLX picks its matmul kernel and K split by row count, so a last-row prompt could return
other bytes than the same row of the all-rows forward, which `Caps.prompt_last_row` promises. `.last_row`
is now the slice of the head's call over every row, as an `.all_rows` ask runs it. `head_tail`, both
`head_tail_rows` and the `qmm_rows_min` floor are gone.

The engine frees an interior prompt chunk's logits without evaluating them, and with prompt checkpoints
the final prompt forward is at most 31 rows.
With thinking off, Inkling's template renders only a "Thinking effort level: 0" line, and Inkling 2 could
then think through all of max_tokens. contentChannelTail now ends the render with
`<|message_model|><|content_text|>` (Inkling 2) or `<|content_text|>` (Inkling Small, whose render ends at
`<|message_model|>`) when thinking is off and the request has no tools.
…s stored per release

A greedy or seeded request on a served drafter that groups now runs its own rounds and is nobody's company
(`native_group.roundsAlone`, `MLX_SERVE_GREEDY_SOLO_ROUNDS`), so its text does not follow other requests.
The paths that still can are in docs/known-issues.md.

The round ladder is timed once per key (build and MLX build, chip, RAM, model folder, the server's MLX_
variables) and read back by later boots (`ladder_store.zig`, `MLX_SERVE_ROUNDS_LADDER`, =0 off), so two
boots of one build verify the same draft counts.
…U epilogue

`sortedGateUpInterleaved`: the mapped gate_up's epilogue applies the expert's scale and the soft-capped
SwiGLU to the rounded gate (even) and up (odd) products, so a prompt chunk's activation is one launch.
…elines at load

Default on (=0 gives main's path): TRUNK_Q8 (the dense trunk at 8-bit affine g64 at load, the bytes
tests/convert_inkling2.py --bits 8 writes), PREP_STRIDED (prep reads a joined projection's parts in place),
GATHER_ROWMAP and GU_ACT (a NAX prompt chunk's gate_up through the sorted pairs' row map, the SwiGLU in its
epilogue), GATE_MM (past packed_rows, a later pass's message gates as one tiled f32 kernel), STREAM_ROW (the
norm kernel at one threadgroup a row), PREFILL_ASYNC (a prompt's eval points as async evals) and
PIPELINES_AT_LOAD (this build, machine and composition's first launches replayed at load).

Opt-in for an A/B against main's code: NAX_PREFILL (relative_attention_nax.metal, Stéphane Busso's, for
the prompt-row read; off: relattn_nax.metal), with BIAS_IN_ATTN under it.
…_Q8, opt-in)

The Markov chain's fold held as int8 a vocab row with a scale each (`Drafter.quantizeFoldRows`,
`markov_fold_q8_row.metal`), and the step's RNN reading its block-row and newest-mix share from `kappa`,
made once a block (`markov_step_rnn.metal`). Opt-in for an A/B against main's group-64 8-bit fold
(`MLX_SERVE_INKLING2_MARKOV_Q8`). Drafts are proposals, so the trunk's picks stand. It acts only on a pack
without a DFlash2 drafter/.
…y reads and the levers

rounds_contract.zig: commit_conv, accept_tree, sample_tree_mass/_search/_draw, dflash_conv, dflash_top16_shard
and _merge, dflash_edges, dflash_tree. group_contract.zig: relsplit_nax, relsplit_lanes. trunk_contract.zig:
gate's prompt arm. contract.zig: gate_mm, prep's strided reads, the norm at one threadgroup a row,
relative_attention_nax (NAX_PREFILL) and MARKOV_Q8's two kernels. Each has a float64 reference or the kernel it
replaces, and a planted control.
relative_attention_nax.metal's flash read (with the in-read relative bias) won its A/B against main's relattn_nax
on the ddalcu 8-bit pack with DFlash2 (coding test, 23,077-token prompt, 1,024 greedy tokens, 8 runs, M5 Max):
prefill 3,938.9 -> 4,088.9 tok/s (+3.81%), TTFT 5.87 -> 5.65 s, peak -0.2 GB, PPL 8.3295 -> 8.3303. Decode
moved -1.95% with the text (the same 8 rows and round time). =0 serves main's read.
MLX_SERVE_GREEDY_SOLO_ROUNDS is now opt-in. On by default it held greedy multi-user decode at about 147-151 tok/s
from 2 to 8 users on an M5 Max (bench.sh, the 8-bit pack with DFlash2), where grouped rounds reach 275. Off, a greedy
request groups as on main; =1 keeps its text the one it gets alone. known-issues says so.
A pack with drafter/ serves DFlash2 and one without serves the bundled MTP head, and nothing in the log said which:
the engine's sidecar check logs that it declines drafter/, which reads as if the pack ran without it.
… solo rounds' docs say opt-in

With NAX_PREFILL on, a prompt that relative_attention_nax cannot serve (not bf16 at head dim 128, or no tensor units)
skipped main's relattn_nax and fell to relattn. It now takes main's read. The engine rules and the gotcha still
described rounding alone as the default; they now say it is opt-in, and its env entry's release is 26.12.1.
…atched slots keep main's path

PREP_STRIDED, STREAM_ROW, GATE_MM, GATHER_ROWMAP, GU_ACT and PREFILL_ASYNC keyed on the forward's rows, so batched
decode at 9-32 slots and grouped verifies (past 64 rows at 11 DFlash2 lanes on NAX) took arms measured only on prompt
chunks; GATHER_ROWMAP's prompt call also lifted the condition that keeps MLX's verify bits. Each lever now asks
kernels.Load, which visit and sequence read from the forward's mode: a prompt chunk, or a step (decode, verify,
grouped verify, batched slots) that runs main's path. Every lever logs its engagement once, and tests read the flag:
the gate, norm and prep kernels at 12, 36 and 72 step rows and the experts at 72 on NAX take main's bytes with the
levers on, and through the forward 12 batched slots and a 6 x 6 grouped verify engage none.
…ames a layout it declines

GATHER_ROWMAP and GU_ACT gated on a hand list (an FP4 bank, bf16 rows). They now ask gather_qmm_nax.bankLayoutOk, the
bank half of the kernel's own `supported` (NVFP4 g16, MXFP4 g32, affine 2, 3, 4 and 8 bits at g32, 64 and 128 with
bf16 scales and biases), so a q4 pack's affine experts take it; MXFP8, affine 5 and 6 bits and other scale dtypes keep
MLX's gather and log `[inkling2] MLX_SERVE_INKLING2_GATHER_ROWMAP declined: <layout>` once. The SDK's interleaved
SwiGLU epilogue test runs every layout the check takes, not NVFP4 g16 alone.
…D off or once its record is complete

Every launch hashed its kernel, template arguments and dtypes and scanned up to 1024 keys (`pipes.saw`), with the
switch off too, in a dispatch-bound one-row decode. The lookup now runs only while a record is open (`Pipes.watching`)
or replays. A record closes after 4096 forwards with no first launch: it ends with a `#closed` line, and a process that
replays a closed record never looks a launch up. Test: off, open, closed and replayed-closed records.
… run on Metal only; the fit key test holds off macOS

TRUNK_Q8 and PREFILL_ASYNC were not Metal-gated, so they changed Inkling 2's CUDA path unmeasured, and
PIPELINES_AT_LOAD made its folder there for kernels that never launch. TRUNK_Q8 (config.trunkQ8) and PREFILL_ASYNC
(plugin.prefillAsync) now need a Metal build and the record needs the kernels on; another backend keeps main's dense
trunk and synchronous eval points. The fit key test asserted the executable's digest, which off macOS is the zero
placeholder by design; it now asserts that placeholder there.
…orm and prep are held to main's bytes

norm.metal's stream-row change kept every thread's D / TG elements (`mine[J][D / TG]`) on every path and read them
back by a runtime index, so the one-row decode norm (ROW 0) indexed a private array that grows as an M1 or M2 narrows
the threadgroup. ROW 0 now keeps the one element it writes, as main did, and ROW 1 keeps its elements by a loop of
constant trip count; STREAM_ROW takes a row only while a thread keeps at most four (`row_elems`, pre and mid's bound),
so a narrowed threadgroup gets the D / TG grid. Main's norm.metal and prep.metal are held as test-only sources:
the norm writes their bytes at 1, 8, 16 and 512 rows (both modes, with and without the router, f32 and bf16), and
the contiguous prep at 1 (log-scaled or not), 8, 16 and 512 rows on a sliding and a global layer.
… from float64 than the paths they replace

The prompt read's proofs compared relative_attention_nax with MLX's attention and its two bias arms with each other;
GATE_MM's compared it with an f32 CPU reference. Both are now measured against float64 beside the old path: the read
as served (in-read bias) against main's relattn_nax at 24 heads over 8, R 1,024, sliding 1,024 and global, 100 and
128 rows behind 1,100 keys and a global 128 rows at 16,384 keys, with a planted control, the projected bias printed
beside it; the gates against the GATE_MM=0 arm at 96, 100 and 128 rows, no farther in l2 and max where that arm's
matmuls are TF32 (NAX), within 1e-5 of the peak everywhere, with a planted control. The contract's global read
serves 9 rows at 16,384 keys.
… kv-off and 8-bit views

Under `--kv-quant 8` every prompt read takes the cache's dequantized bf16 view, and kv-off takes a strided view of the
cache's buffer; no test ran the changed reads on either. Through the SDK's KVCache (the keys before a chunk, then the
chunk), at the release's shapes, sliding 1,024 and global, 100 and 128 rows: on the kv-off view main's relattn_nax and
NAX_PREFILL's two bias arms write the bytes they write on contiguous K and V, and on the 8-bit view NAX_PREFILL's
read as served (in-read bias) is no farther from the float64 read of the view's values than main's read.
…projected-bias arm is removed

At 0, BIAS_IN_ATTN served a third read: relative_attention_nax over a bias projected and rounded to bf16 before the
read, where main's relattn_nax makes it in f32. That arm is removed with the code only it reached (relativeNaxTiles,
the kernel's BIA=0 branch and its template argument). The tensor-unit read now has one gate, `relnaxTakes` (both
levers on, tensor units, bf16 at head dim 128, 16 relative dims), which the read asks too, and every prompt it does
not take, either lever at 0 included, reads main's relattn_nax: the one fallback, in place of a hand gate beside it.
Test: with BIAS_IN_ATTN=0 a prompt read is main's bytes and the tensor-unit read does not engage; with it on it
engages. The flash-read test runs the in-read bias; the in-read against projected float64 test is gone with the arm.
…d arm's

The two arms round in a different order at the same precision. On an M5 Ultra at 96 rows GATE_MM measured l2
2.4% over the old arm and max 15% under, which the both-metrics-no-farther bar failed. The planted control still
fails the new bar.
…what M1 and M2 compile

The offline contract (metal-tt for M1 and M2) found both records the PR added stating 1024. prep_strided's
instantiations compile for 928 on both. relsplit_lanes' compile for 96 or more, and the bf16 tree read of one split at
5 rows of 4 lanes behind 30 keys for 64, under its 96-thread launch: recorded as 96 with that shape's cap at 64. The
kernel is dispatched only in a drafter's verify, and a drafter loads on Apple9+ only (plugin.draftsOn), so its launch
records min_gen 15 (first served on M3), the field the contract keeps for the families a kernel is dispatched on:
gate 5 checks it from M3, and the records stay what M1 and M2 compile. The planted control shares the lanes record and
now passes offline because that record is true (96 against its 512).
…ion class

A relative band between the two arms failed twice on one element: at 100 rows GATE_MM's max error was 8.1% over
the old TF32 arm's, at 96 rows 15% under. Both arms now sit within 1e-6 of the peak in max and 1e-6 x sqrt(n) x
peak in l2, GATE_MM within 2x of the old arm in each; the planted control stays outside.
@davidtai

Copy link
Copy Markdown
Contributor Author

Thanks for the numbers. The fix is one commit (16799f633), and it cherry-picks cleanly onto main, so I've opened it on its own as #1400. This PR keeps the same commit, so whichever lands first, the other merges without a conflict.

On the two open points:

  • reasoning_budget_tokens: Inkling's think markers are not single tokens, so the budget only caps what is delivered, not what is decoded. The log line says that. Bounding the decode needs the budget enforced inside the token loop, which is a separate change.
  • The 0.9 default: since 8dfc6126, Inkling 2 declares that it thinks by default, as its template's default effort is high. A client that wants no thinking has to send reasoning_effort: "none". That is intended.

@ddalcu

ddalcu commented Nov 30, 2026

Copy link
Copy Markdown
Owner

❌ 🔴 NEEDS WORK

🤖 MLXServe-PRBot — code review

Not validated: the PR adds to patches/ / scripts/build-mlx-patches.txt, so the shared MLX build is stale for it (MLX patch change: needs a fresh build-mlx.sh run, not validated locally). It is held from auto-merge until the maintainer builds and checks it.

  • The earlier static review of this head stands. The bot builds, tests and validates it once this is fixed.

Validated on M5 Max (36 GB), macOS 27.2.1, head 48f90fb0:

  • zig build check: not run (MLX patch change; lib/mlx is staged without it)
  • zig build lint / test: not run
  • merge with main: clean

Generated by Claude Code

Each loaded the bf16 release pack and ran two 3,300-row prompts.

- "a prompt's norm kernel at one threadgroup a row serves the same
  logits": the norm kernel byte tests hold the served row norm to main's
  norm bytes at the release's width (1, 8, 16 and 512 rows, routed and
  not, f32 and bf16), the kernel contract holds the row norm to the
  three-threadgroup norm's bytes (random and stress fills), and the
  pipeline-record test shows a prompt's rows launch the row kernel.
- "a prompt's reads with the in-read bias keep the top token": it
  asserted only the top token; the float64 distance tests at the
  release's shapes (contiguous and 8-bit cache views) are the read's
  precision bar, and the bit-for-bit test covers the reads it declines.

The test-only stream_row hook served only the first test and goes with it.

ddalcu commented Nov 30, 2026

Copy link
Copy Markdown
Owner

❌ 🔴 NEEDS WORK

🤖 MLXServe-PRBot — code review

The delta since 48f90fb0 is a clean merge of main 41fb3736 (no hand-resolved hunks; it includes #1400, whose commit this PR also carries) plus 382bab1e. That commit drops two release-pack tests:

  • The stream_row whole-forward test. It was the only bit-for-bit check of the row norm through a whole prompt forward. The coverage left is the norm kernel's byte tests at the release's widths, the kernel contract and the pipeline-record test. That holds for the kernel, but nothing now runs a whole release-pack prompt through the row norm against main's path. Say so in the body.
  • The relnax top-token test. It asserted only the top token. The float64 distance tests are the real bar, so its loss costs nothing.

The TestMain.stream_row seam goes with it.

Still blocking, unchanged since the last review: no non-NAX (M1-M4) run. gate_mm, prep_strided, stream_row and prefill_async have no device gate and run on every Apple GPU, with no switch back to main's path. That run is the gate.

No conflicts with main.


Generated by Claude Code

Each release-pack test opened its own 45 GB copy of the pack. The tests
now ask test_loads.hold for a load: the first test that asks opens it,
and a later test that asks with the same key takes the one held. The
key is the loader's type, the test's parts (the pack directory, dense
or 8-bit trunk) and every registered INKLING2 variable as it reads at
the ask, so a load made under one lever value never serves a test that
asks under another.

- One load is held at a time: an ask with another key frees the held
  load first, and a test that keeps its own load calls test_loads.drop
  before it opens one.
- A held load lives on the C allocator (std.testing.allocator checks
  each test for leaks) until the next ask with another key, a drop, or
  the process's exit.
- A table load taken from the slot gets its slots' drafter state back
  as a fresh load leaves it (Loaded.freshSlots: no open verify, every
  ring, context and calibration dropped), so a test that reuses a slot
  id never starts from another test's calibration.
- Own loads: the drafter's full-layer test (it switches spec.full and
  restores it), the TRUNK_Q8 bytes test (it reads trunkQ8Tensors, the
  last load's count), and the served prefix-cache test on INKLING2_PACK
  (its own engine load; it now drops the held load first).
- Order: the SwiGLU test moves next to the other dense-trunk tests and
  the TRUNK_Q8 bytes test moves after the 8-bit-head test, so each
  configuration's tests run back to back. No assertion changes.

INKLING2_RELEASE loads per binary go from 10 to 5 (own 2, dense 1,
8-bit 1, engine 1); INKLING2_DFLASH2_PACK loads go from 4 to 1.
@davidtai

Copy link
Copy Markdown
Contributor Author

Interim evidence for the non-NAX paths. This is not an M1–M4 run.

Setup. Both arms ran on an M5 Ultra with MLX_SERVE_DIAG=force-gpu-family-fallback=1, which makes mlx-serve report no NAX and take the pre-NAX GPU-family paths:

  • this PR at 48f90fb09;
  • main at c3390fd85.

MLX's own internal kernels may still use the M5's tensor units. So this run checks the portable code paths' correctness and their speed relative to main. It does not show M1–M4 timing or their threadgroup limits, so the tester's M1–M4 run is still the real check.

Since 48f90fb09, the head has changed only by merging main and by test-only changes: two redundant release tests were removed, and the release tests now share one pack load.

Paths that ran (serve logs):

  • No line in either arm names a NAX path.
  • This PR's portable paths engaged in 3 of 3 logs per cell: gate_mm, prefill_async, prep_strided and stream_row.
  • Main shows none of them, as expected.

Tests on 48f90fb09 with the fallback on: the inkling2 lane, ReleaseSafe, with the release pack: 368 passed, 23 skipped, 0 failed.

Standard cell (8-bit pack, p01/p14/p21 at about 22-23K tokens, 1,024 tokens, A B B A A B, spec on; average of 3):

Cell Metric main this PR Change
greedy prefill tok/s 2,873.6 2,919.4 +1.6% (3 of 3 prompts)
greedy decode tok/s 208.99 200.58 -4.0%
greedy tokens per round 4.68 4.45
greedy ms per spec round 22.37 22.17 B lower on 3 of 3 prompts
greedy peak GB 31.7 31.2
card prefill tok/s 2,871.0 2,913.9 +1.5% (3 of 3)
card decode tok/s 154.97 178.75 +15.3%
card tokens per round 3.49 4.02
card peak GB 31.7 31.3

Reading the cells:

  • Prefill: about 1.5% faster on every prompt in both cells. The larger prefill gains in this PR come from its NAX paths, which are off here.
  • Decode: the text differs on every prompt, because the PR's kernels change the rounding order. Decode tok/s therefore follows how many drafts each text happens to accept: greedy is -4.0% and card is +15.3%.
  • Per-round cost: with greedy decoding, each spec round costs the same or slightly less on this PR.
  • Conclusion: the non-NAX paths are correct, and on this machine they show no prefill or per-round regression.

@davidtai

davidtai commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Status for review:

  • The head d1b2023a3 merges main 41fb3736 and otherwise changes tests only, plus one helper the tests call (Loaded.freshSlots in plugin.zig). The body's known limits now say what the dropped stream_row whole-forward test covered, and what still covers the row norm.
  • The non-NAX result above comes from an M5 with the GPU-family fallback forced on.

The open gate is a run on a real M1-M4 Mac, and none of my machines is one. Could someone with an M1, M2, M3 or M4 Mac (48 GB or more for the 8-bit pack; peak is about 31 GB) run these on this branch and post the output?

scripts/build-mlx.sh                                  # this PR adds an MLX patch
zig build test -Doptimize=ReleaseSafe -Dtest-filter=inkling2
zig build -Doptimize=ReleaseFast

Then serve ddalcu/Inkling-2-Mini-MLX-8bit as you usually do, with MLX_SERVE_DIAG=prefill-trace set, and send one prompt of about 8,000 tokens with max_tokens 256. Please post:

  • the test totals;
  • every [inkling2] ... engaged line;
  • the [prefill-trace] line;
  • the prompt and decode tok/s.

The same request on main gives the baseline.

If the 8-bit pack is too large for the machine, the test line alone helps: the kernel tests run without a pack.

ddalcu commented Dec 1, 2026

Copy link
Copy Markdown
Owner

❌ 🔴 NEEDS WORK

🤖 MLXServe-PRBot — code review

The delta since 555f91b6 is d1b2023a. The release-pack tests now share one load per configuration through test_loads.zig:

  • hold keys a load by type, its parts and every INKLING2 variable's current value, so a test under another variable value never gets the wrong load.
  • One load is held at a time.
  • The load lives on the C allocator, outside the leak checker.

Non-blocking: nothing calls drop() after the last inkling2 test. The bf16 release pack, tens of GB, stays resident for the rest of the test binary, and any later test that loads its own model runs beside it. Drop it at the end of the inkling2 tests, or say in test_loads.zig that the env-gated release tests are meant to run alone.

Still blocking, unchanged: no non-NAX (M1-M4) run. gate_mm, prep_strided, stream_row and prefill_async have no device gate and no switch back to main's path, so that run is the gate.

No conflicts with main.


Generated by Claude Code

ddalcu commented Dec 1, 2026

Copy link
Copy Markdown
Owner

❌ 🔴 NEEDS WORK

🤖 MLXServe-PRBot — code review

The delta since d1b2023a is 97dbf807 and 46252be9. The net change makes the open and close methods on the shared-load openers pub in proof_test.zig and repro_test.zig. test_loads.zig comes out byte-identical: the second commit undoes the first one's edit to it. Tests only, no behaviour change.

The drop() note from the last review still stands, non-blocking.

Still blocking, unchanged: there is no non-NAX (M1-M4) run. gate_mm, prep_strided, stream_row and prefill_async have no device gate and no way back to main's path, so that run is the gate.

No conflicts with main (e9a3f220).


Generated by Claude Code

@davidtai

davidtai commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Gates on the head 46252be96 (main 41fb3736 merged), M5 Ultra:

Still open: an M1–M4 run (see the request above) and the maintainer's MLX patch build.

@ddalcu

ddalcu commented Dec 1, 2026

Copy link
Copy Markdown
Owner

❌ 🔴 NEEDS WORK

🤖 MLXServe-PRBot — code review

Not validated, same reason as before: it still adds patches/mlx-metal-alloc-fill.patch to scripts/build-mlx-patches.txt, so the shared MLX build is stale for it (MLX patch change: needs a fresh build-mlx.sh run, not validated locally). Held from auto-merge until the maintainer builds and checks it. The delta since the last review is a rebase onto main plus test commits; it merges cleanly with main.

Validated on M5 Max (36 GB), macOS 27.2.1, head 46252be9:

  • zig build check / lint / test: not run (MLX patch change; lib/mlx is staged without it)
  • merge with main: clean

Generated by Claude Code

…their own change

ddalcu#1330 no longer patches MLX. The async-against-sync eval point test stays and reads
the pool as it is.

ddalcu commented Dec 1, 2026

Copy link
Copy Markdown
Owner

❌ 🔴 NEEDS WORK

🤖 MLXServe-PRBot — code review

The delta since 46252be9 is a2e2422c. It drops patches/mlx-metal-alloc-fill.patch, its line in scripts/build-mlx-patches.txt, the mlx_serve_metal_alloc_fill / allocFill seam in src/mlx/ffi.zig, and the pool-fill test that used it. Nothing in the tree still references them. The async-eval test keeps its sync-vs-async comparison and loses only the fill arm. That clears the local bot's blocker, the MLX patch that needed a fresh build-mlx.sh.

Still blocking, unchanged: no non-NAX (M1-M4) run. gate_mm, prep_strided, stream_row and prefill_async have no device gate and no way back to main's path, so that run is the gate.

No conflicts with main 7f563a0a.


Generated by Claude Code

@ddalcu

ddalcu commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

❌ 🔴 NEEDS WORK

🤖 MLXServe-PRBot — code review

The code builds and the tests pass here and on an M1. It still can't land, for two reasons:

  • No non-NAX perf numbers from the author. gate_mm, prep_strided, stream_row and prefill_async have no device gate and no fallback to main's path. Our M1 run below proves they are correct on non-NAX. It does not prove they are no slower there, and that proof has to come from you: a main-vs-branch table on an M1-M4 for the claimed cells.
  • Regression gate not run: there is no Inkling 2 pack on this machine, so the speedups in the body are unreproduced here.

Validated on M5 Max (36 GB), macOS 27.2.1, head a2e2422c:

  • zig build check: pass (21 s)
  • zig build lint: pass
  • zig build test -Dtest-filter=inkling2: pass, 208/226 (18 skipped), 693 s
  • zig build test (full): 5866/6299 passed, 432 skipped, 1 failed. The failure is disk_tier volumeSpace, which fails the same way on main (environmental), so it is not this PR. 48 min.
  • M1 8 GB (non-NAX), Debug, -Dtest-filter=inkling2:
    • main 7f563a0a: 183/198 passed.
    • head: 197/226 passed. The new gate_mm (f32 and bf16) and gate kernels pass their contracts. The 10 contract FAIL lines are all planted controls that go red as designed. There is no new threadgroup warning.
  • red-on-revert: not forced. The tests are inline with the kernels and plugin code they cover.
  • regression gate: not run (no Inkling 2 pack on disk)

Generated by Claude Code

prep_strided, gate_mm, stream_row and prefill_async now ask
verifyQmmNaxAvailable(), the device check the row map and the tensor-unit
read already use. A GPU without NAX serves a prompt on main's path, byte for
byte. Tests that assert one of these paths engages skip off NAX, the
contract checks the tiled gates' and row norm's wrappers only on NAX, and a
new proof forces the GPU-family fallback and checks that no prompt path
engages and that the logits equal main's path (kernels.test_main gains
gate_mm, prep_strided and stream_row).
@davidtai

davidtai commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the M1 run. That answers correctness off NAX.

1. Non-NAX speed. The head 405e80aa9 (after the head you validated) gates gate_mm, prep_strided, stream_row and prefill_async on verifyQmmNaxAvailable(), the same check the tensor-unit paths use. Off NAX, a prompt takes main's path for all four, so an M1-M4 Mac runs main's code for them, with no change to its speed.

  • A new test, inkling2 proof: off NAX a prompt takes main's path, byte for byte, forces the fallback on an M5. It checks that none of the four paths (nor the row map) engages, and that the logits equal main's path byte for byte.
  • The tests that assert these paths engage now skip off NAX.
  • CI is green on 405e80aa9. On the M5 Ultra, with the release pack, the inkling2 lane passed 320 / 3 / 0, the new off-NAX test included. The full suite failed only on volumeSpace and the 4 media crashes main shows on the same machine, and lint passed.

2. Regression gate. It needs the 8-bit pack ddalcu/Inkling-2-Mini-MLX-8bit. Every cell in the body is THE standard cell: p01/p14/p21, A B B A A B, greedy and card, against main. A machine with the pack can reproduce them.

ddalcu commented Dec 1, 2026

Copy link
Copy Markdown
Owner

✅ 🟢 APPROVED

🤖 MLXServe-PRBot approved — reviewed at head 405e80aa, no issues found.

The delta since a2e2422c is 405e80aa, and it closes the non-NAX blocker the right way: M1-M4 no longer run the new prompt paths at all.

  • streamRow (kernels.zig:586), the tiled gates in gateAt (kernels.zig:698), the strided prep (kernels.zig:887) and prefillAsync (plugin.zig:1602) now also ask verifyQmmNaxAvailable(), the same gate the row map and the tensor-unit read already use. Off NAX, a prompt takes main's kernels and main's synchronous eval points.
  • TestMain gains gate_mm, prep_strided and stream_row, so each path can be forced back to main's by name.
  • The proof off NAX a prompt takes main's path, byte for byte sets vqmm_nax_probe_override = false and restores it afterwards. It checks that none of the four paths engages and that the logits equal main's. verifyQmmNaxAvailable reads the override before its cache, so the forced fallback is real.
  • The tests and contract cases that assert these paths engage now skip off NAX, instead of failing there.

No non-NAX speed claim is left to prove: those Macs run main's code. The perf table only has to cover NAX. No conflicts with main 7f563a0a.

Static review only — merge waits for the local PRBot's build/test validation.


Generated by Claude Code

@ddalcu ddalcu added Approved and removed NeedsWork labels Dec 1, 2026 — with Claude
@ddalcu

ddalcu commented Dec 1, 2026

Copy link
Copy Markdown
Owner

✅ 🟢 APPROVED

🤖 MLXServe-PRBot approved — reviewed at head 405e80aa, no issues found.

The delta since a2e2422c gates gate_mm, prep_strided, stream_row and prefill_async on verifyQmmNaxAvailable(). M1-M4 serve a prompt on main's path, so the non-NAX blocker is gone, and an M1 run below confirms it natively.

Validated on M5 Max (36 GB), macOS 27.2.1, head 405e80aa:

  • zig build check: pass (34 s)
  • zig build lint: pass
  • off NAX a prompt takes main's path, byte for byte with the fallback forced: pass
  • -Dtest-filter=inkling2: pass, 209/227 (18 skipped); all 13 contracts pass
  • zig build test, full: 5867 passed, 432 skipped, 1 failed (67 min). The failure is disk_tier volumeSpace, which fails on main the same way (environmental).
  • M1 8 GB (native non-NAX), Debug:
    • -Dtest-filter=inkling2: pass, 191/227 (36 skipped). The extra skips are the NAX-gated tests.
    • The off-NAX proof runs on the real GPU (0 skipped) and passes byte for byte.
    • The 10 contract FAIL lines are all planted controls, and there is no new threadgroup warning.
  • red-on-revert: not separable. The tests are inline with the paths they gate.
  • regression gate: not run. There is no Inkling 2 pack on this machine, so the M5 prompt speedups in the body are unreproduced here. This is partial.

Generated by Claude Code

davidtai added a commit to davidtai/mlx-serve that referenced this pull request Dec 1, 2026
…#1330 + ddalcu#1401 + ddalcu#1402) for acceptance

The one conflict is plugins/inkling2/kernels.zig's all_kernels list: the union of
ddalcu#1401's DFlash2 heads and conv-norm kernels and ddalcu#1402's PF_INT8 kernels.
@davidtai

davidtai commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing in favour of #1401 (#1401), so that one PR gets the review, as the review on #1401 asked.

#1401's head contains every commit of this PR (head 405e80aa9), unchanged. This PR's description stays the record of its own measurements: the standard cells and sweeps against main, EvalPlus, and the offline M1/M2 kernel-contract check (no M1-M4 Mac has run it). #1401's description covers the combined head. Like this PR, #1401 merges after #1256, and its NAX includes move to TurboNAX once #1256 lands.

@davidtai davidtai closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants