Repository navigation
inkling2 metal: exact GQA 3:1 decode KV reuse and multi-stream batched attention (Refs #5191) - #5206
Conversation
|
Thanks @gilby. We ran this head (
Landings are paused while we cut 1.3.6. This goes into the first trains after the release, and its train runs the remaining cells.
|
|
Thanks for the M3 Ultra A/B! On 1-stream decode (
The only differences on 1-stream decode are:
So the batched path itself does not run on 1 stream; the ~0.04–0.08 tok/s delta is within noise / minor per-visit host + Metal dispatch/library layout effects. |
…d attention Add exact 0-ULP GQA 3:1 decode kernels (tf_ink2_attn_scalar_gqa and tf_ink2_attn_scalar_gqa_batched) and multi-segment batched prep (tf_ink2_prep_batched) using per-segment GPU KV address descriptors. One 32-lane simdgroup now handles all 3 query heads sharing each (row, kv_head, chunk), loading K, V, and relative bias projections once instead of 3x while preserving the exact FP32 arithmetic and BF16 rounding order of tf_ink2_attn_scalar. Multi-stream non-tree decode visits in attendSegments now batch into a single prep, decode, and merge launch using a uniform active chunk stride across segments. Register launch records, host planning/ABI tests, 4-gate kernel contracts with 0-ULP scalar parity checks, and 6 planted red controls. Refs ashhart#5191
ae96e25 to
0957970
Compare
|
Thank you @gilby. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
Refs #5191
Summary
Adds exact
0-ULP GQA 3:1 KV-head reuse for Inkling 2 Mini Metal attention and batches multi-streamattendSegmentsacross shared GPU descriptors without altering FP32 reduction order or BF16 output rounding:0-ULP GQA 3:1 decode/verify KV reuse (tf_ink2_attn_scalar_gqaandtf_ink2_attn_scalar_gqa_batchedinzig/kernels/metal/inkling2/attention.metal):(row, kv_head, chunk), loading K, V, and relative bias projections once instead of 3x while preserving the exact FP32 arithmetic and BF16 rounding order oftf_ink2_attn_scalar(0-ULP bit-equal).attention_plan.zig(r.rows >= 2 or activeChunks(l, r.last_pos) >= 16): keeps full threadgroup occupancy on lone-row short/sliding decode (rows == 1, chunks < 16) while activating GQA 3:1 KV reuse on multi-row batches (c > 1, tree/spec verify, prompt chunks) and long single-stream decode (>= 16active chunks).attendSegments(tf_ink2_prep_batched,attention.zig,attention_plan.zig,forward.zig):attendSegmentsinto a single prep, decode, and merge launch using per-segment GPU KV address descriptors and a uniform active chunk stride across segments.metal_inkling2_attention_gqa.zigandmetal_inkling2_attention_gqa_controls.zig(using sharedcontract.register, 6 planted red controls), plus M1–M5 launch records ininkling2_attention_metal_records.zigand host planning/ABI unit tests inattention_test.zig.Verification
Static Checks & Kernel Contracts
python3 tools/pr_check.py --base 0460c536a4: 0 errors (clean merge verified againstorigin/mainc6f2f86227).applegpu_g17,tf-kernel-contract --only "metal inkling2 attention"): 15/15 kernels pass gates 1–4 (0fail,0-ULP bit-equal totf_ink2_attn_scalar), 13/13 planted controls red, 8/8 M1–M5 limits pass (0problems).applegpu_g15,tf-kernel-contract --only "metal inkling2 attention"): 15/15 kernels pass gates 1–4 (0fail,0-ULP bit-equal totf_ink2_attn_scalar), 13/13 planted controls red, 8/8 M1–M5 limits pass (0problems).Controlled Interleaved A-B-B-A Benchmarks (
Inkling-2-Mini,--no-drafts --parallel 4 --context 8192)Base
0460c536a4vs Newae96e25b2c(2reps per leg,A1 -> B1 -> B2 -> A2,pmset -g thermnominal on every leg,0cross-leg token mismatches across all 3 Macs):Apple M5 Ultra 512 GiB
code T=0 c=1code T=0 c=4chat T=0 c=1chat T=0 c=4code T=1 c=1code T=1 c=4chat T=1 c=1chat T=1 c=48,210-tok prefill8,210-tok post-prefill decode (c=1)Apple M5 Pro 64 GiB
code T=0 c=1code T=0 c=4chat T=0 c=1chat T=0 c=4Apple M3 Ultra 512 GiB
code T=0 c=1code T=0 c=4chat T=0 c=1chat T=0 c=4code T=1 c=1code T=1 c=4chat T=1 c=1chat T=1 c=48,210-tok prefill8,210-tok post-prefill decode (c=1)