Repository navigation
Inkling 2 Mini on Metal: a prompt-cache snapshot copies each key-value head's live rows, and the real-checkpoint serving tests run to it - #4607
Closed
sethforprivacy wants to merge 23 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
… a resumed prompt reads the rows a fresh one wrote
This was referenced Nov 22, 2026
…n before its row, and resume a turn the cache can keep
This was referenced Nov 22, 2026
8 tasks done
4 of 5 tasks
ashhart
force-pushed
the
lead/inkling2-mini
branch
from
November 23, 2026 19:59
3e0e9bc to
f790014
Compare
8 tasks done
ashhart
force-pushed
the
lead/inkling2-mini
branch
3 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
|
Owner
|
Thank you, @sethforprivacy. Every commit this PR adds is now on main inside #4387 with your authorship kept, so it ships with Inkling 2 Mini on Metal in the next release. Closing this one as landed there.
|
5 of 8 tasks
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.
What this changes
Before: with a prompt cache (
--prompt-cache-gib), a Mini turn that resumes from a kept state gives another reply than the same prompt answered fresh. After: the two are equal. A second commit correctsserving_test.zig's two real-checkpoint tests, which abort on #4387's head before they reach this, so that they run and check it.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 (97c91058f). This pull request's own commits ared877d3ce4(snapshot.zigandruntime_test.zig) and52bed2b8b(serving_test.zig). Neither depends on the other drafts.atc overlap --json: not run; ATC is not installed on the machine that pushes.The cause. A cache slot holds its keys head by head, each head the ring's rows (
attention.metalwrites a row at(h * ring + pos % ring) * D), and its values the same way.snapshot.zigcopied the firstlive * kv_width * 2bytes of a slot, which is head 0's region and then on into the next heads' regions, not each head's live rows:max_tokens), headh's rows landhtimes the difference of the two rings away from where the kernels read them.The fix. The save and the restore copy each head's first
liverows, from and to that cache's own head stride. A snapshot's size is whatsnapshot.bytesalready charged.How it showed. A three-turn chat, 2,602 tokens in the first prompt, each later turn adding a question;
--prompt-cache-gib 4against0, plain, greedy, on the stack named under Receipt:token_shae0ab3a54d5c83073935a5dfde0ab3a54d5c8f70b7d74e30dac1bda4c664a(its prompt differs, as turn 2's reply did)f70b7d74e30dThe chunk cuts are the same in both runs (the fresh turn also cuts at 2,560), and the result is the same at 64-row and 256-row chunks and with and without the drafter. Dumping the residual after every visit of the forward that follows the resume: resumed and fresh are equal through visits 0 to 4, which are sliding layers with full rings, and every row differs after visit 5, the first global layer.
Turn 2's prompt work is 2.67 s fresh and 0.19 s resumed, so the cache is worth having right.
Checks on this head
52bed2b8b.runtime_test.zig, new: "A snapshot restores each head's live rows into a cache of another capacity". It fills the first 100 rows of every head of every slot's keys and values, and the convolution states, with random bytes in a cache of capacity 200, saves, restores into a cache of capacity 500 and reads the same rows back. It needs a Metal device and skips without one. On Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo #4446'ssnapshot.zigit fails; on this head it passes.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 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 41 controls: 41 red as planted, 0 missed; 0 limit problems, exit 0.zig fmt --check build.zig zigandgit diff --check: clean.serving_test.zig's two real-checkpoint tests, as52bed2b8bcorrects them, withTF_INKLING2_METAL_DIRandTF_INKLING2_DSPARK_DIRset and Metal loader: a checkpoint span of 16 GiB or more loads (each pread capped at 1 GiB) #4435's read cap picked (the table under "The real-checkpoint serving tests").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). CUDA and HIP are not touched; I did not look at whether their snapshots have the same shape.The real-checkpoint serving tests (
52bed2b8b).serving_test.zig's two tests run withTF_INKLING2_METAL_DIR(andTF_INKLING2_DSPARK_DIRfor the second). On #4387's head they abort at the assert infirstLogprobRow, and behind the abort two of their expectations cannot hold. The commit changes the tests only:serialandtransactionscalledfirstRowon a stream that had drawn nothing, andfirstLogprobRowreads the token drawn (tokens[(next - 1) % ring], withnext > 0asserted). The host draws and then asks (lanes/open.zig), so the tests now do the same.transactionsplants a wrong seventh draft and then expected all eight sampled rows to be the reference's tokens. The eighth row is the model's reply to the wrong draft (94 where the reference continues with 1377), so the comparison is the seven rows before it.prompt_cache.zigskips a mark at the prompt's end unless the family warms), socachedwas 0. The longer turn is now served twice: the first pass is fresh (cached0) and keeps a state at its history, the second resumes there, and both must give the reference's tokens. The history isst.prompt_rowstokens, the grid a planned family's states sit on, so the test follows the chunk size if that changes (64 on this head).With the three corrected, the tests reach the defect this pull request fixes:
zig build test-inkling2-metal-host, both directories set97c91058f) with52bed2b8bonlyad3d31f9f) with this pull request's two commits, no drafter directory819edd9bd,e610dc650)On #4618's head alone the drafted test's
drafted.accepted > 0fails without #4447: its prompt there is 256 tokens (that head's chunk), and the drafter with #4387's attention scale has no draft accepted on it. With #4447's two commits it passes.Receipt
snapshot.zigagainst this head's.inkling2_loopMetal path, any request that resumes from the prompt cache.thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7,--parallel 4 --context 16384. The served rows are from the whole stack (Inkling 2 Mini DSpark on Metal: attention scale 1/sqrt(128), and the recurrent step reads kappa as FP32 #4447, 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, 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 prompt-chunk draft that follows it) with this commit applied and Metal loader: a checkpoint span of 16 GiB or more loads (each pread capped at 1 GiB) #4435's read cap.bench_concurrent.py --alone --serialon the same build: 12 of 12 replies equal their solo runs, plain and with the drafter.Checklist
d877d3ce4and pass with it; they skip without the checkpoint.)"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (A resumed prompt equals a fresh one from this head on; the other two as before.)--drafter, no slower than without it. (Neither path is touched.)