Repository navigation
inkling2 metal: fused AR+RMSNorm, vectorized 192-thread loop messages/gates, and bfloat4 attention prep - #4777
cwschroeder wants to merge 21 commits into
Conversation
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
|
aee31d7 to
44d5883
Compare
…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
…/gates, and bfloat4 attention prep
44d5883 to
2599d5a
Compare
|
Thank you for rebasing this onto main, @cwschroeder. We went through the new head commit by commit. It still carries the earlier Inkling Metal stack underneath your work, including commits that change the order FP32 dot products are summed in (the lane-strided sum and the simdgroup router, loop-gate and grouped-expert dots). TensorFold keeps every output bit equal to the serial reference, by default and behind a switch, so those commits cannot land, and the PR is held until the stack is rebuilt without them. Where your own commits reshape a reduction, the same applies; where they only reorder work, scheduling or launches, they can be reviewed once they sit on a base without those changes. An exact version of the faster router and gate dots, one thread per output in the original summation order, is something we are looking at on our side. Nothing is needed from you right now; we will follow up here.
|
What this changes
Stacked on #4766 (
59fce1473, overlead/inkling2-mini3e0e9bcb8). Keeps zero overlap with #4689 (tf_inkling2_arand convolution kernels are untouched):tf_ink2_fused_ar_norminglue.metal,glue.zig,forward.zig):float4/bfloat4vectorized kernel (240B TG memory, 3 barriers, queries loaded once instead of up to 5x), eliminating the FP32 intermediate round-trip and separate norm launch across ungated attention, ungated MLP, and final norm stages.blockResidualNorm), count-checked red control, and Metal launch record (glue_plan.zig,inkling2_glue_metal_records.zig,metal_inkling2_glue.zig,metal_inkling2_glue_controls.zig).tf_inkling2_loop_messagesandtf_inkling2_loop_gates(loop.metal,loop.zig,loop_plan.zig,loop_test.zig,inkling2_loop_metal_records.zig):bfloat4/float4rows once into registers (cuttingloop_messagesbank reads 3x -> 1x and query reads 2x -> 1x, andloop_gatesh/mreads 2x -> 1x), halves barrier counts (4 -> 2inloop_messages,2 -> 1inloop_gates), reduces TG memory (144 -> 96B and80 -> 48B), and writes coalescedfloat4/bfloat4outputs.bfloat4loads and stores inink_prep_qrelandink_prep_kv(attention.metal):tf_ink2_prepandtf_ink2_prep_slotswithbfloat4loads/stores while preserving the exact FP32 sum order and BF16 rounding steps (0-ULP bit-identical).Checks on this head
zig fmt --check build.zig zig: PASS (Zig0.17.0)tools/pr_check.py --base origin/lead/inkling2-mini: 0 errors (lean 167 vs 167, 0 new, all modified files<= 600lines)zig build native -Doptimize=Debug: PASSzig build test-inkling2-controls-host test-inkling2-metal-host test-metal-launch-map-host: PASS (1235 registered launches, 2 controls, 0 missing)applegpu_g17,tensor units true):tf-kernel-contract --only "inkling2 glue": 10/10 kernels pass Gates 1-4, 10/10 controls red as planted, 0 limit problemstf-kernel-contract --only "inkling2 loop": 2/2 kernels pass Gates 1-4, 2/2 controls red as planted, 0 limit problemstf-kernel-contract --only "inkling2 attention": 10/10 kernels pass Gates 1-4, 8/8 controls red as planted, 0 limit problemsReceipt
0.17.0,thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7(unmodified BF16+NVFP4+MXFP8).--no-drafts1-row vs drafted multi-row verify):sha=658383e87632) andtemp=1.0, top_p=0.95, top_k=20, seed=42(sha=3c62ce56afc5).sha=b5017c21c071).tf_ink2_nvfp4_gu_units_activeonfwd_verifyandtf_ink2_attn_prompt_slidingonfwd_prefill,powermode 0):tf_ink2_fused_ar_norm: -20.8% to -29.1% onfwd_verify(1.566 -> 1.111-1.240 ms), -34.4% onfwd_prefill(3.061 -> 2.009 ms/chunk)tf_inkling2_loop_gates: -20.6% to -31.4% onfwd_verify(0.593 -> 0.407-0.471 ms), -24.1% onfwd_prefill(2.469 -> 1.873 ms/chunk)tf_ink2_prep: -5.8% to -20.8% onfwd_verify(0.371 -> 0.294-0.349 ms)powermode 0, 128 tokens): 111.1 tok/s attemp=1.0, top_p=0.95, top_k=20, seed=42(decode=1.143 s) and 99.4 tok/s greedy (decode=1.278 s,sha=b5017c21c071).