Skip to content

Inkling 2 Mini on Metal: wide prompt chunks take the routed experts on turned tiles, 16 weight rows by 32 of an expert's pairs an op - #4649

Closed
sethforprivacy wants to merge 13 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-turned
Closed

sethforprivacy wants to merge 13 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-turned

Conversation

@sethforprivacy

Copy link
Copy Markdown
Contributor

What this changes

Before: a tensor-unit tile of the routed experts is 32 weight rows by 16 of an expert's pairs, at every chunk width. After: a chunk of more than 512 rows takes the same products on tiles turned the other way, 16 weight rows by 32 of the expert's pairs an op. A 1,024-row chunk gives an expert 64 pairs on average, so a 32-pair band is full, and a block of weights is decoded once for 32 pairs where it was decoded once for 16.

A 1,024-row prompt chunk at 16K tokens of context goes from 428 to 403 ms of GPU time, and a 45K-token prompt from 2,078 to 2,212 tok/s served. Same bits.

This is a proposal on top of #4387, opened as a draft.

The kernels. ink2_units_t<FP8, GU> is ink2_units with the tile turned: a threadgroup is 16 weight rows of one expert, and each simdgroup's op takes 32 of the expert's pairs, where ink2_units takes 32 weight rows by 16 pairs. The four entries are tf_ink2_{nvfp4,mxfp8}_{gu,down}_units_t. The decode of a weight block, the scale, the gate and the epilogue are the same code.

Why the bits are the same. An output is one (pair, weight row) dot product. Both tiles accumulate it over the same 16-column steps in the same order with the same operands; the tile's orientation decides which outputs share an op, not an output's terms. So the width may choose between them, as #4523's rule allows only for kernels with one result: a row's sums still do not depend on the chunk it came in. Every served reply has the hash it had on #4645, among them the prompts that fill in 1,024-row chunks.

Who takes which. experts.units picks by the call's rows: over 512, the turned tiles. Rounds, and prompt chunks beside other streams (256 rows at most since #4644), stay on #4523's tiles. experts.unitsTurned asks for the turned tiles at any width, which is how the contract reaches them with small shapes.

Checks on this head

  • Head commit: 84ab2c63f.
  • 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 52 kernels: 52 pass gates 1-4, 0 fail, 0 known findings; 52 controls: 52 red as planted, 0 missed; 0 limit problems, exit 0. Four of the kernels and four of the controls are new: each turned entry against float64 on seven shapes, one of them 40 rows of one expert so that the pairs cross a 32-pair band, and its control (the NVFP4 factor doubled, the MXFP8 scale's exponent off by one) red at the first shape.
    • 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, which have no tensor units and never load these kernels. CUDA and HIP are not touched.

Receipt

GPU time of a 1,024-row prompt chunk at 16K tokens of context, and of a 45K-token prompt in all (a development tree that is this stack with timing switches):

#4645 This head
The chunk 428 ms 403
The 45K-token prompt, tokens a second of GPU time 2,186 2,314

Served:

#4645 This head
A 45,246-token prompt, lane_bench.py 2,078 tok/s (21.8 s to the first token) 2,212 (20.5 s)
A 6,905-token prompt beside a decoding stream 4.1 s 4.1 s
One stream, plain, code and chat (short prompts) 60.6 and 61.2 tok/s 60.5 and 61.1
One stream, --drafter 124.8 and 93.1 123.5 and 92.0
Four streams, plain 215.9 and 217.5 215.8 and 217.8
Four streams, --drafter 277.4 and 226.0 276.8 and 226.0

The decode rows do not reach the change (a round is at most a few dozen rows); they are there to show the build is otherwise the same. The drafted chat prompt's three repetitions were 96.1, 90.8 and 92.0.

Checklist

@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:48
@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

@ashhart
ashhart force-pushed the inkling2-mini-metal-turned branch from 84ab2c6 to 69863f2 Compare December 1, 2026 17:16
@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thanks @sethforprivacy. #4649 is #4645 plus one commit, wide chunks take the routed experts on turned tiles, 16 weight rows by 32 of an expert's pairs an op.

Exactness

  • zig/src/families/inkling2/metal/experts.zig:302: on a GPU with tensor units, a chunk of more than 512 rows now takes the routed experts on the turned kernels (experts_units.metal:141, ink2_units_t), at default settings. The doc comment says these give "the same sums" as ink2_units. That is plausible: each output still sums its K blocks in the same simdgroup split, and the simdgroup partials are summed the same way. But the weights become the left operand and the pairs the right, and nothing shows the tensor-unit op sums a 16-wide block in the same order with the roles swapped. The new contract cells check the turned kernels against the FP64 reference within a bound, with planted controls, which is good. They don't compare the turned output with ink2_units byte for byte.
  • This matters beyond this kernel. backend.zig:141 declares the backend chunk_invariant whenever the units are present, so the host may re-cut a prompt and expect the same bits. If the turned tiles round differently, a row's bits would depend on whether its chunk is over 512 rows, and that declaration would no longer hold. Please add a device test that runs both kernels on the same pairs (over 512 rows, both formats, gate-up and down) and requires equal bytes. Or keep wide chunks on ink2_units until that test exists.
  • This builds on the tensor-unit experts from 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 and the 1,024-row chunks from Inkling 2 Mini on Metal: a wide prompt chunk stages its convolution taps in the scratch (157.8 to 11.6 MiB a stream) #4644; those asks stay on those PRs.

Stale against today's main

Main now reports each kernel choice through TF_EXPLAIN (explain.reportExpert in zig/src/families/inkling2/metal/explain.zig:118). When this series is rebased onto it, the expert report should name the units kernels and the turned tiles, so TF_EXPLAIN describes what actually runs.

Repo checks we ran on this branch:

  • zig fmt and ast-check are clean.
  • The lean check is unchanged.
  • No Zig file is over 600 lines.
  • No new environment variables, and no serving pins touched.
  • The source pins are updated.

The M5 check we'd like to see:

@sethforprivacy

Copy link
Copy Markdown
Contributor Author

Thanks for the rebase and the careful review, @ashhart. I'm closing this one rather than putting it behind a switch.

The tensor-unit sums don't match main's bits, and I measured that already on 23 Nov (issuecomment-7107950724). The experts changed 19 of 24 greedy replies, a prompt's projections and sliding attention changed 20, and the logits changed 9,182 of 51 million BF16 values, though none of the 24 replies. A default-off path that only M5 takes, and whose replies differ from the default, isn't worth the contract and review load it would add to the repo.

What happens to the rest:

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