Repository navigation
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
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.
… rows where prep wrote them
…in the fewest 1,024-key folds a slot
…up to 32 rows is one launch
…s and enable gpu_tokens Preserve ashhart#4618's exact dot-product, BF16 rounding, and softcap30 summation order in both tf_inkling2_logits (glue.metal) and tf_ink2_logits_units (experts_units.metal). Add LogitMode (.logits, .argmax, .both), Stage-1 per-tile reduction, and Stage-2 tf_inkling2_reduce_argmax matching exact firstGreatest tie-breaking and NaN-at-0 semantics while skipping unread f32 logits DRAM stores when mode == .argmax. Enable gpu_tokens = true with async GPU-resident decode queueFn, shared token/flight metadata rings, mixed/pure verify batch planning, updated launch records, host unit tests, and contract argmax probes + planted tie-order controls for both glue and tensor-unit logits kernels. Refs ashhart#4652
…atch_rows=64 Rebase PR ashhart#4596 onto ashhart#4618 with 0-ULP sliding attention parity (192-thread GQA 3:1 KV sharing, up to 8-stream slots), batched prepSlots/relTable/merge across all 48 visits, exact ashhart#4618 prompt_attention on the 8 global visits, and batch_rows=64. Refs ashhart#4652.
|
Thanks @sethforprivacy. We read this against its base and have one thing to settle before the rest of the Inkling 2 Mini stack. On tensor-unit Macs, Could you add a direct comparison of the full FP32 logits and the BF16 result from both kernels, on adversarial and served shapes at 1, 8, 16 and the largest admitted rows? If any byte differs, please keep the scalar reduction on this path, because our bar is that every output bit stays the same. We haven't run this on a device yet.
|
|
Done, and the bytes differ. The numbers first, then one question before I change the branch. The comparison. Both kernels through their host launches ( It is a device test, Served shape. The checkpoint's unembedding (200,058 vocabulary rows) against the final-norm rows of a 256-token prompt (tap 48, the kernel's input): its last 1, 8, 16 and 256 positions.
Nine sums in ten differ in their last bits (the largest gap at 256 rows is 0.00012), and at 256 rows 0.018 % of the logits land on the other side of a BF16 rounding (0.015 % at one row). The largest gap between two BF16 results is 0.125, one BF16 step for a logit between 16 and 32, and 0.095 after the cap. Of the 9,182, 439 are more than one BF16 step apart: those are logits next to zero, where the sums' own gap spans several steps, and the widest of them is 0.000006. Adversarial fills, 256 rows. The rows at 1, 8 and 16 show the same thing at their size.
The large gaps in the two wide fills are single BF16 steps of large sums; where the cap has flattened both values the served logits agree, which is why fewer of those differ. A row of NaN is the same bytes from both kernels. Served replies. This head built twice, differing only in which kernel The question. By your bar the scalar reduction stays here. Before I change the branch: the same will hold under this PR and above it. #4523 (the experts' products), #4631 (a prompt's projections and sliding attention) and #4660 (the drafter's attention) put their sums on the tensor units as well, and each description says which sums change. I have not run this comparison on those yet, but I expect the same result, since the tensor op adds a tile's products in an order no scalar loop here reproduces. Most of the M5 speed in this stack is in those kernels. Which would you like?
I'll make the revert here as soon as you say 1 or 3, and I can run the same comparison on #4523, #4631 and #4660 in the meantime if that helps you decide. |
|
The same comparison on the other tensor-unit paths, as offered above. It is not the result I expected. The kernels differ from their scalar twins about as the logits do, but the model amplifies that, and most long greedy replies change. How. Two commits on #4631's head, which has #4523, #4618 and #4631: 1. The kernels on the same buffers, 256 rows, a prompt's final-norm rows as input. The rows at 1, 8 and 16 are in the test's output and show the same rates.
2. A whole 256-token prompt, each path on alone against every path off. Hidden rows at the four tap visits, 589,824 BF16 values each, then 64 greedy tokens.
3. Served: replies that differ from every path off, of 24.
With #4660 the accepted drafts move (4,021 of 9,498 against 4,013 of 9,112) and no reply does, since the target verifies every draft. Where replies differ, both read as the model's: they run together for a dozen or more tokens and then take another wording. 4. One more row, because it bears on the choice. #4387 has a pair of this kind already: What I take from it.
So the question above is the same, with numbers in place of my expectation: on a GPU with tensor units, is the reference the scalar kernels' output, or is it that GPU's own path taken once? I will not change a branch until you say. |
3e0e9bc to
f790014
Compare
…ed figures; the engine receipt moves to ink mac engines
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
|
…mac-beat-4618-on-m5-ul Inkling 2 Mini on Mac: beat ashhart#4618 on M5 Ultra, starting with DSpark's hold cost
…eal speed, not a void run The void premise was wrong: ashhart#4618's 123/281 tok/s is sethforprivacy's stack that card 210 took, none of it on main; main's routed experts decode ~1.16 s a round by design (serial scalar dots, one threadgroup a row and route), and the server log shows the steady latency signature. bench.sh gains the guard: a MIN_TPS floor per cell plus PARTNER_JSON so a second control aborts when it runs over 2x under its partner; controls pair, never against the candidate. Control runs take TOKENS=32 to fit timeout 600.
What this changes
Before: a round's logits cost a pass of the 922 MB output matrix for every row. A verify window of eight rows spent about 11 ms of its 32 ms there, and a shared round of four streams the same for its four rows. After, two commits:
5712db321: the logits kernel takes a vocabulary row for up to eight rows of the window, so the matrix is read once. Same bits. An eight-row window goes from 31.9 to 26.6 ms.ad3d31f9f: on a GPU with tensor units the logits run on them, one pass of the vocabulary for up to 16 rows, at about 1.0 ms whatever the width. An eight-row window goes to 24.8 ms.Served on the whole stack: one drafted stream 106 to 123 tok/s on the code prompt and 79 to 92 on the chat prompt; four streams 237 to 281 and 188 to 223 drafted, 182 to 215 plain. Every reply is the same as before.
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 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, 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 and 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 (530fca3f5). This pull request's own commits are5712db321andad3d31f9f. The first needs none of the stack and could be taken alone; the second needs 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's tensor-unit source.atc overlap --json: not run; ATC is not installed on the machine that pushes.5712db321, one read of the matrix.tf_inkling2_logitswas a thread a (vocabulary row, row of h): 2,304 products added in order, and the vocabulary row read again by every row's thread. A thread now takes a vocabulary row for up to eight rows of h (thread_position_in_grid.ycounts groups of eight) and keeps eight sums, each still adding its products indorder with contraction off, so every logit has the bits it had. The kernel's contract entry and control are the ones it had; the entry's widest shape goes from 7 rows to 11 so that it crosses a group.ad3d31f9f, the tensor units.tf_ink2_logits_unitsis built like #4523's expert kernels: a threadgroup is 32 vocabulary rows against 16 rows of h, each of its eight simdgroups sums an eighth of the 2,304 columns 16 an op (BF16 operands, FP32 sums), the eight partial sums are added in order, and the result is rounded to BF16 and capped at 30 as before. It runs at every width, one row included, so a row's logits do not depend on the rows beside it. GPUs without tensor units keep the first commit's kernel.Which bits change. With the second commit, the order of each logit's 2,304-term sum, before its BF16 rounding. No reply changed in any run here: the test reply below, the twelve replies of the concurrency check and the three-turn chat all give the hashes they gave on #4608.
Checks on this head
ad3d31f9f.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.tf-kernel-contract --only inkling2(-Doptimize=safe):SUMMARY 46 kernels: 46 pass gates 1-4, 0 fail, 0 known findings; 46 controls: 46 red as planted, 0 missed; 0 limit problems, exit 0.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 take the first commit's kernel. CUDA and HIP are not touched.Receipt
530fca3f5against this head.inkling2_loopMetal path, every round (the second commit: Macs with tensor units).thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7,--parallel 4 --context 16384 --prompt-cache-gib 0. The served rows have 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 and 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 at their current heads and Metal loader: a checkpoint span of 16 GiB or more loads (each pread capped at 1 GiB) #4435's read cap applied.GPU time of a verify window, the means over one drafted reply of 256 tokens (the same reply on all three,
token_shab4fcf236afd2):5712db321The logits launch by itself, timed by repeating it four times in those windows: 1.6 ms at four rows and 2.8 at eight with the first commit, 0.9 and 1.0 with the second. A one-row forward takes 15.5 ms with either.
Served, TensorFold's clients, 256 tokens, greedy, three reps:
--drafter--drafterbench_concurrent.py --alone --serial, four streams: 12 of 12 replies equal their solo runs, plain and with the drafter, and the serial check passes (181 and 147 drafts accepted). A three-turn chat gives the same hashes with the prompt cache on and off.Kernel contract
metal inkling2 units tf_ink2_logits_units(zig/tests/contract/metal_inkling2_logits_units.zig). It declares noreplaces: its sums take another order thantf_inkling2_logits', so it is checked against the same float64 dot, BF16 round and cap, at 1, 8 and 20 rows (20 crosses a 16-row band) and at 64, 90 and 32 vocabulary rows (90 leaves the last tile part full, where the kernel reads the last row again and stores nothing for it).shapes.SUMMARYline and exit status: Metal,tf-kernel-contract --only inkling2, M5 Ultra: the line above, exit 0. The new entry alone: non-finite classes equal float64's, five runs byte-identical with guards intact, 12 shapes within the bound, and the sums gate at k 2,304.inkling2_units_metal_records.zig): 256 threads, reserved; 16,384 bytes of threadgroup memory;offline = false, as for the other tensor-op kernels.tf_inkling2_logitskeeps its entry, its control and its record; its shapes gate now runs 1, 5 and 11 rows.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (All three on this head, 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. (Against 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: one plain stream and prompts are unchanged, everything else is faster.)