Skip to content

Inkling 2 Mini DSpark on Metal: the block attends on the M5 tensor units, so a hold costs the same at any context - #4660

Draft
sethforprivacy wants to merge 33 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-dspark-units
Draft

sethforprivacy wants to merge 33 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-dspark-units

Conversation

@sethforprivacy

Copy link
Copy Markdown
Contributor

What this changes

Before: a DSpark block's attention scores every kept key of its context on scalar threads and sums the values in key order, so a hold's GPU time grows with the context: 3.6 ms at 276 tokens, 7.2 at 8.4K, 20.9 at 44K. By 44K drafting gains nothing, and after a 92K-token prompt the drafted stream is slower than the plain one (42.4 against 46.0 tok/s).

After, on M5: the block attends on the tensor units, a chunk of its context a threadgroup, and a hold takes 3.4 to 3.6 ms at any of those contexts. Drafted decode after a 92K-token prompt is 85.5 tok/s, after 44K 84.9. Replies are the same, token for token.

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

The two kernels (dspark_units.metal, compiled with the tensor-fragment helpers, loaded only where the GPU has tensor units):

  • tf_ink2_dspark_attn_units: a threadgroup is one key head and one chunk of 256 kept keys. The key head's 24 (row, head) pairs sit in two simdgroups; the scores and the weighted values are tensor products over 64-key tiles read straight from the context ring, with a running peak and mass a pair. It writes a partial a (pair, chunk): 128 sums, the peak and the mass.
  • tf_ink2_dspark_attn_merge: a threadgroup is one (row, head). It scores the block's own eight keys, then folds the chunks' partials in order and rounds once to BF16.

All three drafter layers take them: the two sliding layers over their last 1,024 keys and the global layer over everything kept. The partials live in the score scratch the drafter already holds (scoreBytes is unchanged from 528 tokens of window up, and has a floor below that). Without tensor units the block attends on tf_ink2_dspark_attention as before.

Which bits change. The drafter's own, on M5: a weight is rounded to BF16 before it multiplies a value (as the target's prompt attention does), and the sums run a tile at a time instead of in key order. No reply changes: a draft is a proposal that the target verifies, and every reply below has the hash of its plain run. What can move is how many drafts land. Over the four prompts below the accepted drafts are 104, 103, 95 and 104, where they were 104, 102, 95 and 104.

One change outside the drafter. metal_inkling2_main.zig built its Suites in a local and returned it by value, while every kernel's context already pointed at a probe inside that local. Adding a ninth suite moved the copy enough for the experts' probes to be read from the dead frame (a segfault in their clear). Suites.init now builds the suites where they live. This is in the contract's driver only.

Checks on this head

  • Head commit: 28a0b4638.
  • 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. New there: the span a block reads in whole chunks (dspark_kernels_test.zig), and each control's edit applying once.
    • tf-kernel-contract --only inkling2 (-Doptimize=safe): SUMMARY 45 kernels: 45 pass gates 1-4, 0 fail, 0 known findings; 45 controls: 45 red as planted, 0 missed; 0 limit problems, exit 0. Two of the kernels and two of the controls are new (below).
    • 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, which never load these kernels. CUDA and HIP are not touched.

The contract entries (metal_inkling2_dspark_units.zig). Each output is checked against the softmax in float64 from the BF16 inputs, within a stated bound: 1/64 of the sum of its terms' magnitudes. That is three roundings of 2^-8 (a BF16 weight above the line, the same below it, and the BF16 output) and a fourth for FP32. The kernels land at 0.20 to 0.36 of it.

  • The whole launch, eight shapes: no context; one key; a sliding layer and a first kept position that leave one key; a first kept position inside a tile, so that a tile is skipped and the next starts part way; three chunks with a part tile at the end; a sliding window over 1,025 keys, with and without a first kept position; and a sliding window at 5,000, which wraps its 1,152-row ring. The first and last kept keys are planted to weigh in every sum, and the rows just outside them hold a key that would swamp it if it were read.
  • The fold alone, on planted partials: none, one and five chunks after the block's keys.
  • A NaN in a query makes its pair's 128 outputs NaN and no other pair's.
  • Controls: the context's scores without the log2 factor (red at 52 times the bound), and the fold keeping its earlier mass unscaled (red at 8 times).

Receipt

One stream, greedy, 160 new tokens after a prompt of the given length, --parallel 1 --context 131072:

Prompt Plain --drafter, before --drafter, this head
276 tokens 59.3 tok/s 102.7 105.0
8,436 54.2 85.8 98.0
44,436 52.3 53.5 84.9
92,436 46.0 42.4 85.5

GPU time of a hold (one stream, greedy, the whole chain in one command buffer; a development tree that is this stack with a timing switch):

Context Before This head
276 tokens 3.57 ms 3.36
8,436 7.18 3.48
44,436 20.94 3.62

A chunk of 128, 512 or 1,024 keys instead of 256 gives 3.64, 3.70 and 3.72 ms at 44K, so the width is not a tuning point.

Short prompts, where the change should cost nothing (--parallel 4 --prompt-cache-gib 0, TensorFold's clients, 256 tokens, greedy, three reps):

Before This head
One stream, plain, code and chat 60.5 and 61.1 tok/s 60.6 and 61.2
One stream, --drafter 123.5 and 92.0 124.7 and 93.2
Four streams, --drafter 276.8 and 226.0 278.6 and 227.5
Four streams, --drafter, lane_bench.py 207.9 213.4
A 45,246-token prompt 2,212 tok/s 2,215
  • Exactness: each drafted reply above has its plain run's hash. bench_concurrent.py --alone --serial, four streams: 12 of 12 replies equal their solo runs, plain and with the drafter, and the serial check passes (182 and 147 drafts accepted, where they were 181 and 145). The concurrency check's four replies and a three-turn chat with the prompt cache on and off have the hashes they had before.
  • Peak footprint: 22 GB plain and 23 GB with the drafter, as before.
  • 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 contract entries name kernels that do not exist before; they are collected only where the GPU has tensor units.)
  • 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 the stack with this commit, the resumed prompt with 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 applied.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (The drafter's proposals only, as above; no reply changes.)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it. (With --drafter a stream was slower than without it after a 92K-token prompt; it is now 1.9 times faster there.)

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.
…s; contract pins for the base and attention kernels
…s streams, and one in all when they are greedy
…window costs and a hold timed at load, up to the whole block
…e step against the recurrent kernel and the pick against a scan
@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

@Spectre056

Copy link
Copy Markdown

I can run this one on an M5 Max as well, alongside #4631: Apple M5 Max (40-core GPU), 128 GB, macOS build 26B131, Zig 0.17.0.

Plan: thinkingmachines/Inkling-2-Mini@ed40e7da with --drafter, without and with this commit. Cells: drafted decode after about 44K and 92K-token prompts, the per-hold time if a profile switch reports it, accepted drafts per prompt, and each reply's hash against its plain run.

Same question as on #4631: main plus the stack at your listed heads, or a narrower base? I'll post the results with receipts.

@sethforprivacy

Copy link
Copy Markdown
Contributor Author

@Spectre056 thank you. The same answer as on #4631, with one difference. The base is moving (#4387 is on main and the maintainers are rebasing this stack themselves), so I would wait for the rebased head before spending time on it.

The difference: this PR changes only the drafter. The target verifies every draft, and on the full stack 24 of 24 greedy replies were identical with the drafter's attention on the tensor units, on its scalar kernel and with no drafter (accepted drafts 4,021 of 9,498 against 4,013 of 9,112). So replies do not move here; what the tensor-unit sums change is the drafter's own arithmetic. Whether that passes the bit-equality rule from #4448 is the maintainers' call and has not been said yet. Once there is a head on main to run, I will post it here.

@Spectre056

Copy link
Copy Markdown

Understood, thanks for the detail on the drafter. I'll wait for the head on main and run it when you post it here.

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