Repository navigation
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
Conversation
3e0e9bc to
f790014
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
|
|
I can run M5 Max numbers for this, a narrower M5 tier than your M5 Ultra: Apple M5 Max (40-core GPU), 128 GB, macOS build 26B131, Zig 0.17.0. Plan: One question: should I run it on |
|
@Spectre056 thank you, M5 Max rows would be useful, but I would hold off for now, for three reasons.
If the maintainers say there is a form of this they would take, I will post the base to run on here, and your numbers would be the first on an M5 Max. |
|
Understood, I'll hold for the rebased head. For reference, I had already run this on the stack at its listed heads before your note: head
Short-prompt decode was level (48.3 against 48.3 tok/s chat, 49.8 against 49.9 code), and each arm gave one |
…in the fewest 1,024-key folds a slot
…uffers, independent launches side by side
… a row's sums never depend on its chunk
…mdgroup folds the partial sums itself
…de between a prompt's chunks
…y for up to 16 rows
… the prompt kernel, a tile of keys a chunk
2d7a9c9 to
c375a66
Compare
|
@Spectre056, thanks for waiting. You offered on 25 Nov to rerun once this sat on
|
|
Thanks @sethforprivacy. #4631 is #4618 plus two commits, and both replay cleanly onto today's main. Both change what a prompt's rows compute on GPUs with tensor units. Decode rows are unchanged, and so are GPUs without tensor units. Exactness
Tests
Both are good correctness checks, but neither compares with main's bits. Note also that the pre-M5 sliding prompt variant in the contract tests a configuration the server never takes: the tiled route requires tensor units. Repo checks we ran on the rebased branch:
The M5 check we'd like to see, main against this branch at default settings:
|
|
Thanks, Ash. I reran the requested head Both builds were unpatched and used
At 44K, prefill improved 30.4% with drafting off and 30.3% with drafting on. Baseline TTFT there was 65.535 s off and 65.825 s on. With DSpark, short code wall time on the head went from 7.453 s to 4.288 s. Draft-on and draft-off emitted identical token arrays in all 12 pairs on each build. Baseline-to-head token arrays differed for all five prompts in both modes, consistent with the prompt arithmetic change described here. Draft-off recorded zero proposals. On the head, the draft-on counters recorded 1,478 accepted out of 3,917 proposals, which can include copy proposals. An SSH disconnect interrupted the baseline run. I kept its 11 completed measurements and collected the remaining 13 after fresh warm-ups. I have the raw per-request timings, full token hashes, and build provenance available if useful. |
|
@sethforprivacy No worries. I didn't see your post and closure before running, so its there anyways for posterity, I suppose. :) |
What this changes
Before: a prompt's rows run the same kernels as a round's rows, except global attention. A 256-row chunk spends half its time in the seven projections of a visit on the shared matvec, and at any real context a quarter in the sliding layers' scalar attention. After, on a GPU with tensor units, two commits:
3ebdde760: a prompt's rows take their projections on the tensor units. A 256-row chunk at 2K tokens of context goes from 251 to 163 ms.2d7a9c90c: a prompt's rows take the sliding layers' attention on the prompt kernel that the global layers already use, a tile of 64 keys a chunk. That chunk goes to 127 ms.A 45K-token prompt goes from 906 to 1,634 tok/s. Decode is not touched: a round's rows keep their kernels.
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: fill a prompt a chunk a call, so other streams keep decoding (a reply's longest stall beside a 32K fill 36.3 s to 0.4 s) #4608 and 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 (ad3d31f9f). This pull request's own commits are3ebdde760and2d7a9c90c.atc overlap --json: not run; ATC is not installed on the machine that pushes.The rule that keeps replies exact. In #4523 I wrote that a kernel may only replace another at every width, because choosing a kernel by a chunk's width made a reply depend on how its prompt was cut. That was too strong. What a reply needs is that every prompt row takes one kernel and every round row takes one kernel; the two may differ. Here the choice is made by the caller, never by the width: the prompt pass sets
Options.prompt, and a one-row prompt chunk takes the same kernels as a 256-row one. So:token_shaat 64, 33, 16, 7 and 1 rows a chunk (measured on this head with a debug switch for the chunk size that is not in the diff), and a 44K-token prompt gives one at 256, 512 and 1,024 rows a chunk in a development tree with the row limits raised;3ebdde760, the projections.tf_ink2_dense_unitsis #4523's construction for a BF16 weight: a threadgroup is 32 outputs against 16 rows, eight simdgroups each sum an eighth of the columns 16 an op, and the eight partial sums are added in order. It takes 2,304 or 3,072 columns, which are the six input projections andwo.projectinforward.zigsends a prompt's rows there and a round's rows todense, as before.2d7a9c90c, the sliding layers.tf_ink2_attn_promptgains a window: a row's keys are those within it, a block skips the chunks before its first row's window, and a row's partial slots count from its own window's first chunk, which is wheretf_ink2_mergealready reads them for a sliding layer.PromptArgsgainswindow(0 for a global layer, as every caller so far). On a sliding layer the prompt path uses 64-key chunks, one tile each, so a row has at most 17 slots. The decode path keeps the scalar kernel and its 32-key chunks. GPUs without tensor units keep the scalar kernel for prompts too: I could not measure the pre-M5 prompt kernel on a sliding layer, so the forward does not select it there.Which bits change. For a prompt's rows only: the order of each projection's sum, and on sliding layers the attention's arithmetic, which becomes the prompt kernel's (P rounded to BF16 at each tile's maximum) where it was the scalar kernel's. Replies to a given prompt therefore differ from #4618's; rounds after the prompt compute as before.
Checks on this head
2d7a9c90c.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 48 kernels: 48 pass gates 1-4, 0 fail, 0 known findings; 48 controls: 48 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, where the forward selects nothing new. CUDA and HIP are not touched.Receipt
ad3d31f9fagainst this head.inkling2_loopMetal path, prompt rows.thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7,--parallel 4 --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, 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 and 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 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. Two CI virtual machines were building on the same host during the served runs.GPU time of one 256-row prompt chunk, by where in a 44,424-token prompt it falls:
3ebdde760With the attention left out a chunk takes 94 ms at every context, so what grows is the global layers' attention, and at 44K attention is again nearly half of a chunk.
Served,
lane_bench.pyand the other clients as in #4618:--drafter--drafteroMLX 0.8.1 does 2,628 to 2,895 tok/s on the 45K-token prompt on this machine, so the prompt path is at about 60 % of it, from a third.
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 (181 and 153 drafts accepted). A three-turn chat gives the same hashes with the prompt cache on and off (turns 2 and 3 resumed at 2,560 tokens). The chunk sizes are above.exp2in the prompt kernel (the exponentials are 3 ms of a 178 ms chunk). Chunks of 512 and 1,024 rows are 11 and 18 % faster again with the row limits raised, at the cost of a convolution staging buffer that grows with the chunk for every stream; that is not in this pull request.Kernel contract
metal inkling2 units tf_ink2_dense_units(zig/tests/contract/metal_inkling2_dense_units.zig): noreplaces, as its sums take another order thansp_matvec's. It is checked against a float64 dot of the BF16 values at 1, 8 and 20 rows (20 crosses a 16-row band), at 64, 24 and 90 outputs (24 and 90 leave the last tile part full) and at both widths.metal inkling2 prompt m5 sliding tf_ink2_attn_promptand its pre-M5 twin, in the attention probe: the prompt kernel on a sliding layer of 64-key chunks against the probe's float64 attention, with a window that starts inside a tile (8 rows ending at position 1,099), one that wraps the 2,048-row ring (64 rows ending at 2,048) and one not yet full (64 rows ending at 79). The pre-M5 twin is collected only on a GPU without tensor units; the forward does not take that path there, as said above.shapes.SUMMARYline and exit status: Metal,tf-kernel-contract --only inkling2, M5 Ultra: the line above, exit 0. The sliding entry's shapes are within 0.884 of the float64 bound at worst.tf_ink2_dense_units256 threads, reserved, 16,384 bytes of threadgroup memory,offline = false. The prompt kernel's record is the one it had.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: a round's logits in one pass of the vocabulary (one drafted stream 106 to 123 tok/s, four streams 237 to 281) #4618: prompts are faster; decode is unchanged within the noise of a host that was also building.)