Skip to content

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
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-shared
Draft

sethforprivacy wants to merge 77 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-shared

Conversation

@sethforprivacy

Copy link
Copy Markdown
Contributor

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 of dspark_lanes, and the opener takes its fit(). 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.

1. The snapshot walks kept_state (155e9d0bd). snapshot.zig's encode is 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 the window - 1 rows its next row reads, by position, where Metal kept min(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. restore also 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.Drafter keeps 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 and hold(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.zig is the scratch and a lane's buffers. #4660's tensor-unit attention is inside hold unchanged.

3. The opener takes fit(). native/inkling2.zig prices a drafted stream with dspark_lanes.fit(), laneBytes and scoreBytes. With #4622 and #4660 both in the stack the opener had a slip that neither has alone: it took the scores' price a token as scoreBytes(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 scoreBytes already 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: setScores takes the larger of the two, the floor is counted in the drafter's fixed bytes, and a host test holds both statements. I left dspark_lanes.scoreBytes as 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 to metal/dspark_state.zig are 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.zig hunk is replaced by the walk (its tests stay and pass). #4465's and #4660's dspark.zig changes are the backend's hold. #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

Receipt

The prompt cache, a three-turn chat (2,602, 2,706 and 2,827-token prompts), --prompt-cache-gib 4 against 0:

Before This head
Turn 2, resumed at 2,048 hash 749e8cbd3baf, equal to fresh the same hash, equal to fresh
Turn 3, resumed at 2,602 hash 32d35900a128, equal to fresh the same hash, equal to fresh
The two kept states 788 MiB 468 MiB

Both 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) and lane_bench.py:

Before This head
One stream, plain, code and chat 62.7 and 63.3 tok/s 62.7 and 63.4
One stream, --drafter 127.3 and 93.1 121.8 and 94.7
The concurrent client's one-stream row, --drafter 127.2 and 95.9 127.1 and 97.8
Four streams, --drafter 283.1 and 231.2 283.1 and 231.1
A 45,246-token prompt 2,417 tok/s 2,417
A 6,905-token prompt beside a decoding stream 3.83 s 3.82 s

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

  • Exactness: every reply above has the hash it had before. 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: hash 4d9062f8e44f before and on this head, drafted and with "draft": false, with the same 73 of 153 drafts accepted.
  • The opener at --context 262144 --parallel 8 --prompt-cache-gib 16 with the drafter: opens the whole window as before, with the same startup line.
  • Licence of any new weights or drafter, or "n/a": n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The wrapped-ring test's last check is written to fail on the slot-order copy; it was not run against it. The device tests skip without a GPU, the real-checkpoint ones without their directories.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (All three on this head.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (None change.)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it. (Against the stack before the move: level.)

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.
sethforprivacy and others added 19 commits November 22, 2026 08:46
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
…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
@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

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.

3 participants