Repository navigation
Inkling 2 Mini on Metal: the prompt kernel keeps one set of sums in registers and skips the bias on far tiles (prefill 2,215 to 2,376 tok/s at 45K, same bits) - #4666
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
…to eight rows of a window
…y for up to 16 rows
… the prompt kernel, a tile of keys a chunk
…ps in the scratch, so a stream's cache stages a window only
… cap while replies decode
…s from the cache, with no staging between
…16 weight rows by 32 of an expert's pairs an op
… skips the bias and key tests on far tiles, and loads a query row four values at a time
|
@sethforprivacy the pre-M5 run you asked for on #4387:
The two pre-M5 prompt entries are collected and pass all four gates:
42 kernels rather than your 52 is the count without the M5-only entries on this chip. The Not run: the served hashes (the cold-prompt and decode rows on this stack are queued behind my other GPU jobs and will follow on #4387). I also did not run the fold-into-stored-partial path your description says the contract does not reach. |
|
Thank you, this is the first time the pre-M5 prompt entries have run on a real Mac without tensor units: until now I only had the offline build for M1 to M4. Both entries passing all four gates with their controls red on an M4 Pro at The fold into a stored partial is not reached by the contract on any chip; on the M5 Ultra it is checked by the served hashes at |
|
@sethforprivacy the served hashes on the pre-M5 build, as asked. Same Mac as above (M4 Pro, no tensor units), the stack at this PR's head
The prompts: a 28-token question (16 tokens out), a 416-token prompt (16 out), a 1,916-token prompt (16 out) and a 4,200-token prompt (8 out). So changes 1 and 2 reproduce on the pre-M5 build at both windows. What this does not reach: no prompt here is long enough to fill a 4,096-key chunk several times (the longest is about 4,200 tokens), so the multi-fold path at 262,144 is exercised by one chunk boundary at most; a 16K or longer prompt would be the real check, which I have not run. One observation: the 416-token prompt's hash |
|
Thank you. Identical hashes without and with the commit, at both windows, is what I hoped to see on that build. It reaches more than you credit it with. A chunk is the fewest keys that fit the capacity in 64 slots ( So that path is now checked on the pre-M5 build, which I could not do. I have added your two runs to the description. Two independent implementations giving |
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
|
What this changes
Three changes to
tf_ink2_attn_prompt, none of which changes a sum. A 1,024-row chunk of a 45K-token prompt goes from 442 to 412 ms of GPU time on average, and from 504 to 459 at the prompt's end; the prompt is 2,376 tok/s served where it was 2,215.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, 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: 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: 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 (84ab2c63f). This pull request's own commit is232ee08a3. It touchesprompt_attention.metalonly and needs 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's direct key reads; the rest of the stack is where it was measured.atc overlap --json: not run; ATC is not installed on the machine that pushes.1. One set of sums in registers (442 to 412 ms with the other two in place; the largest of the three). The kernel kept a chunk's folded sums (
out, 64 FP32 values a lane) beside the running ones (acc) through the whole tile loop, though it touches them once every 16 tiles. They now live where they end up, in the chunk's partial slot: the chunk's first fold stores0 * x + acc * y, a later fold reads the slot, folds and stores, and the copy at the end is gone. A lane writes only its own elements. The peak and the mass (four values) stay in registers, since a row's lanes share them.2. No bias read and no key test on a far tile (435 to 430). On a global layer, a tile whose every key is 1,024 or more positions before both of a lane's rows has every key live and no bias, so the 32 table reads and the four tests a key are skipped. The score is still
(score * scale + 0.0f) * LOG2E.3. A query row four values a load (442 to 435). On the M5 layout a fragment's eight values are four columns of two rows, so two
bfloat4loads replace eight single ones a step, as #4645 did for the keys and values.Why I think the registers matter this much. Measured on the way, and left out: loading the query fragments once a chunk instead of once a tile (64 more BF16 values live in a lane) made a chunk 47 ms slower, and hoisting the element loop's per-row arithmetic into two small arrays made it 24 ms slower. Less live state is the direction that helps this kernel; more does not, even when it saves work.
Which bits change. None. Each change keeps the expression it replaces (the first fold multiplies the same zero; the far tile adds the same zero), and every reply below has the hash it had on #4649, including at
--context 262144, where a chunk is 4,096 keys and folds four times.Checks on this head
232ee08a3.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 52 kernels: 52 pass gates 1-4, 0 fail, 0 known findings; 52 controls: 52 red as planted, 0 missed; 0 limit problems, exit 0. The prompt kernel's two M5 entries land where they did on 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 (worst 0.141 and 0.884 of the bound), and their controls stay red.zig fmt --check build.zig zigandgit diff --check: clean.--context 131072and262144below.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). CUDA and HIP are not touched.tf-kernel-contract --only inkling2there gives 42 of 42 kernels and 42 controls red, with both pre-M5 prompt entries passing all four gates, and four served replies have the same hashes without and with this commit at--context 131072and262144, which includes the fold into a stored partial.Receipt
inkling2_loopMetal path: the global layers of every row and the sliding layers of a prompt's rows.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: 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: 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 window's grammar masks step by the padded vocabulary, so a structured reply passes its second row #4635 and Inkling 2 Mini DSpark on Metal: the block attends on the M5 tensor units, so a hold costs the same at any context #4660 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.GPU time of a 1,024-row chunk over a 45K-token prompt,
--context 65536(a development tree that is this stack with timing switches; each row adds one change):Served, one stream, 160 new tokens after a prompt of the given length,
--parallel 1 --context 262144:--drafter, before--drafter, this headServed,
--parallel 4 --prompt-cache-gib 0, TensorFold's clients (256 tokens, greedy, three reps) andlane_bench.py:--drafter--drafter--context 262144and at131072.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. 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. (Against 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: prompts and long-context rounds are faster, the rest unchanged.)