Repository navigation
Inkling 2 Mini on Metal: routed experts on the M5 tensor units at every width (16 rows 49 to 36 ms, 64 rows 138 to 84 ms) - #4523
Draft
sethforprivacy wants to merge 35 commits into
Conversation
Derive per-visit cache access and exact arithmetic for the 48 visits so CUDA admission and kernels have a reference before serving is enabled.
Decode stored NVFP4 and MXFP8 expert weights to BF16 and launch them beside the grouped expert/vision kernels, with exact tensor baselines and planted faults.
Launch cross-pass messages, rank-64 gates, residual steps and split QKV with FP32 reductions, BF16 rounding controls and per-launch resource records.
Run all 48 visits with per-visit cache state, prompt snapshots and exact rollback. Refuse TP, vision and DSpark loading until those engines exist.
… rows where prep wrote them
…in the fewest 1,024-key folds a slot
…up to 32 rows is one launch
8 tasks done
…mdgroup folds the partial sums itself
This was referenced Nov 22, 2026
This was referenced Nov 22, 2026
5 of 6 tasks
8 tasks done
4 of 5 tasks
ashhart
force-pushed
the
lead/inkling2-mini
branch
4 times, most recently
from
November 24, 2026 09:43
aefb063 to
c41911e
Compare
Owner
|
Sorry for the noise: this was closed automatically when #4387 landed on main and its base branch was removed. It is reopened and now targets
|
17 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update: head
55de80afd(three commits carried from #4448)The branch now carries #4448's three later commits (the sixteen-wide greedy pick, the depth mix and the combine; here
dffe4700a,ee3323711and55de80afd), so the comparison below is against #4448 atcca30e890. This pull request's own commit is stillee248f9e3.GPU time of one forward, cache empty, single forwards at each width:
cca30e890Served on the whole stack (#4447, #4465 at
db534d6cfand this head), TensorFold's clients, 256 tokens, greedy, three reps: plain 59.5 and 59.9 tok/s on the two prompts and 182.8 and 181.6 in total at four streams; with the drafter 100.4 and 79.3, and 237.8 and 189.1 at four streams. oMLX 0.8.1 on the chat prompt, same client: 72.5 with its drafter and 54.9 without, 126.6 at four streams. 12 of 12 replies equal their solo runs, plain and drafted. A 45K-token prompt: 702 tok/s.Checks on this head:
zig build nativecompiles; the six Inkling host steps exit 0;tf-kernel-contract --only inkling2:SUMMARY 45 kernels: 45 pass gates 1-4, 0 fail, 0 known findings; 45 controls: 45 red as planted, 0 missed; 0 limit problems, exit 0;zig fmt --checkandgit diff --checkclean; lean 167 on the base and 167 here, 0 new.What this changes
Before: Mini's routed experts run on register kernels at every width, and each row pays for its own eight experts: a 16-row round takes 49 ms of GPU time and a 64-row prompt chunk 138 ms, 85 ms of it in the experts. After: on a GPU with tensor units the gate-up and down products run on them at every width, 1 row to 64: 16 rows take 36 ms and 64 rows 84 ms. One row takes 17.4 ms where it took 16.1, so one plain stream is slower; that is the trade, and the numbers are below.
This is a proposal on top of #4387, opened as a draft.
3e0e9bcb83, then Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo #4446 and Inkling 2 Mini on Metal: experts, gates, router, depth mix, combine, row batching, attention chunks and a concurrent forward (1,159 to 14 ms a row on M5 Ultra) #4448 (d87e8695d). This pull request's own commit isee248f9e3.atc overlap --json: not run; ATC is not installed on the machine that pushes.The kernels (
experts_units.metal, afternax.hand the M3 decode helpers).tf_ink2_grouplists each expert's route pairs, as it already does for the grouped kernels. Thentf_ink2_nvfp4_gu_units,tf_ink2_nvfp4_down_unitsand their MXFP8 twins: a threadgroup is 32 weight rows of one expert against that expert's pairs, 16 pairs a band. Each of its eight simdgroups takes one eighth of the columns, 16 columns an op, throughnax.h's 16x32x16 fragments with BF16 operands and FP32 sums (units.metalbuilds the descriptor without relaxed precision); the eight partial sums are then added in order. The weights are decoded in registers exactly as the M3 kernels decode them (bf16(e2m1 * e4m3 * phi),bf16(ldexp(e4m3, scale - 127))), the activation and the combine are unchanged. Gate-up reads 2,304 columns and down 1,152; the launcher refuses other shapes.Why every width and not only prompt chunks. I first ran these kernels for prompt chunks only, and replies changed with the chunking: Mini routes each token to 8 of 128 experts by score, a different summation order flips a near-tie now and then, and greedy output then parts ways within a few tokens. A 378-token prompt cut into 64-row, 33-row and 16-row chunks gave three different replies. With one kernel at every width a row's sums depend only on its own inputs, so:
token_shaat 64, 33, 16, 7 and 1 rows a chunk (1 row is the decode path's width);GPUs without tensor units keep the M3 kernels at every width, which is the same property there.
Which bits change. The order of each expert dot: eighths of the columns, each summed 16 columns an op in column order, then the eight partials in order; it was lane-strided blocks and a
simd_sum. Every rounding point is where it was. Replies can therefore differ from #4448's; on the 300-token Fibonacci reply used in #4447 thetoken_shais the same.What I tried for the projections and left out. The same construction for the six input projections and
wois also exact at every width and takes a 64-row chunk to 55 ms, but it costs 0.7 to 1.4 ms at one to four rows againstsp_matvec, so decode would pay for the prompt. It is not in this pull request.Checks on this head
ee248f9e3.zig build native -Dcpu=apple_m1: compiles.test-inkling2-metal-host,test-inkling2-host,test-inkling2-controls-host,test-inkling2-launch-map-host,test-inkling2-metal-capabilities,compile-inkling2-native-host): exit 0.tf-kernel-contract --only inkling2(-Doptimize=safe):SUMMARY 45 kernels: 45 pass gates 1-4, 0 fail, 0 known findings; 45 controls: 45 red as planted, 0 missed; 0 limit problems, exit 0.zig fmt --check build.zig zigandgit diff --check: clean.zig build test test-goldenon this head (the stack's inherited failures are listed in Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo #4446). M1 to M4, where this change selects nothing new. CUDA and HIP are not touched.Receipt
d87e8695dagainst this head.inkling2_loopMetal path, decode and prompt rows alike.thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7,--parallel 4 --context 16384 --prompt-cache-gib 0. The served rows have Inkling 2 Mini DSpark on Metal: attention scale 1/sqrt(128), and the recurrent step reads kappa as FP32 #4447 and Inkling 2 Mini DSpark on Metal: the hold in one command buffer, and drafts priced by the engine up to the whole block (one stream 44 to 97 tok/s on code, 4 streams 77 to 184-223) #4465 at their current heads and Metal loader: a checkpoint span of 16 GiB or more loads (each pread capped at 1 GiB) #4435's read cap applied.GPU time of one forward, cache empty. The 2, 3 and 4-row figures are the means of the verify windows of one drafted reply (the same reply on both heads); the others are single forwards.
d87e8695dA tile's op runs its 16 rows whether one is live or all are, which is why one row costs more and many rows cost less.
Served, TensorFold's clients, 256 tokens, greedy, three reps:
--drafter--drafterbench_concurrent.py --alone --serial, four streams: 12 of 12 replies equal their solo runs, plain and with the drafter, and the serial check passes (138 and 124 drafts accepted). One prompt in five chunkings gives onetoken_sha, as above (measured on this head with a debug switch for the chunk size that is not in the diff).Kernel contract
metal inkling2 units tf_ink2_nvfp4_gu_units,..._nvfp4_down_units,..._mxfp8_gu_unitsand..._mxfp8_down_units(zig/tests/contract/metal_inkling2_units.zig). None declaresreplaces: their sums take another order than the M3 kernels', so each is checked against the same float64 decode, dot and activation that the M3 entries use, at the columns the kernels fix (2,304 and 1,152), with 128 experts astf_ink2_grouprequires, and with one expert taking every row so that 15, 16, 17 and 20 rows cross a 16-pair band. The stated depth is the shared bound on an op's roundings (attention_range.mma_step) a 16-column step, plus the eight partial sums and the epilogue.phiin its own entry; the MXFP8 pair moves the scale's exponent by one in the helper both share (a control compiles only its entry). All four go red atshapes.SUMMARYline and exit status: Metal,tf-kernel-contract --only inkling2, M5 Ultra:SUMMARY 45 kernels: 45 pass gates 1-4, 0 fail, 0 known findings; 45 controls: 45 red as planted, 0 missed; 0 limit problems, exit 0. The new entries alone: non-finite classes equal float64's, five runs byte-identical with guards intact, 7 shapes within the bound, and the fp32-sum gate at k 2,304 and 1,152.inkling2_units_metal_records.zig): 256 threads, reserved; 16,384 bytes of threadgroup memory for the eight partial sums;offline = false, as for the other tensor-op kernels.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Drafted equals plain and concurrent equals solo. A prompt's reply is the same at every chunking, which is what a resumed prompt needs from these kernels; a resumed prompt against a fresh one was not run as such.)--drafter, no slower than without it. (Against Inkling 2 Mini on Metal: experts, gates, router, depth mix, combine, row batching, attention chunks and a concurrent forward (1,159 to 14 ms a row on M5 Ultra) #4448: four streams and prompts are faster; one plain stream is 6 % slower and one drafted stream is equal on the code prompt and 5 % slower on the chat prompt.)