Skip to content

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
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-units
Draft

sethforprivacy wants to merge 35 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-units

Conversation

@sethforprivacy

@sethforprivacy sethforprivacy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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, ee3323711 and 55de80afd), so the comparison below is against #4448 at cca30e890. This pull request's own commit is still ee248f9e3.

GPU time of one forward, cache empty, single forwards at each width:

Rows #4448 cca30e890 This head
1 14.0 ms 15.5 ms
2 17.9 18.6
4 25.1 22.6
16 47.2 33.9
64 134 78

Served on the whole stack (#4447, #4465 at db534d6cf and 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 native compiles; 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 --check and git diff --check clean; 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.

The kernels (experts_units.metal, after nax.h and the M3 decode helpers). tf_ink2_group lists each expert's route pairs, as it already does for the grouped kernels. Then tf_ink2_nvfp4_gu_units, tf_ink2_nvfp4_down_units and 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, through nax.h's 16x32x16 fragments with BF16 operands and FP32 sums (units.metal builds 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:

  • the same prompt gives one token_sha at 64, 33, 16, 7 and 1 rows a chunk (1 row is the decode path's width);
  • concurrent equals solo and drafted equals plain, as before (below).

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 the token_sha is the same.

What I tried for the projections and left out. The same construction for the six input projections and wo is 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 against sp_matvec, so decode would pay for the prompt. It is not in this pull request.

Checks on this head

  • Head commit: ee248f9e3.
  • Lean checker, on the base and on this head: 167 and 167, 0 new.
  • Tests run:
    • zig build native -Dcpu=apple_m1: compiles.
    • The six Inkling host steps (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 zig and git diff --check: clean.
  • CI: not yet reported when this was written.
  • Not run, and why: the whole zig build test test-golden on 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

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.

Rows #4448 d87e8695d This head
1 16.1 ms 17.4 ms
2 20.4 21.1
3 24.0 23.7
4 27.6 26.4
16 49.4 36.0
64 138 84

A 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:

fibonacci-raw gpu-chat-no-think 4 streams, code 4 streams, chat
#4448 head, plain 55.1 tok/s 55.5 128.2 total 127.2 total
This head, plain 51.6 52.0 158.9 157.2
#4448 head, --drafter 78.9 75.6 169.7 140.2
This head, --drafter 79.0 71.8 197.6 161.6
oMLX 0.8.1, DSpark on, same clients not measured 72.5 not measured 126.6
  • Exactness: bench_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 one token_sha, as above (measured on this head with a debug switch for the chunk size that is not in the diff).
  • The drafted chat prompt lands fewer drafts on this head (124 accepted against 132) because the reply itself differs; its two-row windows are also the ones that cost more.
  • Prompt speed: a 45K-token prompt goes from 419 to 666 tok/s. oMLX does 2,785 on this machine, so the prompt path is still short by a factor of four; the 64-row chunk is the next limit.
  • Peak footprint: 20 GB plain, 21 GB with the drafter.
  • Licence of any new weights or drafter, or "n/a": n/a.
Kernel contract
  • Kernels registered with the contract, and the kernel each one replaces: four new entries, metal inkling2 units tf_ink2_nvfp4_gu_units, ..._nvfp4_down_units, ..._mxfp8_gu_units and ..._mxfp8_down_units (zig/tests/contract/metal_inkling2_units.zig). None declares replaces: 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 as tf_ink2_group requires, 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.
  • The probe's weights are scaled down from the M3 probe's (MXFP8 scales around 2^-13, the NVFP4 denominator times 64) so that the gate and up sums stay in the activation's live range; with the M3 probe's values every gate-up output saturates and a doubled weight does not show.
  • A planted control for each kernel: the NVFP4 pair doubles phi in 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 at shapes.
  • Each backend's SUMMARY line 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.
  • Launch records (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.
  • Chips I could not run: M1 to M4 (the entries register only where the GPU has tensor units).

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The four contract entries and their controls are new; they are collected only on a GPU with tensor units.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "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.)
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --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.)

ashhart and others added 30 commits November 21, 2026 16:05
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.
@ashhart
ashhart force-pushed the lead/inkling2-mini branch 4 times, most recently from aefb063 to c41911e Compare November 24, 2026 09:43
@ashhart
ashhart deleted the branch ashhart:lead/inkling2-mini November 24, 2026 09:43
@ashhart ashhart closed this Nov 24, 2026
@ashhart ashhart reopened this Nov 24, 2026
@ashhart
ashhart changed the base branch from lead/inkling2-mini to main November 24, 2026 09:49
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
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 main. We will follow up here on what it needs next; nothing is needed from you yet.

  • Synthena

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants