Repository navigation
Inkling 2 Mini on Metal: decode without tensor units 9 to about 21 tok/s, every output bit equal to main's - #4919
BlivionIaG wants to merge 13 commits into
Conversation
…anks routes once - The four expert dot kernels run one lane to one output weight row: a simdgroup covers 32 consecutive rows, a threadgroup eight simdgroups, and the activation row is read in uniform 16-byte loads. The NVFP4 and MXFP8 weights are decoded from 16-byte words, two elements at a time, through FP16 bit patterns that equal the reference's E2M1 and E4M3 values and scale exactly; the MXFP8 path falls back to the reference decode for scales outside the exact range and for NaN codes. - Sum order preserved: each output is still one serial chain over its row's columns in index order, starting at zero, adding the BF16 weight times the BF16 activation product one term at a time with the same rounding points and no fused multiply-add, so every output bit equals the previous kernel's. - tf_ink2_combine launches 256 outputs a threadgroup. A threadgroup ranks the token's routes by (expert, route slot) once, drops experts outside the layer, and every output adds weight times down in that order from zero, which is the ascending-expert, ascending-slot order the old per-output scan visited. Same chain, same rounding. - Contract: dot kernels and combine at 256 threads; the combine control now plants route-slot order; the gate/up control plants a dropped pair swap.
…byte loads; router picks in parallel - tf_inkling2_router, tf_inkling2_conv_dynamic and tf_inkling2_logits keep one thread to one dot product but load eight BF16 columns of both rows at a time, four loads ahead of each step. - Sum order preserved: each dot is the same serial chain over columns 0..2303, product then add, with the rounding to BF16 or softcap after it as before. - The router ranks its 128 keys (score plus bias) in parallel: rank 0 to 7 by key descending, then expert index ascending, is exactly the set the serial first-greatest scan picks, and the ascending-expert normalization sum is unchanged. A NaN key makes the scan order dependent, so any NaN key runs the original serial scan. The control now plants the dropped bias.
- The zeta chain (64 ranks, 4,608 columns) and the forget and gain chains (64 ranks a channel) load eight BF16 weights at a time and batch the loads ahead of each step. - Sum order preserved: each zeta, forget and gain value is the same serial chain over its columns in index order, product then add, zeta rounded to BF16 as before, no fused multiply-add.
- Names the exact decode speedup and the unchanged sum orders.
# Conflicts: # CHANGELOG.md
- The entry now cites ashhart#4919.
# Conflicts: # CHANGELOG.md
|
Main's
Checks on
|
|
Thanks @BlivionIaG. The revised dots keep the serial sum order, and the current M4 checks are useful evidence. One fix remains in the router: every thread that sees a NaN key writes the same non-atomic
|
# Conflicts: # CHANGELOG.md
Every thread scans all 128 keys, so thread 0 alone stores any_nan before the barrier; the serial fallback is unchanged. The contract's router check adds six rows with NaN keys at varied experts, fifty launches each equal to the serial scan and to the first launch's bytes, with two planted controls: no fallback, and a flag from expert 0's key only.
|
I rechecked zig build tf-kernel-contract -Dcpu=apple_m1 -Doptimize=ReleaseFast
./zig-out/bin/tf-kernel-contract --only 'metal inkling2'Exit 0. This verifies the revised router on M5. The live drafted and undrafted performance comparisons remain separate. Igor Lessio - AIFLOW LABS |
|
Thanks. The router's NaN flag now has one writer and the serial fallback is kept; the repeated NaN-key check (50 launches, 6 rows, NaN keys at varied positions, byte-equal to the serial scan each time) is in the contract with two planted controls, both red: no serial fallback, and the flag taken from expert 0's key only. That check does not go red on the old kernel (20 of 20 passes on the M4), so the two-writer race never showed here; the single writer removes it rather than fixing a failure I saw. Re-measured on head M5 Ultra, against main
M4 Pro, against main
|
|
Thanks, @BlivionIaG. The single-writer flag closes the reported race and keeps the serial fallback. The repeated NaN-key check and new M5 plain/drafted and M4 parity results address the earlier asks. The tested code matches this head. The fixture did not reproduce the old race, so the single-writer source change is the closure. The code is ready to land; changelog integration stays with us.
|
What this changes
Inkling 2 Mini Metal decode without tensor units (M1 to M4) reads each routed-expert weight a byte at a time. This reads 16-byte words in the two expert dot products (
ink2_dot_nv,ink2_dot_mx), keeping one serial chain from column 0 per output, and gives the router, dynamic convolution, logits and loop gates 16-byte loads and a parallel top-8 pick at one row. Every output bit equals main's. On an M4 Pro, one-stream decode goes from about 9 to about 21 tok/s against maina15c7b0603.2f386ca16f, changes the summation order and cannot land; this is the exact form asked for there).ff73e7441c(experts and combine one thread an output),aa3422fe09(the expert grid against frozen main kernels) and inkling2 metal: the router and loop-gate dots a thread an output, bit for bit main's #4912 (split router and loop gates for two rows or more) overlap this change; the PR is adapted to them: main's grid, controls and records are unchanged, and the earlier 256-thread lane-a-row kernels and the combine ranking are dropped (the combine's single sort is Inkling 2 Mini on Metal: prompt experts, projections and loop gates on simdgroup matrices without tensor units (stacked on #4618) #4756's).atc overlap --json: not rerun on this head.Checks on this head
956d1c857e(slice/decode-exact), a merge of main4c79cfe346.tools/pr_check.py --base 4c79cfe346 --pr 4919: 0 errors, 0 warnings.zig fmt --check build.zig zig: clean.-Dcpu=apple_m1):test-inkling2-metal-host101 passed, 6 skipped;test-inkling2-host45 passed, 4 skipped (the real-checkpoint tests withoutTF_INKLING2_CKPT).tf-kernel-contract --only inkling2: 61 kernels pass gates 1-4, 68 controls red as planted, 0 missed, 0 limit problems; includes the repeated NaN-key check (50 launches, 6 rows) with its two planted controls (no serial fallback; flag taken from expert 0's key only). The check passes on the old two-writer kernel too (20 of 20), so the race never showed; the single writer removes it.Receipt
95591a94f8, M4 Pro,--context 8192 --parallel 1 --no-drafts --prompt-cache-gib 0 --no-thinking, full token ids and SHA-256 equal in all 14 cells: cold 255863541147578, 2561f6434a3a13f, 257f5a8eb75e54b, 5129d934d0e3802, 51321583159d990; chat 8/16/244c2031fb15353a974c335a4e0e69856242e3; greedy 2566ce0eb7d34ed; seeded (T 0.7, seed 1234)12dd740614ad; four concurrent requests equal their solo runs. The first merge (6cf853d06d) gave the same 14 against maina15c7b0603.tools/bench_concurrent.py,--parallel 4, 128 tokens, A-B-B-A against maina15c7b0603(one-row decode runs the same kernels on95591a94f8): one stream, code 9.3 and 9.2 tok/s on main, 20.9 here (B1's 1.9 was its first-run pipeline compile); chat 9.4 on main, 20.7 and 20.3 here. Four streams: code 10.8 and 11.0 on main, 32.4 and 37.8 here; chat 2.1 on main A1 and 39.9 and 39.5 here. Main's A2 at four streams did not finish because another job put the machine under memory pressure, and a rerun against95591a94f8was spoilt by the same pressure (503s), so I give no number from it.--aloneon B1: 20 of 20 equal.7cddab1446against main9a38b1f7b3: all 8 replies equal in token ids and SHA-256; one stream 0.9 on main to 36.8 here and four streams 3.1 to 43.9 aggregate (code);--alone30 of 30 equal. Not re-measured on this head.-Dcpu=apple_m1 -Doptimize=ReleaseFast, Inkling-2-Minied40e7da625f594fc9c4990f5f66be24873c22d7; Apple M4 Pro 48 GiB (no tensor units), and Apple M5 Ultra 256 GiB for the earlier-design cells.Sum orders
Checklist