Repository navigation
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
Conversation
|
I tried both chain kernels on M5 Max on exact head For the two kernels outside that suite, I compiled the published
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 |
|
Thank you for running both kernels on an M5 Max, and for the fixtures. Both are now under the contract at
|
|
I reran the registered contracts on 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-limitsThe revision also trial-merges cleanly into Igor Lessio - AIFLOW LABS |
|
Thank you for the rerun. 43 of 43 kernels and 43 controls red on an M5 Max at |
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
3e0e9bc to
f790014
Compare
383c65d to
6af511e
Compare
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
|
… step reads kappa as the FP32 it is
…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
03bb79e to
6ba49f4
Compare
|
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.
|
|
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.
|
|
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. |
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
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.pyit 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 nativecompiles; 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 --checkandgit diff --checkclean; lean 167 on the base and 167 here, 0 new.Update: head
20933682b(two more commits)779dcf11cand20933682bput 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_stepis checked against the registeredtf_ink2_dspark_recurrenton 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 atshapes.tf_ink2_dspark_chain_pickis 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 atshapes.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.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 --offlinebuilds 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 nativecompiles; 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 --checkandgit diff --checkclean; 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.measureandwarm); this does the same for Mini.backend.warmtimes a window of each width from 1 to 16 rows (the second of two runs) andfactspasses them aswindow_costs, for a lone stream only (window_costs_lone).Drafter.measuretimes 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 declaredbatched, 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.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 atf06c27ab1and #4523 applied:--drafter, previous head--drafter, this headbench_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 nativecompiles; 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 --checkandgit diff --checkclean; 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)57f8bc518zscratch fix (e610dc650there), which the next commit needs.84c393292tf_ink2_dspark_chain_pickwrites each step's draft (the first greatest logit) into a small token buffer andtf_ink2_dspark_chain_stepreads 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_stepandtf_ink2_dspark_chain_pickhave no contract record or control. The step istf_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 nativecompiles; the six Inkling host steps exit 0 (dspark_kernels_test.zigcounts each registered symbol once in the source, which is why the chain's kernels are not named aftertf_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 --checkandgit diff --checkclean; 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 atd87e8695dapplied (its concurrent encoder accounts for part of the gain; its description has the split):--drafterbench_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)ec483711dmakes 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 at49e474a55underneath:--drafter, seven drafts a hold (d00306598)--drafter, three drafts a hold (this head)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 --checkclean; the contract run isd00306598's, since this commit changes one constant indspark.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.
3e0e9bcb83, then Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo #4446 (992258230,c68340d31,5ea131a37) and Inkling 2 Mini DSpark on Metal: attention scale 1/sqrt(128), and the recurrent step reads kappa as FP32 #4447 (819edd9bd). This pull request's own commits are1129a91fb(base logits),e4fea4d8d(attention, and the contract pins) andd00306598(comment lengths).atc overlap --json: not run; ATC is not installed on the machine that pushes.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 ofunembed[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 recomputedexp(score - peak) / denominatorfor 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_baseonly: the order of its dot (eight columns a lane a step, thensimd_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 thatfuse_taps,block_qkv,context_kv,swigluandlogitshave. 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
d00306598.zig build native -Dcpu=apple_m1: compiles.dspark_kernels_test.zigpins 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 zigandgit diff --check: clean.zig build test test-goldenon 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
inkling2_loopwith--drafteronly.thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7with itsmtp.safetensors, greedy. The pread cap of checkpoint_metal: clamp pread chunks to INT_MAX #4433 or Metal loader: a checkpoint span of 16 GiB or more loads (each pread capped at 1 GiB) #4435 is applied locally. Measured with the speed commits of 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 underneath.token_sha fb2a08cc6d0fon the Fibonacci prompt before and after both commits). The attention commit leaves the proposals themselves unchanged: the same rounds, drafts and accepts (87, 278, 212 at a short context; 67, 104, 52 after a 9,625-token prompt).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.
tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0, with 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 at49e474a55: plain 46.2 and 46.5 tok/s; with the drafter 67.1 and 64.7. oMLX 0.8.1 with DSpark, same client and machine: 72.5 on the chat prompt.tools/bench_concurrent.py --levels 1,4 --alone --serial: with the drafter 96.9 (code) and 77.5 (chat) tok/s in total, plain 92.0 and 91.2; at Inkling 2 Mini DSpark on Metal: attention scale 1/sqrt(128), and the recurrent step reads kappa as FP32 #4447's head it was 38.1 and 30.5 against 62.4 and 62.9. All 12 replies equal their solo runs. On the chat prompt four drafted streams are still slower than four plain ones: the hold still runs a stream at a time and samples each draft on the host.Checklist
"draft": false, and concurrent equals solo. (A resumed prompt not run.)--drafter, no slower than without it. (Faster than before everywhere measured; four drafted chat streams are still slower than four plain ones.)