Repository navigation
Inkling 2 Mini on Metal: the snapshot and the DSpark drafter move onto #4724's shared kept-state walk and lane host (same replies, kept states 40 % smaller) - #4749
Draft
sethforprivacy wants to merge 77 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
…in the fewest 1,024-key folds a slot
… step reads kappa as the FP32 it is
…ws the hold drafts
… the prompt kernel, a tile of keys a chunk
The CUDA caches are head-major ([kv head][ring][dim]); copyState copied rows as [ring][kv*dim], so a state held part of head 0's ring and none of the others. A resumed prompt looked right only because the slot still held its own keys: after another prompt resumed the shared prefix, it answered that prompt. inkling2-serving adds that order (A keeps 14 and 39, B resumes A's 14 and decodes, A resumes 39 == fresh).
…ps in the scratch, so a stream's cache stages a window only
… cap while replies decode
…s from the cache, with no staging between
…16 weight rows by 32 of an expert's pairs an op
…n before its row, and resume a turn the cache can keep
… of its context a threadgroup, so a hold costs the same at any context
… skips the bias and key tests on far tiles, and loads a query row four values at a time
…re, and the running sums take theirs: six steps fewer a visit
…cache save and restore kept_state.zig says which rows of which key head of which visit a kept state holds (a global layer all of them, a sliding one its window less one), in packed order, split where a ring wraps. A backend supplies only the copy: CUDA's copyState and snapshotBytes now walk it, issuing the same copies in the same order as before. Host tests restore into caches of other capacities; inkling2-serving restores a device state into a model of another capacity and resumes a turn after a history kept at the chunk grid, after another prompt.
…t, the lanes and the score scratch dspark_lanes.zig holds what Metal's dspark.zig and dspark_state.zig keep beside their kernels today: the rings, each stream's committed rows [from, end), its held drafts, what an absorb commits and when a hold may draft, and the bytes a token of window costs a lane and the shared scores (`tokenBytes`, `fit`, `laneBytes`, `scoreBytes`). Drafter(B) drives the round loop's drafter over a backend B that takes each absorb and each hold in one call for all its streams and returns the drafts, so a backend can keep one command buffer a hold. Nothing calls it yet: host tests pin it to Metal's state functions and to the absorb/hold rules of dspark.zig.
…, a sliding layer's window less one by position
…st, and the opener takes its fit
ashhart
force-pushed
the
lead/inkling2-mini
branch
4 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
|
17 tasks
This branch has not been deployed
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
Metal moves onto #4724's shared code, as agreed on #4387: the prompt-cache snapshot walks
kept_state, the DSpark drafter becomes a backend ofdspark_lanes, and the opener takes itsfit(). No kernel changes and no reply changes. A kept state gets smaller, and one slip in the window fit goes away.This is a proposal on top of #4387 and #4724, opened as a draft.
f7e97de0d(which is on Inkling 2 Mini on CUDA: #4387's engine loads the checkpoint, answers correctly (64/64 teacher-forced), serves --parallel streams, and resumes prompt-cache states exactly #4640 at321432e4b), merged into the Metal stack as it is served here: Inkling 2 Mini on CUDA and Metal #4387 at3e0e9bcb83with Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo #4446, Inkling 2 Mini DSpark on Metal: attention scale 1/sqrt(128), and the recurrent step reads kappa as FP32 #4447, 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, 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, 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, Inkling 2 Mini on Metal: prompt chunks of 256 rows, filled a chunk a call (a 45K prompt 702 to 905 tok/s; replies keep decoding beside a prompt) #4608, 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, Inkling 2 Mini on Metal: with a drafter, the window fit prices a token at a token's bytes (a 64 GB limit holds the whole window for eight streams) #4622, Inkling 2 Mini on Metal: a prompt's projections and sliding attention on the tensor units (a 45K prompt 906 to 1,634 tok/s) #4631, Inkling 2 Mini on Metal: a window's grammar masks step by the padded vocabulary, so a structured reply passes its second row #4635, 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, 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, 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, Inkling 2 Mini DSpark on Metal: the block attends on the M5 tensor units, so a hold costs the same at any context #4660, Inkling 2 Mini on Metal: the prompt kernel keeps one set of sums in registers and skips the bias on far tiles (prefill 2,215 to 2,376 tok/s at 45K, same bits) #4666 and Inkling 2 Mini on Metal: six fewer steps a visit, the convolutions read their rows in place and the running sums take theirs (plain decode 61 to 63 tok/s, same bits) #4689. The diff againstlead/inkling2-minitherefore shows all of that. This pull request's own commits are155e9d0bd(the snapshot),7a4b861ce(the drafter and the fit) and5f17fb0d4(a comment of Inkling 2 Mini on Metal: a window's grammar masks step by the padded vocabulary, so a structured reply passes its second row #4635 that passes 120 columns only once the stack is together).atc overlap --json: not run; ATC is not installed on the machine that pushes.1. The snapshot walks
kept_state(155e9d0bd).snapshot.zig'sencodeis a walk over the 48 slots (Visit{ key_at, value_at, 8 heads, ring(slot), 256 bytes a row, globals[slot] }) with one blit a piece, and #4607's per-head hunk in that function is gone. This settles the one difference #4724 left open in the walk's favour: a sliding layer keeps thewindow - 1rows its next row reads, by position, where Metal keptmin(len, ring)rows in slot order. A row before the window is never read again, so the rest was dead weight, and a state now restores into rings of another size.restorealso refuses a state whose kept rows do not fit the rings (kept_state.fits).2. The drafter is a backend of
dspark_lanes(7a4b861ce).dspark.Drafterkeeps its kernels, scratch, weights and the timed hold, and gives the host what it asks for:Lane(the rings' buffers and the newest row),openLane,closeLane,setScores,policy,absorb(pieces)in one command buffer andhold(items, drafts), which is #4465's chained hold for greedy streams and the step-a-buffer path for sampled ones. The books (from,end, the held drafts), the absorb and hold rules and every refusal are the host's now;dspark_state.zigis the scratch and a lane's buffers. #4660's tensor-unit attention is insideholdunchanged.3. The opener takes
fit().native/inkling2.zigprices a drafted stream withdspark_lanes.fit(),laneBytesandscoreBytes. With #4622 and #4660 both in the stack the opener had a slip that neither has alone: it took the scores' price a token asscoreBytes(1) - scoreBytes(0), and #4660's floor under small windows makes both of those 599,040, so the fit charged the shared score scratch nothing a token (768 bytes) when it chose the window. The reservation made after it was right.fit()carries the 768, so that cannot come back.#4660's wider scratch. From 1,024 tokens up the host's
scoreBytesalready holds the tensor-unit partials (768 bytes a token against 390). Under 1,024 they need a floor of 599,040 bytes, which is Metal's alone:setScorestakes the larger of the two, the floor is counted in the drafter's fixed bytes, and a host test holds both statements. I leftdspark_lanes.scoreBytesas it is rather than put a Metal kernel's constant in shared code; say if you would rather it lived there.In #4724's files. One edit, in
dspark_lanes_test.zig: the lines that pinned the prices tometal/dspark_state.zigare gone, since those functions no longer exist and the host's prices are the only ones. The constants it still checks against Metal (block,absorb_rows,vocabulary,hidden) stay.What becomes of the open drafts. #4607's
snapshot.zighunk is replaced by the walk (its tests stay and pass). #4465's and #4660'sdspark.zigchanges are the backend'shold. #4622's fit is the shared one. I have left those drafts as they are until #4724 lands, and will fold this into them then if that is easier to review.Which bits change. None. Every reply below has the hash it had before the move.
Checks on this head
5f17fb0d4.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, 79 of 79 steps. That includes Inkling 2 Mini: one shared per-head kept-state walk (CUDA uses it) and a shared DSpark lane host with one tokenBytes #4724's host tests ofkept_stateand of the lane host over its recording backend.TF_INKLING2_METAL_DIR,TF_INKLING2_DSPARK_DIR): exit 0. That is the serving tests of 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 (a resumed turn equals a fresh one) and the drafting test (drafted tokens equal the target's, and a rollback is exact), now through the shared host.tf-kernel-contract --only inkling2(-Doptimize=safe):SUMMARY 56 kernels: 56 pass gates 1-4, 0 fail, 0 known findings; 56 controls: 56 red as planted, 0 missed; 0 limit problems, exit 0. No kernel changed; run for completeness.zig fmt --check build.zig zigandgit diff --check: clean.runtime_test.zig: the byte accounting test now expects a sliding layer's window less one. A new device test saves at position 2,500 (past the sliding ring's wrap), restores into a cache of another capacity, and checks that every kept position of a sliding and a global head is at its slot in the new rings, and that the row before a sliding head's kept rows was not carried. That last check is the one the old slot-order copy would not meet; I did not run it against the old copy.dspark.zig: the host's score bytes hold the tensor-unit partials from 1,024 tokens up, and the floor holds them below.native/inkling2.zig: the fit's bound test readsfit().zig build test test-golden(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: I have no CUDA machine, and this touches no CUDA file. M1 to M4: nothing here depends on the tensor units except Inkling 2 Mini DSpark on Metal: the block attends on the M5 tensor units, so a hold costs the same at any context #4660's path insidehold, which is unchanged; not run.Receipt
inkling2_loopMetal path: the prompt cache, and every stream served with--drafter.thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7.The prompt cache, a three-turn chat (2,602, 2,706 and 2,827-token prompts),
--prompt-cache-gib 4against0:749e8cbd3baf, equal to fresh32d35900a128, equal to freshBoth resumes are past the window, so every sliding head restores 1,023 rows by position.
Served,
--parallel 4 --prompt-cache-gib 0, TensorFold's clients (256 tokens, greedy, three reps) andlane_bench.py:--drafter--drafter--drafterA lone drafted stream moves by a few percent from one server start to the next (its drafts are priced from a hold timed at load); the two one-stream rows are that spread, not a change.
bench_concurrent.py --alone --serial: every reply equals its solo run, plain and with the drafter, at one stream and at four. The concurrency check's four replies are unchanged. A seeded sampled request (temperature 0.8, top_p 0.95, seed 37), which takes the step-a-buffer hold: hash4d9062f8e44fbefore and on this head, drafted and with"draft": false, with the same 73 of 153 drafts accepted.--context 262144 --parallel 8 --prompt-cache-gib 16with the drafter: opens the whole window as before, with the same startup line.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (All three on this head.)--drafter, no slower than without it. (Against the stack before the move: level.)