Repository navigation
inkling2 metal: width-invariant M5 NAX route_scores/loop_zeta/loop_blend/rel_table and vectorized bfloat4 stores - #4766
Closed
cwschroeder wants to merge 23 commits into
Conversation
… rows where prep wrote them
…in the fewest 1,024-key folds a slot
…up to 32 rows is one launch
…uffers, independent launches side by side
… a row's sums never depend on its chunk
…t attention, and use mv_mma for prompt dense projections
Replace the scalar stride-2304 tf_inkling2_logits kernel with a 256-thread (8-simdgroup) batched implementation where each simdgroup computes one vocab row across up to 8 token rows, sharing coalesced bfloat4 unembed loads and preserving width-invariant FP32 reduction and BF16 softcap rounding. Update glue dispatch, contract limits record, host check, and 8x8 tile/interval contract tests.
… and batch conv staging and commits
…size prompt part_o by capacity, and widen glue/loop scratch to 512
…eams and raise batch_rows to 64
…, 8 KiB active-expert NAX, and blocked stage_conv
…nd 8 KiB bfloat4 dense_units
…end/rel_table and vectorized bfloat4 stores
Owner
|
Thanks @cwschroeder. #4777 is built directly on this branch and contains all of its commits, so I'm closing this one to keep the review in one place. Its one extra commit reworks some of the same loop and attention code, so #4777 is the version to review from here. The red macOS dev-tools check comes from the base branch, not from your work.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Stacked on #4761 (
6d4ea7da4, overlead/inkling2-mini3e0e9bcb8). Zero overlap with open Inkling 2 Mini PRs outside this stack (no DSpark, no host lane sampler, no pre-M5 simdgroup MMA, no prompt attention changes):dense_units.metal/dense_units.zig/loop.zig/glue.zig/forward.zig(all widths1..512, preserving bit-exactplain == draftedwidth invariance):tf_ink2_route_scores_units_16/tf_ink2_route_scores_units_64(256 threads, 8 KiB TG):[rows, 2304] x [128, 2304]^T -> FP32 [rows, 128]with identical 8-way K-split order across bands (5.55 -> 1.42 msclock-norm in 512-row prefill, 3.91x faster).loop_zetavia existingdense_units.encode([rows, 4608] x [64, 4608]^T -> BF16 [rows, 64], exact 8-way K-split order across all widths).tf_ink2_loop_blend_units(32 threads, 0 B TG):[rows, 64] x [2304, 64]^Tforforget+gainvia 4 exact FP32 NAX ops plus the four-step FP32 blend (11.21 -> 3.42 msclock-norm in 512-row prefill, 3.28x faster).tf_ink2_rel_table_units(32 threads, 0 B TG):[rows*24, 16] x [16, 1024] -> BF16via single non-transposed exactink2_mma_ntop per 16x32 tile (6.13 -> 1.38 msclock-norm in 512-row prefill, 4.44x faster).bfloat4/bfloat2stores & alignedushort/uintweight loads indense_units.metalandexperts_units.metal:dense_units.metalwritesbfloat4whenfull_n(dense6_units_64-21.1% clock-norm,dense6_units_16-5.5%).experts_units.metalreplaces unaligned 4-byte loads + variable shifts with alignedushort(NVFP4) /uint(MXFP8) loads andbfloat2/bfloat4stores (nvfp4_gu_units-6.4%,nvfp4_down_units-10.1%,mxfp8_down_units-8.4%).metal_inkling2_nax_ops.zig,metal_inkling2_nax_ops_controls.zig,metal_inkling2_main.zig,metal_inkling2_controls_host.zig, andinkling2_dense_units_metal_records.zig.Checks on this head (
59fce1473)zig fmt --check build.zig zig: PASS (Zig0.17.0)tools/zig/lean_check.pyvs6d4ea7da4: 167 vs 167, 0 newtools/pr_check.py --base origin/lead/inkling2-mini: 0 errors (1 advisory warning for--pr NUMBER)zig build native -Doptimize=Debug: PASSzig build test-inkling2-controls-host test-inkling2-metal-host test-metal-launch-map-host: PASS (1234 registered launches, 2 controls, 0 missing)tf-kernel-contracton Apple M5 Max,applegpu_g17,tensor units true):--only "inkling2 dense_units": 10/10 kernels pass Gates 1–4 (6dense_units+ 4 new NAX ops), 10/10 controls red as planted, 0 limit problems--only "inkling2 units": 4/4 kernels pass Gates 1–4, 4/4 controls red as planted, 0 limit problemsReceipt
0.17.0,thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7(unmodified BF16+NVFP4+MXFP8,powermode 0).--no-drafts, 1-row) vs drafted (multi-row verify): greedy233dbb7e56f4 == 233dbb7e56f4, sampledtemp=1.0, top_p=0.95, top_k=20, seed=42ed31ffde9b47 == ed31ffde9b47(100% bit-exact).b5017c21c071), shorttemp=1.0(3854e647286d), and 5,588-token prefill (df4a96126cd8).fwd_prefill(512-row chunk at ~5K context):442.4 -> 349.3 msraw (-21.1%; clock-normalized391.2 ms, -11.6% net /-51.2 msa chunk); 5,588-token TTFT4.291 -> 3.700 s(1,510 tok/s).temp=1.0, top_p=0.95, top_k=20(seed=42, 128 tok,decode=1.152 s), 97.4 tok/s greedy (thermal=1).