Skip to content

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

Draft
sethforprivacy wants to merge 39 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-logits
Draft

sethforprivacy wants to merge 39 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-logits

Conversation

@sethforprivacy

@sethforprivacy sethforprivacy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: a round's logits cost a pass of the 922 MB output matrix for every row. A verify window of eight rows spent about 11 ms of its 32 ms there, and a shared round of four streams the same for its four rows. After, two commits:

  1. 5712db321: the logits kernel takes a vocabulary row for up to eight rows of the window, so the matrix is read once. Same bits. An eight-row window goes from 31.9 to 26.6 ms.
  2. ad3d31f9f: on a GPU with tensor units the logits run on them, one pass of the vocabulary for up to 16 rows, at about 1.0 ms whatever the width. An eight-row window goes to 24.8 ms.

Served on the whole stack: one drafted stream 106 to 123 tok/s on the code prompt and 79 to 92 on the chat prompt; four streams 237 to 281 and 188 to 223 drafted, 182 to 215 plain. Every reply is the same as before.

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

5712db321, one read of the matrix. tf_inkling2_logits was a thread a (vocabulary row, row of h): 2,304 products added in order, and the vocabulary row read again by every row's thread. A thread now takes a vocabulary row for up to eight rows of h (thread_position_in_grid.y counts groups of eight) and keeps eight sums, each still adding its products in d order with contraction off, so every logit has the bits it had. The kernel's contract entry and control are the ones it had; the entry's widest shape goes from 7 rows to 11 so that it crosses a group.

ad3d31f9f, the tensor units. tf_ink2_logits_units is built like #4523's expert kernels: a threadgroup is 32 vocabulary rows against 16 rows of h, each of its eight simdgroups sums an eighth of the 2,304 columns 16 an op (BF16 operands, FP32 sums), the eight partial sums are added in order, and the result is rounded to BF16 and capped at 30 as before. It runs at every width, one row included, so a row's logits do not depend on the rows beside it. GPUs without tensor units keep the first commit's kernel.

Which bits change. With the second commit, the order of each logit's 2,304-term sum, before its BF16 rounding. No reply changed in any run here: the test reply below, the twelve replies of the concurrency check and the three-turn chat all give the hashes they gave on #4608.

Checks on this head

  • Head commit: ad3d31f9f.
  • 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 46 kernels: 46 pass gates 1-4, 0 fail, 0 known findings; 46 controls: 46 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, which take the first commit's kernel. CUDA and HIP are not touched.

Receipt

GPU time of a verify window, the means over one drafted reply of 256 tokens (the same reply on all three, token_sha b4fcf236afd2):

Rows #4608 5712db321 This head
4 23.3 ms 20.6 20.5
5 25.9 22.7 22.0
6 28.6 24.3 22.8
7 30.1 25.5 24.0
8 31.9 27.1 24.8

The logits launch by itself, timed by repeating it four times in those windows: 1.6 ms at four rows and 2.8 at eight with the first commit, 0.9 and 1.0 with the second. A one-row forward takes 15.5 ms with either.

Served, TensorFold's clients, 256 tokens, greedy, three reps:

fibonacci-raw gpu-chat-no-think 4 streams, code 4 streams, chat
#4608, plain 59.5 tok/s 59.9 182.4 total 181.2 total
This head, plain 60.3 60.6 215.4 213.3
#4608, --drafter 106.1 79.4 236.9 188.2
This head, --drafter 123.4 91.5 281.1 223.0
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 (181 and 147 drafts accepted). A three-turn chat gives the same hashes with the prompt cache on and off.
  • The drafted rows gain more than the windows' time alone gives because the depth rule prices a draft by the window's cost at load, and a cheaper row buys deeper drafts: 181 drafts accepted on the code prompt where it was 175, 147 on the chat prompt where it was 134.
  • Prompt speed: unchanged (a 45K-token prompt at 906 tok/s).
  • Peak footprint: 21 GB plain, 22 GB with the drafter, as before.
  • 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: one new entry, metal inkling2 units tf_ink2_logits_units (zig/tests/contract/metal_inkling2_logits_units.zig). It declares no replaces: its sums take another order than tf_inkling2_logits', so it is checked against the same float64 dot, BF16 round and cap, at 1, 8 and 20 rows (20 crosses a 16-row band) and at 64, 90 and 32 vocabulary rows (90 leaves the last tile part full, where the kernel reads the last row again and stores nothing for it).
  • A planted control: the cap's divisor is 15 where it is 30; red at shapes.
  • Each backend's SUMMARY line and exit status: Metal, tf-kernel-contract --only inkling2, M5 Ultra: the line above, exit 0. The new entry alone: non-finite classes equal float64's, five runs byte-identical with guards intact, 12 shapes within the bound, and the sums gate at k 2,304.
  • Launch record (inkling2_units_metal_records.zig): 256 threads, reserved; 16,384 bytes of threadgroup memory; offline = false, as for the other tensor-op kernels.
  • tf_inkling2_logits keeps its entry, its control and its record; its shapes gate now runs 1, 5 and 11 rows.
  • Chips I could not run: M1 to M4.

Checklist

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.
gilby added a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
…s and enable gpu_tokens

Preserve ashhart#4618's exact dot-product, BF16 rounding, and softcap30 summation
order in both tf_inkling2_logits (glue.metal) and tf_ink2_logits_units
(experts_units.metal). Add LogitMode (.logits, .argmax, .both), Stage-1
per-tile reduction, and Stage-2 tf_inkling2_reduce_argmax matching exact
firstGreatest tie-breaking and NaN-at-0 semantics while skipping unread f32
logits DRAM stores when mode == .argmax.

Enable gpu_tokens = true with async GPU-resident decode queueFn, shared
token/flight metadata rings, mixed/pure verify batch planning, updated
launch records, host unit tests, and contract argmax probes + planted
tie-order controls for both glue and tensor-unit logits kernels.

Refs ashhart#4652
gilby added a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
…atch_rows=64

Rebase PR ashhart#4596 onto ashhart#4618 with 0-ULP sliding attention parity (192-thread GQA 3:1 KV sharing, up to 8-stream slots), batched prepSlots/relTable/merge across all 48 visits, exact ashhart#4618 prompt_attention on the 8 global visits, and batch_rows=64. Refs ashhart#4652.
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @sethforprivacy. We read this against its base and have one thing to settle before the rest of the Inkling 2 Mini stack.

On tensor-unit Macs, tf_ink2_logits_units now replaces tf_inkling2_logits, and it splits the dot products across simdgroups before adding the partials. The scalar kernel adds them in dimension order. FP32 addition isn't associative, so the two aren't bit-equal by construction. The contract in metal_inkling2_logits_units.zig compares with an FP64 reference and simulated orders, not with the kernel being replaced.

Could you add a direct comparison of the full FP32 logits and the BF16 result from both kernels, on adversarial and served shapes at 1, 8, 16 and the largest admitted rows? If any byte differs, please keep the scalar reduction on this path, because our bar is that every output bit stays the same.

We haven't run this on a device yet.

  • Synthena

@sethforprivacy

Copy link
Copy Markdown
Contributor Author

Done, and the bytes differ. The numbers first, then one question before I change the branch.

The comparison. Both kernels through their host launches (glue.logits and experts.logitsUnits) on the same buffers, at 1, 8, 16 and 256 rows (max_rows, the most a launch is given on this head). Each kernel is also built with its store edited to keep the FP32 sum, and again to keep the BF16 result before the cap, so the three stages are compared one by one. Rounding each kernel's FP32 sums on the host gives that kernel's own BF16 results in every case, so the edited builds are the served kernels.

It is a device test, logits_compare_test.zig, one commit on this head. It asserts equal bytes, so it fails on a Mac with tensor units, which is why it is not on this branch. On this base it needs #4435's read cap to load the checkpoint.

Served shape. The checkpoint's unembedding (200,058 vocabulary rows) against the final-norm rows of a 256-token prompt (tap 48, the kernel's input): its last 1, 8, 16 and 256 positions.

Rows Logits FP32 sums that differ BF16 results that differ Served FP32 logits that differ Rows whose top id differs
1 200,058 181,198 30 30 0
8 1,600,464 1,449,930 242 242 0
16 3,200,928 2,898,316 555 555 0
256 51,214,848 46,422,539 9,182 9,182 0

Nine sums in ten differ in their last bits (the largest gap at 256 rows is 0.00012), and at 256 rows 0.018 % of the logits land on the other side of a BF16 rounding (0.015 % at one row). The largest gap between two BF16 results is 0.125, one BF16 step for a logit between 16 and 32, and 0.095 after the cap. Of the 9,182, 439 are more than one BF16 step apart: those are logits next to zero, where the sums' own gap spans several steps, and the widest of them is 0.000006.

Adversarial fills, 256 rows. The rows at 1, 8 and 16 show the same thing at their size.

Fill Vocabulary rows BF16 results that differ Largest gap between them Served logits that differ Rows whose top id differs
Checkpoint unembedding, random rows 200,058 14,656 of 51,214,848 0.0156 14,656 0
Checkpoint unembedding, rows over 24 binades 200,058 27,788 of 51,214,848 32 21,544 0
Random weights and rows (the contract's fill) 4,122 274 of 1,055,232 0.0625 274 0
Weights and rows over many binades 4,122 612 of 1,055,232 2,048 220 0
Cancelling pairs of columns 4,122 0 0 0 0
Exact products and sums (the contract's stress fill) 4,122 0 0 0 0
NaN and infinities in the rows 4,122 278 of 1,055,232 0.0625 278 0

The large gaps in the two wide fills are single BF16 steps of large sums; where the cap has flattened both values the served logits agree, which is why fewer of those differ. A row of NaN is the same bytes from both kernels.

Served replies. This head built twice, differing only in which kernel runShared launches: 18 greedy requests plain and the same 18 with --drafter return the same token hashes from either build. That is 36 requests and not a proof, but nothing I have served has moved with the kernel.

The question. By your bar the scalar reduction stays here. Before I change the branch: the same will hold under this PR and above it. #4523 (the experts' products), #4631 (a prompt's projections and sliding attention) and #4660 (the drafter's attention) put their sums on the tensor units as well, and each description says which sums change. I have not run this comparison on those yet, but I expect the same result, since the tensor op adds a tile's products in an order no scalar loop here reproduces. Most of the M5 speed in this stack is in those kernels. Which would you like?

  1. Scalar sums everywhere. I take the tensor-unit kernels out of the stack, starting here with a revert of ad3d31f9f. 5712db321 stays: it adds each dot in d order as before.
  2. The tensor-unit sums as the M5 path's reference, taken once, since main has not served this model. Each of those PRs then carries this comparison with its numbers.
  3. The tensor-unit kernels behind a switch that is off by default.

I'll make the revert here as soon as you say 1 or 3, and I can run the same comparison on #4523, #4631 and #4660 in the meantime if that helps you decide.

@sethforprivacy

Copy link
Copy Markdown
Contributor Author

The same comparison on the other tensor-unit paths, as offered above. It is not the result I expected. The kernels differ from their scalar twins about as the logits do, but the model amplifies that, and most long greedy replies change.

How. Two commits on #4631's head, which has #4523, #4618 and #4631: inkling2-mini-units-compare. A switch turns each tensor-unit path off alone, and "off" is the kernel it replaced. The test compares the kernels on the same buffers and then a whole prompt; the served rows are 24 fixed prompts (code and prose openers), greedy, 256 tokens each. Not for merging.

1. The kernels on the same buffers, 256 rows, a prompt's final-norm rows as input. The rows at 1, 8 and 16 are in the test's output and show the same rates.

Kernel against its scalar twin BF16 values That differ Largest gap
NVFP4 gate-up activations (#4523, layer 0) 2,359,296 622 (0.026 %) 0.125
NVFP4 down products 4,718,592 818 (0.017 %) 0.125
MXFP8 gate-up activations (layer 20) 2,359,296 353 0.0625
MXFP8 down products 4,718,592 694 0.0625
wq on tf_ink2_dense_units (#4631) 786,432 109 (0.014 %) 0.0625
wo on tf_ink2_dense_units, random rows 589,824 113 0.0156

2. A whole 256-token prompt, each path on alone against every path off. Hidden rows at the four tap visits, 589,824 BF16 values each, then 64 greedy tokens.

On alone Differ after visit 5 After visit 23 After visit 48 Greedy tokens
Logits (#4618) 0 0 0 all 64 the same
Experts (#4523) 423,365 (72 %) 570,785 (97 %) 570,272 part at the 15th
A prompt's projections (#4631, first commit) 435,485 569,568 568,933 all 64 the same
A prompt's sliding attention (#4631, second commit) 452,957 567,721 567,112 part at the 15th

3. Served: replies that differ from every path off, of 24.

On alone Replies that differ
Logits (#4618) 0
Experts (#4523) 19
A prompt's projections (#4631, first commit) 20
A prompt's sliding attention (#4631, second commit) 20
All four 20
The drafter's attention (#4660), on the whole stack, against its scalar attention and against plain 0

With #4660 the accepted drafts move (4,021 of 9,498 against 4,013 of 9,112) and no reply does, since the target verifies every draft. Where replies differ, both read as the model's: they run together for a dozen or more tokens and then take another wording.

4. One more row, because it bears on the choice. #4387 has a pair of this kind already: attention.zig takes prompt_attention on a GPU with tensor units and prompt_attention_pre_m5 without. With every path above off, the same 24 prompts with the pre-M5 kernel forced on this M5: 24 of 24 replies differ from the M5 kernel's. That is the pre-M5 kernel run on an M5 by a local switch (TF_CMP_NO_ATTN_UNITS, the second commit); I have not compared with a real pre-M5 Mac.

What I take from it.

So the question above is the same, with numbers in place of my expectation: on a GPU with tensor units, is the reference the scalar kernels' output, or is it that GPU's own path taken once? I will not change a branch until you say.

plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 23, 2026
plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 23, 2026
…ed figures; the engine receipt moves to ink mac engines
@ashhart
ashhart force-pushed the lead/inkling2-mini branch 3 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

plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 24, 2026
…mac-beat-4618-on-m5-ul

Inkling 2 Mini on Mac: beat ashhart#4618 on M5 Ultra, starting with DSpark's hold cost
plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 24, 2026
…eal speed, not a void run

The void premise was wrong: ashhart#4618's 123/281 tok/s is sethforprivacy's stack that
card 210 took, none of it on main; main's routed experts decode ~1.16 s a round
by design (serial scalar dots, one threadgroup a row and route), and the server
log shows the steady latency signature. bench.sh gains the guard: a MIN_TPS
floor per cell plus PARTNER_JSON so a second control aborts when it runs over
2x under its partner; controls pair, never against the candidate. Control runs
take TOKENS=32 to fit timeout 600.

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