Repository navigation
Inkling 2 Mini DSpark on Metal: the block attends on the M5 tensor units, so a hold costs the same at any context - #4660
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.
… step reads kappa as the FP32 it is
… rows where prep wrote them
…ws the hold drafts
…s; contract pins for the base and attention kernels
…are a round of 16 rows
… ranks the kernel writes
…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
…t draft pays from a third landing
… of its context a threadgroup, so a hold costs the same at any context
aefb063 to
c41911e
Compare
|
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
|
|
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: Same question as on #4631: |
|
@Spectre056 thank you. The same answer as on #4631, with one difference. The base is moving (#4387 is on 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 |
|
Understood, thanks for the detail on the drafter. I'll wait for the head on |
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.
3e0e9bcb83, then 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 and 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 (03bb79ecc). This pull request's own commit is28a0b4638.atc overlap --json: not run; ATC is not installed on the machine that pushes.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 (
scoreBytesis unchanged from 528 tokens of window up, and has a floor below that). Without tensor units the block attends ontf_ink2_dspark_attentionas 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.zigbuilt itsSuitesin 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 theirclear).Suites.initnow builds the suites where they live. This is in the contract's driver only.Checks on this head
28a0b4638.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. 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 zigandgit diff --check: clean.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). 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.Receipt
inkling2_loopwith--drafter.thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7. The served rows are 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, 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 and 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 at their current heads, Metal loader: a checkpoint span of 16 GiB or more loads (each pread capped at 1 GiB) #4435 applied), without and with this commit.One stream, greedy, 160 new tokens after a prompt of the given length,
--parallel 1 --context 131072:--drafter, before--drafter, this headGPU 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):
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):--drafter--drafter--drafter,lane_bench.pybench_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.Checklist
"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.)--drafter, no slower than without it. (With--draftera stream was slower than without it after a 92K-token prompt; it is now 1.9 times faster there.)