Skip to content

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

Draft
sethforprivacy wants to merge 11 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-dspark-speed

Conversation

@sethforprivacy

@sethforprivacy sethforprivacy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Update: head 03bb79ecc (one more commit)

03bb79ecc: the drafter's facts no longer ask for plain rounds (plain_guard = false).

With the guard on, the depth rule may choose a round with no drafts. On the chat prompt of bench_openai.py it did so in 54 of 154 rounds on most server starts and in 2 of 124 on others, with the same reply either way: 71.7 tok/s in the first case and 78 to 80 in the second. The load-time costs are the same on every start (a one-row window 17.0 ms, two rows 19.3, a full hold 4.3), so the difference is the rule's own estimate of a first draft's chance sitting near its line. Here a round with one draft costs about 24 ms against 18 for a plain one, so one draft pays from about a third landing, and the drafter lands 43 to 45 % on that prompt.

Eight fresh starts each way on the chat prompt, one stream: with the guard 71.6 to 71.9 tok/s on seven and 80.0 on one; without it 76.0 to 79.5 on all four tried, and 75.8 to 83.0 on four more with the whole stack. Code and four streams do not change (the rule never chose plain there).

Checks on this head: zig build native compiles; the six Inkling host steps exit 0; tf-kernel-contract --only inkling2: SUMMARY 43 kernels: 43 pass gates 1-4, 0 fail, 0 known findings; 43 controls: 43 red as planted, 0 missed; 0 limit problems, exit 0; zig fmt --check and git diff --check clean; lean 167 on the base and 167 here, 0 new.


Update: head 20933682b (two more commits)

779dcf11c and 20933682b put the chain's two kernels under the contract, as suggested in the review comment below. The "Not registered yet" paragraph further down is superseded by this.

  • tf_ink2_dspark_chain_step is checked against the registered tf_ink2_dspark_recurrent on the same inputs: every byte of its three outputs must equal the recurrent kernel's on the token the buffer holds, including a row with a NaN state. Its control reads the next slot of the buffer, which holds another token, and goes red at shapes.
  • tf_ink2_dspark_chain_pick is checked against a scan of the same 200,058 logits: the first of equal maxima (the fill has few distinct values, so the maximum is tied within a simdgroup and across them), a NaN never picked unless logit 0 is one (a second served row has a NaN at id 0, where the rule picks id 0), both infinities, and the other seven slots of the token buffer left as they were. Its control sends a tie to the later id and goes red at shapes.
  • The two launches moved from the drafter into dspark_kernels.zig (Chain, chainStep, chainPick), so the drafter and the contract launch them through the same code. The step's source now reserves its 256 threads.
  • Records (inkling2_dspark_chain_metal_records.zig): the step at 256 threads, the pick at 1,024 threads with 256 bytes of threadgroup memory. tf-kernel-contract --offline builds both for M1 and M2 at those counts. The launch-map test counts 13 DSpark launches where it counted 11.

Checks on this head: zig build native compiles; the six Inkling host steps exit 0; tf-kernel-contract --only inkling2: SUMMARY 43 kernels: 43 pass gates 1-4, 0 fail, 0 known findings; 43 controls: 43 red as planted, 0 missed; 0 limit problems, exit 0; zig fmt --check and git diff --check clean; lean 167 on the base and 167 here, 0 new. No served number changes: the kernels' text is the same apart from the reservation.


Update: head db534d6cf (one more commit)

db534d6cf: the engine prices a lone stream's drafts, up to the drafter's whole block.

  • What was missing. The backend gave the lanes no window costs and the drafter no step cost, so the depth rule took its fallback for a lone stream: one draft while the first draft lands under 0.8 of the time, two under 0.9, and never more than three. MiniMax M3's DSpark adapter already gives both (measure and warm); this does the same for Mini.
  • What it adds. backend.warm times a window of each width from 1 to 16 rows (the second of two runs) and facts passes them as window_costs, for a lone stream only (window_costs_lone). Drafter.measure times a full greedy hold on an empty context (the third of three runs) and prices a draft at its share (step_ms); the hold is declared batched, which it has been since the previous commit; and a hold may offer the block's seven drafts (it offered three). A shared round keeps three drafts a stream (shared_drafts), so four streams still fill one 16-row window.
  • What I tried for shared rounds and left out. Pricing shared rounds too (the window costs for shared forwards, with shared costs timed at 20 to 32 rows) took four streams on the chat prompt from 183 to about 160 tok/s in total, so shared rounds stay on the default rule.

On the 300-token Fibonacci reply: 87 rounds become 67, 3.45 tokens a round become 4.48, and decode goes from 112.6 to 127 tok/s with the same token_sha.

Served, TensorFold's clients, 256 tokens, greedy, three reps, --parallel 4 --context 16384 --prompt-cache-gib 0, with #4448 at f06c27ab1 and #4523 applied:

fibonacci-raw gpu-chat-no-think 4 streams, code 4 streams, chat
--drafter, previous head 81.4 tok/s 73.7 218.9 total 178.8 total
--drafter, this head 96.6 72.9 223.0 183.6
Plain 52.3 52.7 167.0 166.3
oMLX 0.8.1, DSpark on, same clients not measured 72.5 not measured 126.6

bench_concurrent.py --alone --serial: 12 of 12 replies equal their solo runs at four streams, plain and with the drafter, and the serial check passes (172 and 133 drafts accepted). The chat prompt's one-stream figure moves within its run-to-run spread (72.9 here, 74.0 in the concurrency client's one-stream row).

Checks on this head: zig build native compiles; the six Inkling host steps exit 0; tf-kernel-contract --only inkling2: 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 and git diff --check clean; lean 167 on the base and 167 here, 0 new. Loading takes about a second longer for the 32 timed forwards and three timed holds.


Update: head 84c393292 (two more commits)

Commit What
57f8bc518 #4447's z scratch fix (e610dc650 there), which the next commit needs.
84c393292 A hold is one command buffer a step for all its streams, where each stream took its own command buffers. When every stream of the hold is greedy the whole hold is one command buffer: tf_ink2_dspark_chain_pick writes each step's draft (the first greatest logit) into a small token buffer and tf_ink2_dspark_chain_step reads the previous draft from it, so no logits are read back between steps. Sampled streams keep the host's sampler, a step at a time. Each stream of a hold has its own drafter scratch.

A hold of one greedy stream at depth 3 takes 3.5 ms of wall time here (5 ms at the previous head, 11 ms before this pull request).

Not registered yet: tf_ink2_dspark_chain_step and tf_ink2_dspark_chain_pick have no contract record or control. The step is tf_ink2_dspark_recurrent's body with the token read from a buffer (both call one shared function); the pick is new. Drafts are proposals, so the exactness check is the one below, but say if you want gates for them and I will add them.

Checks on this head: zig build native compiles; the six Inkling host steps exit 0 (dspark_kernels_test.zig counts each registered symbol once in the source, which is why the chain's kernels are not named after tf_ink2_dspark_recurrent); tf-kernel-contract --only inkling2: 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 and git diff --check clean; lean 167 on the base and 167 here, 0 new.

Served, TensorFold's clients, 256 tokens, greedy, three reps, --parallel 4 --context 16384 --prompt-cache-gib 0, with #4448 at d87e8695d applied (its concurrent encoder accounts for part of the gain; its description has the split):

fibonacci-raw gpu-chat-no-think 4 streams, code 4 streams, chat
Plain 55.1 tok/s 55.5 128.2 total 127.2 total
--drafter 78.9 75.6 169.7 total 140.2 total
oMLX 0.8.1, DSpark on, same clients not measured 72.5 not measured 126.6 total

bench_concurrent.py --alone --serial: 12 of 12 replies equal their solo runs at four streams, plain and with the drafter, and the serial check passes (138 and 132 drafts accepted). With the drafter four streams are now faster than without it, and one drafted stream is at 1.04 of oMLX on the chat prompt.


Update: head ec483711d (one more commit)

ec483711d makes a hold offer three drafts where it offered seven. One stream is unchanged, because the host already chose a depth of 1 to 3 there. With several streams the host filled each stream's window to eight rows, so four streams verified 32 rows a round (112 ms here) to land about three tokens a stream. At three drafts a stream, four streams share a round of 16 rows.

tools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0 --levels 1,4 --alone --serial, total tok/s, with #4448 at 49e474a55 underneath:

1 stream, code 1 stream, chat 4 streams, code 4 streams, chat
Plain 46.1 46.5 91.9 91.1
--drafter, seven drafts a hold (d00306598) 67.1 64.6 96.9 77.5
--drafter, three drafts a hold (this head) 67.0 64.7 130.2 107.7
oMLX 0.8.1, DSpark on, same client not measured 69.7 not measured 126.6

Every reply equals its solo run (12 of 12 at four streams) and the serial check passes, at both depths. A sweep with two reps, on a local build that also carries a few launch fusions not in these drafts (so its figures run a little above the table's): a cap of 2 gives 123.6 and 111.2 at four streams and 144.0 and 128.8 at eight; 3 gives 136.6 and 112.7 at four and 136.0 and 112.9 at eight; 4 gives 129.4 and 105.7 at four; 5 gives 125.8 and 100.9. So three is the best single value at one and four streams, and two is better at eight, where four rows a stream fill the forward's 32. This is a fixed cap, not the recipe's depth rule: it is the smallest change that stops drafting from costing throughput across streams, and I expect you to replace it.

With the drafter, four streams are now faster than four plain ones on both prompts, which they were not at d00306598. Checks on this head: the Inkling host steps exit 0, lean 167 and 167 with 0 new, zig fmt --check clean; the contract run is d00306598's, since this commit changes one constant in dspark.zig.


What this changes

Before: one DSpark hold takes about 11 ms on an M5 Ultra, and 26 ms with 10K tokens of context, because its base logits and its attention are computed a thread at a time. After: about 5 ms and 8 ms. Drafted output still equals plain, and the proposals are the same ones.

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

The two kernels:

  • tf_ink2_dspark_base. It ran one thread a (row, id) with a 2,304-step serial dot, for all seven mask rows, so a hold read the unembedding seven times. Now a simdgroup is one id, eight columns a lane a step, every requested row sharing the read of unembed[id]; and the hold asks only for the rows it will draft (depth), for the base logits and for kappa.
  • tf_ink2_dspark_attention. One thread of each (row, head) group scored every retained key serially, and every thread recomputed exp(score - peak) / denominator for every key. Now thread t scores keys t, t + 128, ..., the exponentials and the weights are computed once by all 128 threads, and one thread still adds the denominator in key order. Each value sum is in key order as before.

Which bits change. tf_ink2_dspark_base only: the order of its dot (eight columns a lane a step, then simd_sum, where it was one column-order sum). The contract compared it byte for byte with a serial FP32 sum, which no lane-parallel sum can match, so its check now has the 0.02 relative bound that fuse_taps, block_qkv, context_kv, swiglu and logits have. I changed that bound after seeing the gate fail; say if you would rather pin the kernel's order in the reference. The attention kernel computes the same values in the same sums, and the proposals did not change (below).

Checks on this head

  • Head commit: d00306598.
  • 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: exit 0 (dspark_kernels_test.zig pins the attention kernel's 528 bytes of threadgroup memory).
    • 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. The base control's anchor follows the new source.
    • 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 exact 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.

Receipt

Before After
Hold at depth 1, 2, 3, short context 10.0, 10.7, 11.4 ms 4.0, 5.0, 5.7 ms
Drafted decode, Fibonacci prompt, 300 tokens 67 tok/s 86 tok/s
Hold after a 9,625-token prompt 25.7 ms 7.6 ms
Drafted decode after that prompt, 120 tokens 31.8 tok/s 46.6 tok/s

The first two rows are #4447's kernels against both commits; the last two are the base-logits commit alone against both, so they show the attention commit.

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. (No new test; the existing contract probes cover both kernels.)
  • 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, and concurrent equals solo. (A resumed prompt not run.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (One draft-only sum's order changes, and its contract bound with it, as above.)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it. (Faster than before everywhere measured; four drafted chat streams are still slower than four plain ones.)

@sethforprivacy sethforprivacy changed the title Inkling 2 Mini DSpark on Metal: the hold's base logits and attention on every thread (11 to 5 ms a hold on M5 Ultra) Inkling 2 Mini DSpark on Metal: the hold's kernels on every thread, and three drafts a hold (4 streams 77 to 108-130 tok/s on M5 Ultra) Nov 22, 2026
@sethforprivacy sethforprivacy changed the title Inkling 2 Mini DSpark on Metal: the hold's kernels on every thread, and three drafts a hold (4 streams 77 to 108-130 tok/s on M5 Ultra) Inkling 2 Mini DSpark on Metal: the hold on every thread and in one command buffer, three drafts a hold (4 streams 77 to 140-170 tok/s on M5 Ultra) Nov 22, 2026
@sethforprivacy sethforprivacy changed the title Inkling 2 Mini DSpark on Metal: the hold on every thread and in one command buffer, three drafts a hold (4 streams 77 to 140-170 tok/s on M5 Ultra) 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) Nov 22, 2026
@AIFlowML

Copy link
Copy Markdown
Contributor

I tried both chain kernels on M5 Max on exact head db534d6cfda15a8201b41e06dde5d0a9c62f634d. The six Inkling host targets passed 134 checks with eight skips. tf-kernel-contract --only inkling2 passed all 41 kernels and caught all 41 controls.

For the two kernels outside that suite, I compiled the published dspark.metal in a scratch Swift/Metal harness with the runtime's math and language options:

  • Pick: One 1,024-thread group over 200,058 logits matched a CPU first-maximum scan in seven cases, including cross-group ties, first versus later NaNs, infinities, signed zero and the last vocabulary entry. The other held-token slots stayed intact.
  • Step: In one serial encoder, the chain step read the token written by pick and matched the direct recurrent kernel across all 1,280 BF16 outputs. Running the direct reference with a deliberately different token produced different bytes.

I'd add both to the contract suite. The cross-group tie and guarded output slot make a good pick fixture, and the wrong-token case gives the recurrent fixture a control. These are synthetic kernel checks. I didn't rerun the served checkpoint or depth-pricing measurements.

Igor Lessio - AIFLOW LABS

@sethforprivacy

sethforprivacy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you for running both kernels on an M5 Max, and for the fixtures. Both are now under the contract at 20933682b:

  • the step against the registered recurrent kernel on the same inputs, byte for byte, with the wrong-slot token as its control;
  • the pick against a scan, with ties within and across simdgroups, a first versus a later NaN, both infinities and the other slots guarded, with a later-id tie as its control.

tf-kernel-contract --only inkling2 on an M5 Ultra: SUMMARY 43 kernels: 43 pass gates 1-4, 0 fail, 0 known findings; 43 controls: 43 red as planted, 0 missed; 0 limit problems. The offline build gives both for M1 and M2 at their thread counts (256 and 1,024). The description has the details.

@AIFlowML

Copy link
Copy Markdown
Contributor

I reran the registered contracts on 20933682bc3533922185e402a8c173f8f72bc2f7 on M5 Max. All 43 kernels passed gates 1–4, and all 43 planted controls fired. The chain step matched the recurrent kernel byte for byte and caught the wrong-slot token. The chain pick matched the scan in both shapes, including the new NaN-at-token-zero case, and caught the later-ID tie control.

zig build tf-kernel-contract test-inkling2-metal-host test-inkling2-controls-host compile-inkling2-native-host -Dcpu=apple_m1 -Doptimize=safe -j3 --summary all
zig-out/bin/tf-kernel-contract --only inkling2 --no-limits

The revision also trial-merges cleanly into lead/inkling2-mini at 3e0e9bcb. These checks cover the M5 Max output contracts. Launch limits and served checkpoints remain unverified in this run.

Igor Lessio - AIFLOW LABS

@sethforprivacy

Copy link
Copy Markdown
Contributor Author

Thank you for the rerun. 43 of 43 kernels and 43 controls red on an M5 Max at 20933682b is the same summary I got on an M5 Ultra there, so the chain step and pick fixtures now hold on two chips. The head has moved one commit since (03bb79ecc, no plain rounds beside the drafter); it does not touch either kernel, and its contract summary is the same 43 and 43.

gilby added a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
Integrate PR ashhart#4699's DSpark kernel, weight-packing, online-softmax multi-stream
attention, batched GPU chain sampling, host SIMD draw, and shared depth pricing
optimizations cleanly onto ashhart#4465 (03bb79e):
- Transpose folded phi ([256, 201024]) and load-time split/transposed RNN
  weights (rnn_kappa, rnn_rec) for coalesced GPU loads.
- Replace score-buffer DSpark attention with zero-scratch 768-thread online
  softmax with M5 tensor-unit and TF_SIMD_FRAGS=1 pre-M5 paths, plus tiled
  base and two-stage group softmax/argmax logits.
- Wire batched multi-stream absorb/hold, chances with softmax reach, two-pass
  GPU top-k sampling, host SIMD top-k/greedy draws, and shared-batch target
  pricing while preserving ashhart#4465 invariants (DSP_SCALE, FP32 kappa,
  plain_guard = false, dspark.warm/measure, and firstLogprobRow).

Refs ashhart#4652
@ashhart
ashhart force-pushed the lead/inkling2-mini branch 2 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

@ashhart
ashhart force-pushed the inkling2-mini-metal-dspark-speed branch from 03bb79e to 6ba49f4 Compare November 24, 2026 11:50
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @sethforprivacy. The SIMD base projection changes draft logits only, and the target still verifies every proposed token. The two earlier drafter fixes are included.

Two fixes remain: charge the extra per-stream scratch to admission, including the memory retained after streams close; and give the new contract probes stable addresses through the gate pass. They currently register pointers into a suite that is then returned by value. Current-tree Metal serving and memory checks remain needed; the earlier speed results included other target changes.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @sethforprivacy. The two earlier drafter fixes are now on main, and the remaining chain code is unchanged from the last review. Target verification still protects every proposal.

The standalone branch still needs the retained per-stream scratch charged to admission and stable addresses for its chain contract probes. The overhaul includes the chain changes and replaces both problem areas, so a combined landing should preserve those repairs rather than reintroduce the old implementations. Current-tree serving and memory qualification remain needed.

  • Synthena

@sethforprivacy

Copy link
Copy Markdown
Contributor Author

Thank you for the rebase and both reviews. One question so I do the right work: would you like the two repairs on this branch as it stands (the retained per-stream scratch charged to admission, and the chain's contract probes built where they live, as #4660's driver change does), or would you rather this chain land through the overhaul, with nothing more done here? I'm glad to make both repairs on your rebased head and rerun the serving and memory checks on current main; I have held off only so as not to repair code the combined landing replaces.

gilby added a commit to gilby/TensorFold that referenced this pull request Nov 25, 2026
Integrate PR ashhart#4699's DSpark kernel, weight-packing, online-softmax multi-stream
attention, batched GPU chain sampling, host SIMD draw, and shared depth pricing
optimizations cleanly onto ashhart#4465 (03bb79e):
- Transpose folded phi ([256, 201024]) and load-time split/transposed RNN
  weights (rnn_kappa, rnn_rec) for coalesced GPU loads.
- Replace score-buffer DSpark attention with zero-scratch 768-thread online
  softmax with M5 tensor-unit and TF_SIMD_FRAGS=1 pre-M5 paths, plus tiled
  base and two-stage group softmax/argmax logits.
- Wire batched multi-stream absorb/hold, chances with softmax reach, two-pass
  GPU top-k sampling, host SIMD top-k/greedy draws, and shared-batch target
  pricing while preserving ashhart#4465 invariants (DSP_SCALE, FP32 kappa,
  plain_guard = false, dspark.warm/measure, and firstLogprobRow).

Refs ashhart#4652

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