Skip to content

Inkling 2 Mini on Metal: the prompt kernel reads its key tiles from the cache on M5 (a round at 96K context 28.6 to 21.5 ms, a 45K prompt 1,892 to 2,078 tok/s) - #4645

Draft
sethforprivacy wants to merge 44 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-direct
Draft

sethforprivacy wants to merge 44 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-direct

Conversation

@sethforprivacy

Copy link
Copy Markdown
Contributor

What this changes

Before: tf_ink2_attn_prompt copies every 64-key tile of keys and values into threadgroup memory before its simdgroups read it, one BF16 value a load, 256 values apart, with two threadgroup barriers a tile. A round has three pairs a key head, so one of eight simdgroups uses what all 256 threads copied, and at a long context that copy is most of a round's attention. After, on M5, each simdgroup reads the blocks it needs from the cache, two four-value loads a lane, and there is no staging and no barrier.

A one-row round at 96K tokens of context goes from 28.6 to 21.5 ms of GPU time, at 44K from 22.6 to 18.9. A 45K-token prompt goes from 1,892 to 2,078 tok/s. Same bits.

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

Why the copy is not needed. The staging was there so that a tile's rows are contiguous and its dead keys zero. A tile is 64 keys starting at a multiple of 64 (chunks are 64, or a multiple of 1,024), and a ring is a multiple of 64 rows (ringFor and the global ring both align to tile_keys), so a tile never wraps its ring: its 64 rows are contiguous in the cache. ink_tile_get loads a lane's two rows of a block as two bfloat4, and gives zero for a key from the tile's live count on, which is what the copy stored. Nothing outside the tile's live rows is read.

Before M5. The fragment layout there is another one (TF_SIMD_FRAGS), and I cannot run it, so that build keeps the staging and its barriers exactly as they were, behind the same #ifdef.

Which bits change. None: the operands are the same values. Every reply in the receipt has the hash it had on #4644.

Checks on this head

  • Head commit: a09f3e7d7.
  • 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 48 kernels: 48 pass gates 1-4, 0 fail, 0 known findings; 48 controls: 48 red as planted, 0 missed; 0 limit problems, exit 0. The prompt kernel's two M5 entries (global and sliding) are the ones that exercise the change; their controls stay red.
    • 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, whose build of the kernel is unchanged. CUDA and HIP are not touched.

Receipt

GPU time of a one-row round, plain, after a prompt of the given length (medians of 20 rounds, measured in a development tree that is this stack with timing switches):

Context #4644 This head
264 tokens 16.4 ms 16.3
8,424 18.9 18.1
44,424 22.6 18.9
96,024 28.6 21.5

With the attention left out a round at 44K takes 13.0 ms, so the attention's share there goes from 9.6 to 5.8 ms. One plain stream at 44K tokens of context decodes at 51.1 tok/s where it did 43.4.

Served:

#4644 This head
A 45,246-token prompt, lane_bench.py 1,892 tok/s (23.9 s to the first token) 2,078 (21.8 s)
A 44,424-token prompt, alone 22.6 s 20.4 s
A 6,905-token prompt beside a decoding stream 4.2 s 4.1 s
One stream, plain, code and chat (short prompts) 60.3 and 60.9 tok/s 60.6 and 61.2
One stream, --drafter 124.2 and 93.4 124.8 and 93.1
Four streams, --drafter 276.9 and 225.8 277.4 and 226.0
  • Exactness: every reply has the hash it had on Inkling 2 Mini on Metal: prompt chunks of up to 1,024 rows, their taps staged in the scratch (a 45K prompt 1,634 to 1,892 tok/s) #4644: 12 of 12 of bench_concurrent.py --alone --serial equal their solo runs, plain and with the drafter; the concurrency check's four; a three-turn chat with the prompt cache on and off; one prompt at 64, 33, 16, 7 and 1 rows a chunk (development tree).
  • What I tried first and left out: a round folding a global layer's keys 256 at a time in up to 512 chunks, on the guess that the serial walk of a 1,024-key chunk was the cost. It changed nothing; the copy was the cost.
  • Threadgroup memory: the M5 pipeline now takes none (the two 16 KB tiles are gone); its launch record still declares at most 32,768 and the limits gate passes. Say if you would rather the record say 0.
  • oMLX 0.8.1 does 2,628 to 2,895 tok/s on the 45K-token prompt on this machine.
  • Licence of any new weights or drafter, or "n/a": n/a.

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.
@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