Skip to content

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

Draft
sethforprivacy wants to merge 34 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-speed
Draft

sethforprivacy wants to merge 34 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-speed

Conversation

@sethforprivacy

@sethforprivacy sethforprivacy commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Update: head cca30e890 (two more commits)

How these were found. I repeated one small stage ten extra times a visit and timed a one-row forward, which gives each stage's cost by itself. On this GPU a launch costs from 2 to 28 µs depending on what its threads do, far more than its arithmetic: a copy 2.0 µs, the norm 8.1, each of the gates' three launches 6.6, the router's two together 17.8, the attention's partial sums 19.1, the depth mix 21.7 and the experts' combine 27.8. A thread here runs a serial step slowly, and strided single-value loads slowly; the two worst stages were both long serial loops.

Commit What Bits
7045ba3b3 The depth mix (tf_inkling2_ar): a thread reads four consecutive values of each source (it read nine values 256 apart), 576 threads a threadgroup, and each of the 18 simdgroups folds the partial sums itself, so the two sections one thread ran alone are gone. 21.7 to 7.5 µs a launch, twice a visit. Changed: the order of the mix's two reductions, the norm's sum of squares and the query dot. Every rounding point is where it was.
cca30e890 The combine (tf_ink2_combine): the first topk threads of a threadgroup rank the token's routes once, and each output adds its terms in that order; every output thread used to rank them again, 512 loop steps each. 27.8 to 5.1 µs a launch. Unchanged: the terms and their order (ascending expert, an equal expert by slot) are the same.

Contract: tf_inkling2_ar keeps its entry and passes its gates with its control red; its record is now 576 threads, reserved, and 720 bytes of threadgroup memory, and tf-kernel-contract --offline builds it for M1 and M2 at 576 threads. tf_ink2_combine passes its exact ascending-expert check; its control now plants slot = r in the new loop, and its record carries the 128 bytes of the routes' order.

GPU time of one forward on this pull request's own path (without #4523), cache empty: one row 16.1 to 14.0 ms, 16 rows 49.4 to 47.2, 64 rows 138 to 134.

Served, TensorFold's clients, 256 tokens, greedy, three reps, --parallel 4 --context 16384 --prompt-cache-gib 0, with #4447, #4465 at db534d6cf and #4523 applied:

fibonacci-raw gpu-chat-no-think 4 streams, code 4 streams, chat
Plain 59.5 tok/s 59.9 182.8 total 181.6 total
--drafter 100.4 79.3 237.8 189.1
oMLX 0.8.1, DSpark on, same clients not measured 72.5 not measured 126.6
oMLX 0.8.1, DSpark off, same client not measured 54.9 not measured not measured

bench_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 (170 and 109 drafts accepted).

Against the bar on this machine, on the prompt both servers were timed on: one stream is at 1.09 of oMLX with the drafter and 1.09 without it, and four drafted streams are at 1.49. The prompt path is still short: 702 tok/s on a 45K-token prompt against oMLX's 2,628 to 2,895.

Checks on this head: zig build native compiles; 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 --check and git diff --check clean; lean 167 on the base and 167 here, 0 new.


Update: head f06c27ab1 (one more commit)

f06c27ab1: a greedy row with no token mask is picked sixteen logits a step. The backend's draw scanned the 200,058 logits of each verify row one at a time, 1.3 ms a round at four rows; the new pick takes the maximum sixteen at a time and then finds its first index, 0.1 ms a round. The pick is the scan's: the first of equal maxima, and a NaN only when logit 0 is one; a unit test compares the two on rows with equal maxima, NaNs, both infinities and zeros of both signs. Rows with a token mask and sampled rows are untouched. On the 300-token Fibonacci reply the token_sha is unchanged and decode goes from 108.1 to 112.8 tok/s (measured with #4523 applied). The tables below were taken before this commit.

Checks on this head: zig build native compiles; 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 --check and git diff --check clean; lean 167 on the base and 167 here, 0 new.


Update: head d87e8695d (two more commits)

The numbers in this section replace the earlier ones where they overlap.

Commit What Bits
e4f793b1d The routed experts run grouped from eight rows (was four): below that the ungrouped kernels are as fast, and a verify window of two to four rows stays on them. A projection of up to 32 rows is one launch of the next register width, where three rows were a two-row launch and a one-row launch. Unchanged
d87e8695d The forward runs on a concurrent encoder, with a barrier after every step a later launch reads. Launches between two barriers are independent and run side by side: a visit's six input projections, its three norms, the three attention roles' gates (loop.gatesEach, a step at a time), and every stream's attention (attention.partials and attention.merge, so all streams' partial sums run before any merge). The forward is also cut into five command buffers, each committed once encoded, so the GPU starts while the host encodes the rest. Unchanged

How d87e8695d was checked for missing barriers: every scratch buffer and all 49 per-visit states of a 64-row forward were dumped under the serial encoder and under the concurrent one, five runs: 29 buffers, 0 differ, byte for byte. Two streams run as one shared forward for 40 steps equal their solo logits exactly.

GPU time of one forward, same machine, cache empty:

Rows 49e474a55 This head
1 19.2 ms 16.1 ms
8 41 ms 37.7 ms
16 54 ms 49.3 ms
64 166 ms 138 ms

A one-row forward is on the order of 1,700 launches, most of them small, and they ran one after another; the independent ones now overlap, which leaves on the order of 1,150 steps in sequence.

Checks on this head: zig build native compiles; 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 --check and git diff --check clean; lean 167 on the base and 167 here, 0 new. No kernel is added or changed by these two commits.

Served, TensorFold's clients, 256 tokens, greedy, three reps, --parallel 4 --context 16384 --prompt-cache-gib 0, with #4447 and #4465 at their current heads applied:

fibonacci-raw gpu-chat-no-think 4 streams, code 4 streams, chat
Plain 55.1 tok/s 55.5 128.2 total 127.2 total
--drafter 78.9 75.6 169.7 total 140.2 total
oMLX 0.8.1, DSpark on, same clients not measured (its raw completions return no timing the client reads) 72.5 not measured 126.6 total

bench_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). Peak footprint 20 GB plain, 21 GB with the drafter.

Against the bar on this machine, on the one prompt both servers were timed on: with the drafter, one stream is at 1.04 of oMLX and four streams at 1.11; without it, four streams are at 1.00 and one stream at 0.77 (oMLX's figure is with its own drafter on; I have no plain oMLX figure). Prompt speed is 419 tok/s on a 45K-token prompt against oMLX's 2,785, so the prompt path is still far short.

Update: head 49e474a55 (four more commits)

Since the description below was written this branch gained the shared-forward fix from #4446 (here as 6f0f29433) and three speed commits. The numbers in this section replace the receipt's where they overlap; the rest of the description stands for d447ca703.

Commit What Bits
ef5bd8748 The depth mixes (tf_inkling2_ar) and the loop gates take every row of a forward in one launch, where the forward looped rows. The gates read row r's message at a stride, since the messages interleave 48 entries a row. Unchanged
2c8338c4d For chunks of four rows or more, the routed experts run grouped by expert: tf_ink2_group lists each expert's route pairs, and the _grouped kernels decode a weight block once for a pass of four pairs. Each row's sums are the ungrouped kernels' sums, in the same order. Unchanged
eaea4889d Sliding attention folds 32 keys a simdgroup (was 256). Global attention takes the fewest whole 1,024-key folds a launch slot that still fit the cache in 64 slots (was always 16,384), so a 65,536-token cache runs 1,024 keys a threadgroup. Sliding: changed, the online softmax rounds each P against its own chunk's running peak. Global: unchanged, a slot is a whole number of the kernel's 1,024-key folds and the merge folds them in the same order.

GPU time of one forward, same machine, cache empty:

Rows d447ca703 This head
1 19.7 ms 19.2 ms
8 74 ms 41 ms
16 132 ms 54 ms
64 507 ms 166 ms

One row with 1,200 tokens in the cache: 30.5 ms before the attention commit, 23.5 ms after.

Checks on this head: zig build native compiles; the six Inkling host steps exit 0 (two attention_test.zig cases pin the new chunk geometry); 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 --check and git diff --check clean; lean 167 on the base and 167 here, 0 new.

Exactness on this head, with the drafter commits of #4447 and #4465 also applied for the drafted rows:

  • ef5bd8748 and 2c8338c4d leave every token_sha and the comparison with oMLX's model exactly as they were (the same minimum, median and logit cosines to seven digits).
  • 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 with 138 and 132 drafts accepted.
  • A 25-token prompt fed in chunks of 64, 16, 7 and 1 rows gives one token_sha.

Served, TensorFold's clients, 256 tokens, greedy, three reps, --parallel 4 --context 16384 --prompt-cache-gib 0, with #4447 and #4465 applied:

fibonacci-raw gpu-chat-no-think 4 streams, code 4 streams, chat
Plain 46.2 tok/s 46.5 92.0 total 91.2 total
--drafter 67.1 64.7 96.9 total 77.5 total
oMLX 0.8.1, DSpark on, same clients not measured (its raw completions return no timing the client reads) 72.5 not measured 126.6 total

So against the bar on this machine: one drafted stream is at 0.89 of oMLX on the chat prompt, and four streams at 0.61 with the drafter and 0.72 without. Not met.

Not registered yet: tf_ink2_group and the four _grouped kernels have no contract entry of their own. They are meant as bit-preserving companions of the ungrouped kernels, and the evidence here is the unchanged token hashes; a replaces entry with byte equality is the right gate, and I will add it if you want this in.

Prompt speed: 353 tok/s on a 45K-token prompt (64-row chunks). The chunk size is the limit now: each chunk re-reads every expert it routes to at every visit.


What this changes

Before: on #4387's Metal path one decode row takes 1,159 ms of GPU time on an M5 Ultra, 1,130 ms of it in the routed-expert kernels, so plain decode is 0.86 tok/s. After: the same row takes 19.7 ms and plain decode is 38 tok/s. The kernels compute the same arithmetic contract (stored NVFP4 and MXFP8 decoded in registers to BF16, BF16 activations, FP32 sums); what changes is how each sum is split over threads.

This is a proposal on top of #4387, opened as a draft. It is the speed slice I offered on #4274, and it does not reach the speed bar yet (see the receipt).

Step GPU time, one decode row Of which
#4387 with the serving fixes 1,159 ms experts 1,130 ms
2f386ca16, experts 33.8 ms experts 4.7 ms, loop gates about 10, router 7.6
49c798652, gates and router 19.7 ms experts 4.5 ms, router about 1

What was slow, and what each commit does:

  • Experts (experts.metal). Each kernel launched one 32-thread group per (token, expert) pair, and each thread walked 36 outputs of 2,304 columns one element at a time. Now a threadgroup is eight outputs of one pair and a simdgroup is one output: lane l sums the 16-column (NVFP4) or 32-column (MXFP8) blocks l, l + 32, ... in column order, and simd_sum adds the 32 lanes. Each weight is still bf16(e2m1 * e4m3 * phi) or bf16(ldexp(e4m3, scale - 127)); the NVFP4 inner product is taken as (2 * e2m1) * (e4m3 / 2), which is exact either way. The combine is one thread an output and adds the routed experts in ascending expert order as before.
  • Loop gates (loop.metal). One threadgroup did everything for a row, with 64 threads each running a 4,608-step serial dot. Now three launches: normalize [h | m] to BF16, the rank-64 projection as one simdgroup a rank with eight columns a lane a step (the shape of core/bf16_matvec.metal), then the forget and gain dots and the blend, one thread an output, in rank order as before.
  • Router (glue.metal). 128 threads each ran a 2,304-step serial dot and one thread then scanned 8 x 128 keys. Now the dots are one simdgroup an expert, and the pick is by rank: among ordered keys, "greatest score + bias first, lowest expert on a tie" is what the scan chose. If any key is NaN the kernel takes the original scan, so those picks are unchanged.

Two things about this GPU that the measurements showed: one GPU thread runs a long serial loop slowly (a 2,304-step dot is on the order of 100 µs), and a loop whose bound is not a compile-time constant runs about twice as slow as the same loop with a constant bound.

Which bits change. The order of three sums: each expert dot (lane-strided blocks then simd_sum, where it was one column-order sum), the gates' rank-64 projection and the router's dot (eight columns a lane a step, where each was one column-order sum). Every rounding point is where it was. The gates' and router's intermediates live in a small buffer owned beside their pipelines (64 rows), so their launch signatures and the contract probes are unchanged.

Checks on this head

  • Head commit: d447ca703.
  • Lean checker, on the base and on this head: 167 and 167, 0 new.
  • Tests run:
    • zig build native -Dcpu=apple_m1: compiles.
    • The six Inkling host steps (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.
    • zig fmt --check build.zig zig and git diff --check: clean.
    • zig build test test-golden -Dcpu=apple_m1, run on these commits with my timing code also applied: 936 of 945 steps, 16,780 of 16,937 tests passed, 151 skipped, 6 failed, test-golden 324/337 and 69/69 equal with 0 unexpected. The failures are Inkling 2 Mini on CUDA and Metal #4387's: its own head fails the same tests (rollback_test lone keep twice, the DeepSeek vision_config test, cuda_keep_others_test, contract.registry, the memcpy link check) beside its two compile errors.
  • CI: not yet reported when this was written.
  • Not run, and why: the whole suite on this exact head; M1 to M4; CUDA and HIP (not reached).

Receipt

fibonacci-raw gpu-chat-no-think
#4387 with the serving fixes, plain 0.86 tok/s (one 50-token chat reply; the bench was not run at this speed)
This head, plain 38.3 tok/s 38.0
This head, --drafter (with #4447) 44.2 39.1
  • Four streams, tools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0 --levels 1,4 --alone --serial, total: plain 62.4 (code) and 62.9 (chat) tok/s; with the drafter 38.1 and 30.5, slower than plain for the reason given in Inkling 2 Mini DSpark on Metal: attention scale 1/sqrt(128), and the recurrent step reads kappa as FP32 #4447.
  • The speed bar is not met. oMLX 0.8.1 on this machine and checkpoint, with its own client and DSpark on, decodes about 88 tok/s on a code prompt and 118 tok/s in total at four streams. What is left in the 19.7 ms: the attention inputs' mixes and norms about 3.9 ms, experts 4.5, the six input projections 2.7, attention 2.5, the rest about 6. The plain BF16 projections already move about 1 TB/s here (9 µs a launch).
  • Prompt speed before and after: a 64-row chunk takes 1.9 s before and 0.51 s after on the GPU, about 126 tok/s. The prompt path still loops rows one at a time in several places, and that is not changed here.
  • Peak footprint: 20 GB plain, 21 GB with the drafter (footprint, after the benches).
  • Licence of any new weights or drafter, or "n/a": n/a.
Kernel contract
  • Kernels registered with the contract, and the kernel each one replaces: none is new to the registry and none declares replaces. tf_ink2_nvfp4_gu, tf_ink2_nvfp4_down, tf_ink2_mxfp8_gu, tf_ink2_mxfp8_down and tf_ink2_combine keep their names and bindings with a new launch grid. tf_inkling2_loop_gates and tf_inkling2_router keep their names as the first launch of their operator; tf_inkling2_loop_zeta, tf_inkling2_loop_blend and tf_inkling2_route_scores are the added launches, and each runs inside its operator's existing probe (loop.gates, glue.router), against the same FP64 reference. The three added launches have no registry record or control of their own yet; say if you want them registered separately and I will add that.
  • A planted control for each kernel: the experts' seven controls plant what they planted before; two of them (mx_down_scale, combine_slot_order) and the gates' and the router's had their anchor text updated to the new source. The gates' control now doubles zeta, the router's still drops the bias from the key.
  • Each backend's SUMMARY line and exit status: Metal, tf-kernel-contract --only inkling2 (-Dcpu=apple_m1 -Doptimize=safe), M5 Ultra: 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.
  • Launch records: the five expert launches are 256 threads, reserved; the router's threadgroup memory is 1,600 bytes (was 576) and the gates' 80 (was 9,552).
  • Chips I could not run: M1 to M4. CUDA and HIP are not touched.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (No new test: the existing contract probes and controls cover the rewritten kernels.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Drafted equals plain, and concurrent equals solo since 6f0f29433. Resumed not run.)
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it. (Faster than Inkling 2 Mini on CUDA and Metal #4387 everywhere measured; with the drafter four streams are slower than without, as in Inkling 2 Mini DSpark on Metal: attention scale 1/sqrt(128), and the recurrent step reads kappa as FP32 #4447.)

ashhart and others added 24 commits November 21, 2026 16:05
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.
@ashhart
ashhart force-pushed the lead/inkling2-mini branch 4 times, most recently from aefb063 to c41911e Compare November 24, 2026 09:43
@ashhart
ashhart deleted the branch ashhart:lead/inkling2-mini November 24, 2026 09:43
@ashhart ashhart closed this Nov 24, 2026
@ashhart ashhart reopened this Nov 24, 2026
@ashhart
ashhart changed the base branch from lead/inkling2-mini to main November 24, 2026 09:49
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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 main. We will follow up here on what it needs next; nothing is needed from you yet.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

An update on your Metal stack, @sethforprivacy, now that #4387 is on main. Five of your Inkling Metal commits already landed there, and #4446, #4607 and #4635 are closed as landed.

One commit here, the lane-strided FP32 sum (2f386ca16f), changes the order the dot products are summed in, so outputs can differ in the last bits. TensorFold keeps every output bit equal to the serial reference, by default and behind a switch, so that commit cannot land. We are rebasing the rest of your stack onto main without it, and will check that nothing above it depends on that order. If it is the source of a speedup you want to keep, an exact form that keeps the original summation order would be welcome as its own PR.

Nothing is needed from you for the rebase; we will follow up on each PR.

  • Synthena

@BlivionIaG

Copy link
Copy Markdown
Contributor

An M4 Pro data point for this stack, in case it helps: Apple M4 Pro, 48 GiB, no tensor units, thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7, -Dcpu=apple_m1 -Doptimize=ReleaseFast, serve --context 8192 --parallel 1 --no-drafts --prompt-cache-gib 0 --no-thinking, greedy. Built from main at 68ff0ad8e6 with this pull request's 14 commits cherry-picked (its branch carries #4387's commits unsquashed; one compile fix was needed, a duplicate checkpoint_file_cache import), and a second build with #4523, #4608 and #4618 applied on top in order, which also builds and runs here. Load average was 2 to 5 with other work on the machine, one run per cell, so read ratios and not absolutes.

plain decode, tok/s main this pull request with #4523, #4608, #4618
1 stream, code / chat prompt 0.7 / 0.8 27.4 / 28.1 27.5 / 28.1
4 streams, total, code / chat 1.5 / 2.9 44.5 / 50.4 45.0 / 51.1

Nothing is asked of you; I wanted the non-tensor-unit numbers to exist somewhere, since the descriptions here are M5 Ultra. Our own non-tensor-unit prompt kernels for main are in #4756 (cold 2,048 tokens 146 s to 9.7 s on main with identical bits); it is built on main, not on this stack, so whichever lands first, the other follows its sum order.

@BlivionIaG

Copy link
Copy Markdown
Contributor

For the exact form that @ashhart asked for above: #4919 is a pull request on main that runs the routed-expert, router, combine, logits and loop-gate decode kernels with one lane to one output row, 16-byte loads and a parallel top-8 pick, every sum in main's order. On the M4 Pro from my comment above it takes one-stream decode from 0.7 to about 22 tok/s (4 streams, aggregate 30 to 46 tok/s) with the four greedy chat hashes equal to main's, so it sits below this pull request's 27 tok/s and above nothing that changes bits. The remaining gap here is the lane-strided and tree sums, and I have not touched them. If this lands first, the rest of this stack's decode rows can be re-measured on top of it.

ashhart added a commit that referenced this pull request Nov 24, 2026
… dot the serial chain

Each expert product ran one 32-thread group a route pair, its lanes looping
over the pair's outputs: 36 outputs a lane for GU (n 1152), 72 for down
(n 2304), and eight groups a decode step. Combine ran one group a token.

The four products and the combine now launch threadgroups along the outputs
by route pairs (or tokens), one thread an output. Each thread runs the same
ink2_dot_nv / ink2_dot_mx as before: one FP32 chain from column 0 up, every
product rounded before its add (fp contract off), then the same BF16 rounding
and activation. Combine keeps its ascending-expert loop. Only which thread
computes an output changes, so every output is bit-identical to the serial
reference. Threads past the row return before any read. Launches stay
32 threads, so the existing records hold; the quantize kernels are unchanged.

The grid of outputs by route pairs and launchGrid follow #4448's
2f386ca; its lane-strided partial sums and simd_sum, which change the
FP32 sum order, are not taken.

Tests: test-inkling2-controls-host checks the source keeps both dots serial
with no simd_sum and launches every product and the combine one output a
thread (fails before: five lane loops), and that the grid covers every output
exactly once, with no thread past the row reading. The block count rounds
up as n / 32 plus one for a remainder, so the largest u32 widths (4294967265
through 4294967295) take 134217728 blocks instead of overflowing n + 31; a
test asserts those widths and fails on the n + 31 form.

Co-authored-by: Seth For Privacy <40500387+sethforprivacy@users.noreply.github.com>
ashhart added a commit that referenced this pull request Nov 24, 2026
… dot the serial chain

Each expert product ran one 32-thread group a route pair, its lanes looping
over the pair's outputs: 36 outputs a lane for GU (n 1152), 72 for down
(n 2304), and eight groups a decode step. Combine ran one group a token.

The four products and the combine now launch threadgroups along the outputs
by route pairs (or tokens), one thread an output. Each thread runs the same
ink2_dot_nv / ink2_dot_mx as before: one FP32 chain from column 0 up, every
product rounded before its add (fp contract off), then the same BF16 rounding
and activation. Combine keeps its ascending-expert loop. Only which thread
computes an output changes, so every output is bit-identical to the serial
reference. Threads past the row return before any read. Launches stay
32 threads, so the existing records hold; the quantize kernels are unchanged.

The grid of outputs by route pairs and launchGrid follow #4448's
2f386ca; its lane-strided partial sums and simd_sum, which change the
FP32 sum order, are not taken.

Tests: test-inkling2-controls-host checks the source keeps both dots serial
with no simd_sum and launches every product and the combine one output a
thread (fails before: five lane loops), and that the grid covers every output
exactly once, with no thread past the row reading. The block count rounds
up as n / 32 plus one for a remainder, so the largest u32 widths (4294967265
through 4294967295) take 134217728 blocks instead of overflowing n + 31; a
test asserts those widths and fails on the n + 31 form.

Co-authored-by: Seth For Privacy <40500387+sethforprivacy@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants