Repository navigation
Metal: experimental Inkling 2 Mini text, vision and bundled DSpark - #4337
BlivionIaG wants to merge 108 commits into
Conversation
f110093 to
f3a6a99
Compare
- Preserve the original release NVFP4 and MXFP8 expert weights and execute the looped text backbone on one Metal device. - Keep the bundled DSpark head and plain prompt-cache reuse in the native lane backend. - Refs ashhart#4274. Local M4 Pro evaluation, separate from the upstream full port.
- Keep the original vision tower, PNG/JPEG preparation, and the separate device and operator checks on the full integration branch. - The padded-image real-weight accuracy gate remains open. This commit is not part of the text-only review branch.
- Match pinned Transformers eager QK and scaling boundaries before FP32 softmax. - Keep the trained padded-image projector bound unchanged.
- Keep original NVFP4/MXFP8 checkpoint bytes and decode weights in registers, using BF16 activations and FP32 sums. - Match pinned Transformers conversion and SwiGLU/route precision, with packed-weight and zero-scale controls. - Refs ashhart#4274. Local original-weight M4 Pro qualification; not an upstream submission.
- Keep the shader and probe comments within the repository lean rules; no arithmetic changes.
f3a6a99 to
82e7aa0
Compare
|
Review at This covers a lot of the plan: H1, H2 and H4 fully; most of H3, written as a Metal contract rather than a backend-neutral host spec; and M1-M7. M8 (the served receipt) is missing, and so is an M5 prompt path. Visits and taps check out: 5→L5 pass 0, 23→L11 pass 1, 41→L17 pass 2, and 48 after the final norm, with one cache slot per visit. The bank-then-restart order is right, and the SwiGLU sigmoid is taken on the uncapped gate, as in the CUDA code. Decision needed (@ashhart)
CI
Shared core
Coverage and refusals
Nits
|
- The rebase dropped the alias main uses for slide refusal, so the native server did not compile.
|
Device run on an M3 Pro (36 GB, no tensor units, so the pre-M5 path) at
There's no standard-server baseline on this Mac yet, so these numbers make no speed-bar claim. A llama.cpp row on the same machine is next. |
|
Speed rows from the same M3 Pro (36 GB, pre-M5) at
This chip has no tensor units, so it can't show what M1's M5 prompt path or the planned M5 rows will do. |
…-ups - Comments are one line each again (339 runs collapsed, 40 shortened) and no `/*` text remains, so lean_check.py adds nothing to the base's 168 problems. - TF_INKLING2_MINI_SMOKE reads through platform/environment.zig: a .metal/.path row, a docs row and a valid case in environment_test.zig. - The load check sums every model*.safetensors shard, as core/checkpoint.zig lists them, plus mtp.safetensors when drafted. - The state-bytes test covers Mini's looped shape: 24 physical layers as 48 visits, 8 global, visit 41 at physical 17. - A new contract control isolates the experts' down projections; --loops and --policy refusals have a test that names them. - The cacheBudget doc comment and the CHANGELOG state the DSpark prompt-cache limit: kept states need --no-drafts. - The Inkling 2 contract suites move to metal_inkling2_main.zig, holding their probes for the run, which keeps metal_main.zig under 600 lines. - The NVFP4 outer factor stays the unrounded quotient, pending the maintainer's F1 decision.
|
Follow-ups from the review are on
|
…ites - `zig fmt --check build.zig zig` (what the Zig format workflow runs) is clean; the new suites and loaders had drifted. - Layout and `@intFromEnum` -> `@backingInt` only: the contract, native, vision, forward and environment checks are rerun green on this tree.
|
Point-by-point on the review, head F1, the NVFP4 factor — maintainer decision, not chosen here. No code change. F2, lean rules — cleared. 383 new problems against the base, now 0:
Shared core / refactors (deferred, not ours to land here). Moving Coverage and refusals.
Nits.
Local results on this head (M-series,
CI on |
|
Thanks for the device rows and the llama.cpp comparison. Recorded plainly: on the M3 Pro the agreed bar is not met — plain decode 12.5 vs 18.6 tok/s at c=1 (0.67×), DSpark 0.78×, and c=4 plain 0.74× (24.6 vs 33.2) — so this stays a draft and I am not claiming a pass. The admission observation is tracked as open, not fixed: the DSpark server serializes c=4 under memory pressure even with 72% free, and the per-visit state is whole buffers per pass (F7), so the admission check needs to account for that state rather than only OS pressure; I have not changed it here because it needs a 36 GB machine to reproduce and measure. Token equality between plain and DSpark at c=1 and c=4 is noted as the useful part of those runs. F1 remains the maintainer's decision. |
|
@BlivionIaG, a profile of
So it is neither launch- nor CPU-bound. The trace records no per-shader samples on this chip, so a local phase timer split plain c=1 (the token hash was unchanged with the timer in):
Receipts, traces and the phase-timer patch are kept locally. |
|
M5 Ultra run of
|
|
@SashaMIT, thanks for the M5 Ultra run of The vision failure is real and only an M5 can show it. The 129-row token file is not in the branch and I will not invent it. The receipt that was hashed is 129 rows by 200058 FP32 logits, equal across a 128-row chunk and a 32-row chunk, SHA256 @jschmied, the profile is the useful part. Plain c=1 is 99.4% GPU busy, 1.00 command buffer per token, so it is not launch-bound or CPU-bound. The attention block is 64% of GPU time at 47 GB/s, against 133 GB/s on the unembedding. The experts are not the gap. I am not going to rewrite them for speed on this draft. A fused GEMV for the projections that share an input is M1, which I asked for on #4274 and will not open until that claim is confirmed. Admission: no 36 GB machine here, so I will not land a state-bytes check I cannot measure. Your note that the warning can arrive before or after admission, and that this machine can test a fix, is the reproduction. When a patch exists it goes on the draft for that run, not in ahead of it. F1 is still @ashhart's decision. No change. |
…w projections - Score GEMMs are a full fp32 dot, off the tensor-unit operand cut, so an M5 matches the product measured on earlier chips. - One-row projections that share an input use one launch of the existing matvec lane chains. Same checkpoint token hash, about 2 ms off a 57 ms decode token.
|
@SashaMIT, the Same head, stage split of one decode token, 22-token context, GPU time, cache off. Token hash
The attention kernel is not the gap on this chip. Fusing the one-row projections that share an input, with the same lane chains as the existing matvec, saved about 2 ms and did not change the hash. It does not meet the 25.26 bar. The two mix calls are about half the token, and rewriting that kernel's register use did not move them, so that rewrite is not in the tree. |
|
M5 Ultra retest of
|
- zig fmt on the forward layer, and the score-GEMM note is one line so lean check stays at the base count.
- Drop the blank lines zig fmt --check rejected on the projection fuse.
|
@SashaMIT, recorded. The contract gap is real.
|
- f32_nt and f32_nn were filled from bf16 dyadics, so a 10-bit operand cut still matched the float64 product. - Wide inputs now set the low fraction bits. On this M4 Pro the gates pass at 0.337 and 0.354 of the bound.
…metal-4bit # Conflicts: # CHANGELOG.md
# Conflicts: # docs/receipts/inkling2-mini-m4pro/SHA256SUMS
…etal 4 prompt queue - The recipe gains the decode token's bytes against its floor, the two byte-equal attempts that did not pay and the fusion estimate. - Three decoding streams with a cold 4,096-token prompt arriving, A-B-B-A: the Metal 4 prompt queue is not worse for them, same prompt hash. - The receipt gains mixed_load.py and its output.
|
Another measured prompt-speed step on this branch (head
The MLX comparison table in the description predates this; I will re-run the sweep and update it. |
….75 to 0.83 of its rate - Quiet machine, native then MLX, one run per size; native 5.18 / 21.59 / 97.05 / 225.97 s, MLX 4.32 / 17.04 / 75.55 / 169.70 s at 2,048 / 8,192 / 32,768 / 65,536 tokens. - The recipe, the ledger and known-issues carry the new ratio; the receipt gains the raw JSON and server logs.
- q k^T's epilogue stores bf16(bf16(sum) * scale), the softmax reads and writes bf16 with the same max, exps and sum order, p v reads the bf16 probabilities. - Every value the score matrix held between the kernels was already a bf16 number, so the bytes are the same and the DRAM traffic of the softmax (at its fp32 floor) halves. - The gemm kinds f32_nt / f32_nn become score_nt / prob_nn; the softmax probe takes bf16 scores; a planted control drops the score scale (134 controls).
- Recipe rows, receipt README and SHA256SUMS, the softmax/bf16-score receipt (bench harness, A-B-B-A, tower hashes, contract totals), CHANGELOG.
…le control, the tower's init kinds - Completes the previous commit: records for score_nt / prob_nn, the suite registers the control that drops the score scale, the tower loads the renamed kinds.
…logs) and its checksums - img-sm-* and hash-sm-* files named in the receipt README; SHA256SUMS regenerated (shasum -a 256 -c passes).
…metal-4bit # Conflicts: # CHANGELOG.md
|
One more measured step on the image path (head
What is left in the invoice's 6.5 s is about 3.7 s of text prefill and about 2.8 s of tower. |
…metal-4bit # Conflicts: # CHANGELOG.md
…and a byte-equal rewrite that stays a tie - A visit at 31,744 keys runs at 3.47 TFLOP/s; the score phase's operand preparation is the excess. - A byte-equal variant ran the visit in 0.82 of the time (about 2.5 % of the 32K first token) and was not applied.
…metal-4bit # Conflicts: # CHANGELOG.md
…metal-4bit # Conflicts: # CHANGELOG.md
…metal-4bit # Conflicts: # CHANGELOG.md
… a drafted request resumes it - The head has no recurrence, but its K/V at a position come from the target tap rows, which a kept state does not hold. So the head context is copied beside the lane snapshot: the global layer for all positions (4 KiB each) and the two sliding layers' last 1,024 (8 MiB); about 7 % more per state at 3,000 tokens. The last feature row is not kept. - A kept state with no head (a "draft": false stream, a warm-pass end) resumes a drafted request with the head starting past the prefix: same tokens, fewer accepted drafts. - --prompt-cache-gib with DSpark is accepted; the default budget with drafts is half the room, as on plain servers. - Tests: adapter save/restore equals the source head (past the 1,152 ring, pending rows drained); on the real checkpoint a resumed drafted stream equals a fresh one in tokens and draft counters, greedy and seeded, and equals draft:false. Without the head restore the real-checkpoint test fails (expected 17, found 16 drafted); without the lane copy the unit test fails on the drafted tokens.
…ken, decode, concurrency) and clients - Raw results behind docs/receipts/inkling2-mini-m4pro/drafted-resume/summary.txt, the recipe's Kept prompt states section and the first commit's CHANGELOG, Limits and known-issues text.
…metal-4bit # Conflicts: # CHANGELOG.md # zig/src/platform/environment.zig
…metal-4bit # Conflicts: # CHANGELOG.md
…metal-4bit # Conflicts: # CHANGELOG.md # docs/optimization-ledger.md
- The merge of main left the table twice (ours with the ink2 column, main's without); main's row 39 is added to ours.
|
CI result for |
|
@BlivionIaG, the rerun with #4744 on the M5 Ultra. Yes, it recovers here too, and DSpark now wins at four code streams. Base is this branch at
|
|
@SashaMIT thank you, that is exactly the check I wanted: independent hardware, a fresh server per block, |
Serve the original
thinkingmachines/Inkling-2-Minicheckpoint on native TensorFold Metal, with text, PNG/JPEG vision and the bundled DSpark head. Packed NVFP4/MXFP8 expert weights stay packed; kernels decode them to BF16 in registers, use BF16 activations and sum in FP32.Before:
maindoes not serveinkling2_loopon Metal. After: this branch serves the original checkpoint, includingmtp.safetensors, and accepts images. Experimental, M4-class chips; not a release-support claim.main(merged in, no rebase). Head37f8b61c03. Mergeable. The maintainers' separate Metal line (Inkling 2 Mini on CUDA and Metal #4387) and its stack are a different implementation of the same model; Inkling 2 Mini on Metal: prompt experts, projections and loop gates on simdgroup matrices without tensor units (stacked on #4618) #4756 (on Inkling 2 Mini on Metal: a round's logits in one pass of the vocabulary (one drafted stream 106 to 123 tok/s, four streams 237 to 281) #4618), Inkling 2 Mini on Metal: images under --vision (the tower, the processor and its contract) #4704 and Inkling 2 Mini on Metal: the startup line reports the demand of the asked streams (no change to admission) #4705 carry this PR's M4-class kernels, vision and admission onto that line. The order in which these land is the maintainer's call.atc overlap --jsonon9a255bb79eagainstmain: incomplete (it hit its own limits). Reported conflicts: qwen27 Metal: DSpine drafter for Qwen3.8-27B, opt-in #2634 (docs/environment.md, two qwen27 files), qwen27 Metal: K and V read in place from the mixed projection, no unstack copies (#2940 step 1) #2945, qwen27 Metal: one q27_qk_norm_rope dispatch for Q and K head norm and RoPE (#2940 step 2a) #2955 and qwen27 Metal (M5): fused norm and RoPE write K and V into the cache and Q into qa directly (#2940 step 2b) #2960 (zig/tests/contract/metal_limits.zig,metal_main.zig: contract registrations that both sides add). Test-merged withgit merge-tree; whichever lands second resolves them. Nothing here touches Qwen code.What it contains
docs/recipes/inkling-2-mini-metal.md), supported-models row, kernel-contract, vision and known-issues entries, optimization-ledger cells, and the raw receipts indocs/receipts/inkling2-mini-m4pro/.Shared-core edits (maintainers' call)
core/memory_pressure.zigandcore/lane_host_pressure.zig:Governor.hold_from,streamsFitandChange.hold_from, with tests. The default for every other family is unchanged. Admission counts the weights, scratch and each stream's state bytes and no longer serializes streams that fit under awarninglevel.core/contract/registry_joins.zig: four Metal record joins.native/metal.zigand the build files: registration of the family, andmetal4 = true(the Metal 4 queue is compiled in).platform/environment.zig: the wording of the existingTF_METAL4rule now also covers Inkling 2 Mini's prompt chunks.deepseek_v41/metal/mv*.zigimported family to family, a third vision tower invision.metal,loop_mixagainstattn_res,gemm_outagainstgemm_nax, a third E4M3 decode,core/modelopt*andkv_poolunused, a fourth visit plan (plan.zig). I would do these in a follow-up core PR if the maintainer wants them, or now if the maintainer rules.fmain the expert multiply-add and a changed prompt-chunk sum order (both measured to change bits, so neither is applied).Checks on this head
37f8b61c03.python3 tools/zig/lean_check.py: 165 problems on the base, 165 on this head, 0 new.python3 tools/pr_check.py --base upstream/main --pr 4337: 0 errors, 0 warnings.zig fmt --check build.zig zig: clean.zig build test-inkling2-hostpasses on this head;test-inkling2-media-metal79 passed, 9 skipped (the JPEG tests, for want of the pinned libjpeg-turbo release) at05b6fdb5c0;zig build test-server-cpu1841 passed, 15 skipped at3682b31cfc(it includes the audio-refusal test);zig build dev-toolsbuilds. The onetest-kernel-contractfailure (registry.zig:456, CUDAinkling2_modeloptentries) fails the same way on the maintainers' stack without this PR.e4259ce0e4hadfmt,pytest,zig-macos-dev-toolsand the other quick checks green, and I will report eachzigjob that fails and whether this change caused it.zig build test test-golden(15-minute timeout locally, not a pass); a task-accuracy quality suite; M1, M2; a 36 GB Mac on this head; the M5 tensor-unit prompt path (not written).Receipt
Raw results, the prompt-token generator, hashes and the build SHA-256 are in
docs/receipts/inkling2-mini-m4pro/; its README says which file each number comes from and at which build. Decode, cold-prompt and footprint numbers were taken on the round-three build (a0935b5279), the concurrency table on the build that became05b6fdb5c0; the head differs from those by main merges and documentation only.maindoes not serve this model on Metal. The same-machine reference ismlx_lm.server(mlx 0.32.4, mlx-lm0.1.dev1006+g0c4c99192, same checkpoint, no drafter).9a255bb79e, @SashaMIT); M3 Pro 36 GB (earlier head, @jschmied). Linux and CUDA: not touched.TF_METAL4(default on for DeepSeek-V4.1) now also sends Inkling 2 Mini's prompt chunks of 64 rows or more through a Metal 4 queue on macOS 26 and later (TF_METAL4=0keeps Metal 3; a Mac without it falls back).TF_INKLING2_MINI_SMOKEis test-only and documented indocs/environment.md. No profile row.ed40e7da625f594fc9c4990f5f66be24873c22d7plus itsmtp.safetensors;-Dcpu=apple_m1 -Doptimize=ReleaseFast. An unrelated CPU job used about 60 % of a core in the decode and cold runs, so read ratios.sha=, chat completions at--context 8192)0b037128ee78,b37d8a0e39c4,77bf7c99cc66,538175732cc7, identical across the round-three and round-four builds;bench_concurrent --alone --serialdrafted four streams: 30 of 30 replies equal to their solo runs, 4 of 4 equal to"draft": false. Sampled (temperature 0.7, seed 1234): 30 of 30 and 4 of 4 equal, 467 and 447 drafts accepted. On the maintainers' stack at232ee08a39and Inkling 2 Mini on Metal: a prompt's experts, projections and loop gates on simdgroup matrices where the GPU has no tensor units, bit for bit #4703's head the same prompts give the same hashes (the 416-token one,77bf7c99cc66, matches across the two independent implementations).bench_openai.py --tokens 256 --reps 3 --temperatures 0: MLX 23.05 / 23.69, native plain 31.12 / 31.07, native DSpark 35.76 / 35.01 tok/s (fibonacci-raw/gpu-chat-no-think).bench_concurrent, A-B-B-A, native plain / DSpark aggregate: code 67.0 / 65.1, chat 66.8 / 66.9; one stream 31.1 / 37.7 and 30.9 / 35.8. MLX answers four requests one after another (23.3), so its four-stream row is not a same-width comparison./v1/completions, exact ids, cache off), on the Metal 4 build4418225fb6with the dense prompt tile, quiet machine (load average 2 to 3), native then MLX, one fresh server and one run per size (not interleaved): MLX 4.32 s (474 tok/s) / 17.04 s (481) / 75.55 s (434) / 169.70 s (386) against native 5.18 s (395) / 21.59 s (380) / 97.05 s (338) / 225.97 s (290) at 2,048 / 8,192 / 32,768 / 65,536 tokens, so native runs at 0.83 / 0.79 / 0.78 / 0.75 of MLX's rate. The round-three session had 0.85 / 0.87 / 0.75 / 0.72 (native 5.49 / 22.53 / 108.27 / 249.21 s against MLX 4.68 / 19.53 / 81.74 / 180.27 s); MLX was slower there and the cause was not isolated. The dense projection tile took the first token from 23.8 s to 22.7 s at 8,192 tokens and from 104.8 s to 102.0 s at 32,768 (A-B-B-A, idle machine, same hashes). Sending the prompt chunks through a Metal 4 queue (same kernels, arguments and order) took it another 10 % off in an A-B-B-A on plain servers: 8,192 tokens 25.2 / 24.9 s to 22.5 / 22.3 s, 32,768 tokens 115.6 / 116.6 s to 105.4 / 102.4 s (an earlier loaded session gave 15 to 17 %; samesha=on all runs, the four chat hashes, DSpark with four streams and a prompt in flight, contract 86 kernels / 133 controls red; with three decode streams running and a cold 4,096-token prompt arriving the Metal 4 queue was not worse for them). A 512-row chunk's GPU time by family is in the recipe: the routed experts are 857 ms of 1,281 at the start of a prompt. The speed bar for prompts is not met.57de097873; receiptfidelity/.--vision, PNG and JPEG): native reads the same text, chart values, shapes and scene asmlx_lm.server. The tower's two fp32 attention dots (q.k^T and p.v) were 89 % of a 12.5 s tower on the 1,561-token invoice (one thread per output); they now run 64 x 64 tiles through threadgroup memory with each output's fma chain over k unchanged (bytes equal: the tower's output hash on 14 image requests, 16 identical replies per image, the four text hashes). First token, A-B-B-A on a quiet M4 Pro: 546-token scene 2.95 to 3.35 s before, 1.94 to 2.33 s after (MLX 1.7 s); 1,561-token invoice 15.7 to 16.2 s before, 6.9 to 7.2 s after (MLX 4.7 to 4.8 s). The small images were not re-measured quiet. The score matrix between q.k^T, the softmax and p.v then moved to bf16 (every value it held was already a bf16 number; the softmax was at 1.06 to 1.10 times its bandwidth floor, so halving its bytes was the lever; same max, exps and sum order, each p.v output still one fma chain): invoice first token 6.94 s to 6.54 s (A-B-B-A, load 2.9, 5.8 %; the scene 1.96 to 1.93 s is inside the noise), tower output hash, every reply and the four text hashes equal, standalone bitwise comparison on 7 ragged and full shapes, contract 86 kernels / 134 controls red / 0 missed (one planted control added). About 2.8 s of the 6.5 s is the tower and about 3.7 s is text prefill.docs/receipts/inkling2-mini-m4pro/decode_depth.py): native 28.5 / 28.4 / 25.8 / 23.2 tok/s against MLX 23.0 / 22.6 / 20.0 / 17.8 at 2,048 / 8,192 / 32,768 / 65,536 tokens (1.24 to 1.30 times). Native's growth from 2K to 65K is 8.0 ms a token, within the 8 global visits' K and V bandwidth floor (0.131 ms per 1,000 tokens at 250 GB/s); an A-B-B-A pass for 2K to 32K, the 65K rows later; the machine was loaded (load average 4.5 to 6.3).mtp.safetensors(Apache-2.0, as in docs: a plan for Inkling 2 Mini on CUDA and Metal in claimable slices #4274).Kernel contract
SUMMARYon this head, M4 Pro:SUMMARY 86 kernels: 86 pass gates 1-4, 0 fail, 0 known findings; 134 controls: 134 red as planted, 0 missed; 0 limit problems, exit 0 (the bf16 score matrix of the image tower added one planted control to the earlier 133). On earlier heads: the same 86 kernels and 132 controls (before the dense tile's added control) on an M4 Max ate6cb02e09e(@akol1). An M5 Ultra (@SashaMIT) at9a255bb79e: 86 pass, 132 controls red, 0 missed, 0 limit problems; it counts one control fewer than the M4 chips because the media suite plants thebf16_ntrow control only on chips without tensor units.The agreed gate (#4274,
docs/design/inkling-2-mini.md), item by itemSUMMARY, every planted control red, on the chips namedtf-kernel-contract --only inkling2: 86 kernels pass gates 1-4, 134 controls red, 0 missed, 0 limit problems on an M4 Pro (this head); the same kernels with 132 controls on an M4 Max (@akol1) and an M5 Ultra (@SashaMIT, one control fewer by design: thebf16_ntrow control is planted only without tensor units)."draft": false, concurrent equals solobench_concurrent --alone --serialgreedy on the DSpark build, 30 replies equal to their runs alone and 4 equal to"draft": false, 0 unequal; sampled (T 0.7, seeded), plain and DSpark,--aloneand--serialall equal, 0 unequal (sampled-*.out). I did not run the tiny checkpoint for this table.--parallel 4, greedy and seeded 0.7, 37 resumed past the 1,024-token window), drafted with the cache equals plain cold in 56 of 56 requests; drafted cold equals plain cold in 28 of 28;bench_concurrent --alone --serialon that server 40 alone and 20 serial equal, 0 unequal (drafted-resume/summary.txt). With the drafter on the default cache budget is now half the room, as on plain servers (it was 0;cacheBudget, one line). Not covered: images with drafts and the cache, and warm-pass-end keeps, which resume with the same tokens and fewer accepted drafts. I could not repeat the served resume on the merged head: the machine reported memory pressure from other jobs and the server then keeps no new states, by design.mlx-lm) on the original checkpoint: top-1 equal at 1,762 of 1,792 positions (98.33 %), all 30 differences near ties with their margins in the receipt (fidelity/compare.txt). The tower against Transformers6173a2f6BF16 eager (83 of 83) and the public fixture (20 completion ids of 20) are carried from the first version. The language model was not compared against huggingface/transformers#51050 here [INFERENCE: a BF16 reference of this size does not fit 48 GiB].is_varloop,--loops, audio parts, images before the vision slice, each with a test--vision).Checklist
TF_INKLING2_MINI_SMOKE; the JPEG tests skip without the pinned libjpeg-turbo release).