Skip to content

inkling2 metal: GQA 3:1 sliding KV sharing, multi-stream slots, and batch_rows=64 - #4596

Open
gilby wants to merge 40 commits into
ashhart:mainfrom
gilby:inkling2-lead-batched-slots
Open

gilby wants to merge 40 commits into
ashhart:mainfrom
gilby:inkling2-lead-batched-slots

Conversation

@gilby

@gilby gilby commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Rebases GQA 3:1 sliding KV sharing, multi-stream decode attention slots (up to 8 streams), and batch_rows = 64 onto #4618 while keeping #4618's exact global prompt attention and 0-ULP greedy parity.

What this changes

Shares cached key/value loads across each 3:1 GQA head group and a 2-row cohort (tf_ink2_attn_scalar, 192 threads, 16384 B TG), batches up to 8 decode streams via tf_ink2_prep_slots (32 threads) and tf_ink2_attn_slots (192 threads, 16384 B TG, seg_of = si % max_slots), batches prepSlots/relTable/merge across all 48 visits, keeps #4618's exact tf_ink2_attn_prompt (prompt_attention.metal, prompt_rows = 256, split_rows = 64) on the 8 global visits so P rounding matches bit-for-bit, and raises state.batch_rows / max_segments from 32 to 64.

Checks on this head

  • Head commit: 437cbea72cde697dd8e73fdbaf9383a041ae1233
  • Lean checker, python3 tools/zig/lean_check.py: 7496 files, 167 problems (0 new vs base ad3d31f9ff); python3 tools/pr_check.py --pr 4596 --base ad3d31f9ff: 0 error(s), 1 warning(s) (changelog reminder).
  • Tests run:
    • Host CPU checks (-Dcpu=apple_m1): zig fmt --check build.zig zig exit 0; git diff --check ad3d31f9ff..HEAD exit 0; test-inkling2-controls-host, test-inkling2-host pass; test-inkling2-metal-host (CPU) 78 passed; 5 skipped; 0 failed; test-metal-launch-map-host 8/8 pass (1211 registered launches, 2 controls, 0 missing).
    • Real-checkpoint test-inkling2-metal-host (TF_INKLING2_METAL_DIR set to Inkling-2-Mini-ed40e7da, ReleaseFast -Dcpu=apple_m1): 80 passed; 3 skipped; 0 failed across Apple M5 Ultra, Apple M5 Pro, and Apple M3 Ultra (3 skips are DSpark-gated tests when TF_INKLING2_DSPARK_DIR is unset).
  • CI: Local host, M5 Max contract (49/49 + 49 red), and full M5 Ultra, M5 Pro, and M3 Ultra contract/real-ckpt/serving/cache runs all passed.
  • Not run, and why: Non-Apple backends; all 4 Apple Silicon hardware tiers (M5 Max, M5 Ultra, M5 Pro, M3 Ultra) ran on real hardware.

Receipt

  • Base against branch (Apple M5 Ultra / M5 Pro / M3 Ultra, Inkling-2-Mini-ed40e7da, plain --no-drafts vs #4618 ad3d31f9ff):
    • Apple M5 Ultra (bench_concurrent.py --levels 1,4,16 --temperatures 0,1.0 --tokens 128 --reps 2 --alone):
      • chat T=0.0: c=1 60.0 vs 57.6 (+4.2%), c=4 203.1 (st=217.1, +3.2% agg) vs 196.8, c=16 476.1 (st=585.4, +5.2% agg / +5.9% steady) vs 452.7 (st=552.8) tok/s (sha=32ddb869bec4 exact match, alone_unequal=0)
      • code T=0.0: c=1 60.2 vs 53.6 (+12.3%), c=4 210.3 (st=222.6, +5.6% agg) vs 199.1, c=16 522.8 (st=608.2, +6.4% agg / +7.6% steady) vs 491.2 (st=565.1) tok/s (sha=4490e6bbcfbd exact match, alone_unequal=0)
      • chat T=1.0: c=1 35.5 vs 34.7, c=4 59.7 (st=60.3) vs 59.4, c=16 72.2 (st=73.2) vs 71.9; code T=1.0: c=1 35.3 vs 34.4, c=4 58.1 (st=59.1) vs 57.8, c=16 69.4 (st=70.9) vs 69.4 (exact sha set match)
      • bench_cache.py --tokens 64 --repeats 2 --streams 4 --require-cold (pt=8704): qualified=True, cold ttft_s=8.2196s (rep_min=8.1666s) vs 8.7536s ref (-6.1%), dec=49.9 (rep_max=49.9) vs 48.5 tok/s (sha=95e612cfdcaf exact match)
    • Apple M5 Pro 20-core (bench_concurrent.py --levels 1,4 --temperatures 0,1.0 --tokens 128 --reps 2 --alone):
      • chat T=0.0: c=1 32.1 vs 31.5, c=4 104.0 (st=116.1) vs 102.6 (sha=32ddb869bec4 exact match, alone_unequal=0)
      • code T=0.0: c=1 31.8 vs 31.8, c=4 111.4 (st=118.8) vs 110.7 (sha=4490e6bbcfbd exact match, alone_unequal=0)
      • chat T=1.0: c=1 23.6 vs 23.1, c=4 40.0 (st=41.6) vs 40.2; code T=1.0: c=1 23.5 vs 22.5, c=4 38.6 (st=39.5) vs 39.1 (exact sha set match)
      • bench_cache.py --tokens 32 --repeats 2 --streams 2 --require-cold (pt=2571): qualified=True, cold ttft_s=13.7102s (rep_min=12.7738s) vs 12.6426s ref, dec=26.2 (rep_max=28.2) vs 29.6 tok/s (sha=1fbe89b22692 exact match)
    • Apple M3 Ultra (Metal 3, bench_concurrent.py --levels 1,4 --temperatures 0,1.0 --tokens 128 --reps 2 --alone):
      • chat T=0.0: c=1 46.3 vs 45.3 (+2.2%), c=4 104.7 (st=112.6, +3.8% agg) vs 100.9 (sha=34819971792d exact match, alone_unequal=0)
      • code T=0.0: c=1 47.4 vs 45.4 (+4.4%), c=4 109.8 (st=115.4, +2.9% agg) vs 106.7 (sha=4490e6bbcfbd exact match, alone_unequal=0)
      • chat T=1.0: c=1 29.3 vs 28.4, c=4 43.1 (st=44.1) vs 43.5; code T=1.0: c=1 29.2 vs 28.3, c=4 44.4 (st=45.3) vs 43.9 (exact sha set match)
      • bench_cache.py --tokens 32 --repeats 2 --streams 2 --require-cold (pt=2571): qualified=True, cold ttft_s=8.3322s (rep_min=8.2920s) vs 8.7351s ref (-4.6%), dec=38.4 (rep_max=41.3) vs 37.6 tok/s (sha=1fbe89b22692 exact match)
  • Boxes it reaches: Apple Silicon Metal (M5 Max, M5 Ultra, M5 Pro, and M3 Ultra all verified).
  • New switch? None (batch_rows = 64 and max_segments = 64; up to 8 decode streams batched per max_slots).
  • Environment: Commit 437cbea72c on ad3d31f9ff, Zig 0.17.0 -Dcpu=apple_m1 -Doptimize=ReleaseFast, Apple M5 Max (applegpu_g17), Apple M5 Ultra (applegpu_g17), Apple M5 Pro (applegpu_g17), Apple M3 Ultra (applegpu_g15), checkpoint Inkling-2-Mini-ed40e7da.
  • Paths and platforms the change reaches: Inkling 2 Mini Metal decode attention (prep_slots, attn_scalar, attn_slots, rel_table, merge) and segment batching across all 4 Apple Silicon hardware tiers.
  • Exactness: alone_unequal=0; 100% T=0.0, T=1.0, and cache token_sha parity against #4618 across M5 Ultra, M5 Pro, and M3 Ultra (preserving #4618's exact global prompt_attention on the 8 global visits).
  • Licence of any new weights or drafter: n/a.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and replacements:
    • Updated tf_ink2_attn_scalar (192 threads, 16384 B TG, replaces 32-thread scalar kernel).
    • Added tf_ink2_prep_slots (32 threads, 0 B TG) and tf_ink2_attn_slots (192 threads, 16384 B TG, multi-stream batched attention).
    • Preserved tf_ink2_attn_prompt (prompt_attention.metal, 256 threads, 32768 B TG) on global visits for bit-exact P rounding.
  • Planted controls and status: All sliding/global/relative/merge/prompt controls plus prep_slots (ignoring rseg slot), attn_scalar (row0 sharing across row block), and attn_slots (ignoring rseg slot) controls fail red as planted on M5 Max, M5 Ultra, M5 Pro, and M3 Ultra.
  • Backend SUMMARY lines and exit status:
    • M5 Max (applegpu_g17): SUMMARY 49 kernels: 49 pass gates 1-4, 0 fail, 0 known findings; 49 controls: 49 red as planted, 0 missed; 0 limit problems; gates 15323 ms, limits 11 ms (exit 0).
    • M5 Ultra (applegpu_g17): SUMMARY 49 kernels: 49 pass gates 1-4, 0 fail, 0 known findings; 49 controls: 49 red as planted, 0 missed; 0 limit problems; gates 14069 ms, limits 396 ms (exit 0).
    • M5 Pro (applegpu_g17): SUMMARY 49 kernels: 49 pass gates 1-4, 0 fail, 0 known findings; 49 controls: 49 red as planted, 0 missed; 0 limit problems; gates 14161 ms, limits 32 ms (exit 0).
    • M3 Ultra (applegpu_g15): SUMMARY 44 kernels: 44 pass gates 1-4, 0 fail, 0 known findings; 44 controls: 44 red as planted, 0 missed; 0 limit problems; gates 15661 ms, limits 8 ms (exit 0).
  • Chips not yet run: None (all 4 Apple Silicon hardware tiers completed).

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.
  • 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.
  • 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, greedy and sampled.

ashhart and others added 30 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.
@gilby
gilby force-pushed the inkling2-lead-batched-slots branch from bd88428 to 2bc0975 Compare November 22, 2026 20:27
gilby added a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
…tch_rows=64

Rebase PR ashhart#4596 onto ashhart#4618 with 0-ULP scalar attention parity, adaptive decode chunking, up to 8-stream slot batching, and batch_rows=64. Refs ashhart#4652.
@gilby gilby changed the title inkling2 metal: batch multi-stream decode attention slots up to 8 streams and raise batch_rows to 64 inkling2 metal: GQA 3:1 decode KV sharing, multi-stream slots, and batch_rows=64 Nov 23, 2026
@gilby
gilby force-pushed the inkling2-lead-batched-slots branch from 2bc0975 to d1c8c6c Compare November 23, 2026 06:03
@gilby
gilby marked this pull request as ready for review November 23, 2026 06:03
…atch_rows=64

Rebase PR ashhart#4596 onto ashhart#4618 with 0-ULP sliding attention parity (192-thread GQA 3:1 KV sharing, up to 8-stream slots), batched prepSlots/relTable/merge across all 48 visits, exact ashhart#4618 prompt_attention on the 8 global visits, and batch_rows=64. Refs ashhart#4652.
@gilby
gilby force-pushed the inkling2-lead-batched-slots branch from d1c8c6c to 437cbea Compare November 23, 2026 06:57
@gilby gilby changed the title inkling2 metal: GQA 3:1 decode KV sharing, multi-stream slots, and batch_rows=64 inkling2 metal: GQA 3:1 sliding KV sharing, multi-stream slots, and batch_rows=64 Nov 23, 2026
@ashhart
ashhart force-pushed the lead/inkling2-mini branch 3 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

@AIFlowML

Copy link
Copy Markdown
Contributor

I reran 437cbea72c on the M5 Max. The PR head passed 120 host tests with nine skips and compiled the Mini native opener. The Metal filter passed 49 kernels and caught all 49 planted controls, with zero launch-limit problems.

zig build test-inkling2-host test-inkling2-metal-host compile-inkling2-native-host -Dfixed-cpu -j2 --summary all
zig build tf-kernel-contract -Dfixed-cpu -j2 --summary all
./zig-out/bin/tf-kernel-contract --only 'metal inkling2'

For the eventual integration, the full branch has 83 conflicts against d1ff890729. Testing just the delta from the PR's declared base ad3d31f9ff reduces that to five paths in the Metal attention, forward and state code and their tests. The macOS CI error about qwen27_core.checkpoint_file_cache is outside that delta, and current main already exports the member. I did not rerun the other CI failures or a served checkpoint.

Igor Lessio - AIFLOW LABS

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.

4 participants