Skip to content

inkling2 metal: fuse 0-ULP decode AR/loop/conv, single-CB decode, and split forward - #4593

Open
gilby wants to merge 41 commits into
ashhart:mainfrom
gilby:inkling2-lead-decode-fusion
Open

gilby wants to merge 41 commits into
ashhart:mainfrom
gilby:inkling2-lead-decode-fusion

Conversation

@gilby

@gilby gilby commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Rebases the 0-ULP decode fusions onto #4618 (single-CB decode, grid.y convs with staged rollback, grid.z loop roles, native bfloat AR, and modular forward split) while omitting dense_fuse and preserving bit-exact greedy parity.

What this changes

Collapses rows <= state.batch_rows decode execution into one Metal command buffer using GPU-staged convolution rollback (tf_ink2_stage_conv, tf_ink2_stage_conv_segs, tf_ink2_stage_conv_static, tf_ink2_commit_histories), adds stream-axis grid.y dynamic conv (tf_inkling2_conv_dynamic_segs), grid.z Q/K/V loop role dispatch (roles in InkLoopArgs), native bfloat tf_inkling2_ar_bf16, and splits forward.zig into forward.zig, forward_conv.zig, and forward_layers.zig while keeping dense_fuse, logits, experts, and attention unchanged from #4618.

Checks on this head

  • Head commit: 8c3e0c65f4 (non-Darwin CI test guard on top of 757c6772b9)
  • Lean checker, python3 tools/zig/lean_check.py: 7497 files, 167 problems (0 new vs base ad3d31f9ff); tools/pr_check.py --pr 4593 --base ad3d31f9ff: 0 error(s), 1 warning(s) (changelog reminder).
  • Tests run:
    • Host CPU & cross-compile checks on 8c3e0c65f4: zig fmt --check build.zig zig exit 0; git diff --check ad3d31f9ff..HEAD exit 0; test-inkling2-controls-host, test-inkling2-host (44 pass, 4 skip), test-inkling2-metal-host (76 pass, 6 skip), and compile-inkling2-native-host (macOS/Linux/Windows) pass; test-metal-launch-map-host 8/8 pass (1215 registered launches, 2 controls, 0 missing); test-inkling2-metal-host compiles cleanly (0 errors) for x86_64-linux and x86_64-windows.
    • Real-checkpoint test-inkling2-metal-host (at parent 757c6772b9, TF_INKLING2_METAL_DIR set to Inkling-2-Mini-ed40e7da, ReleaseFast -Dcpu=apple_m1): 81 passed; 3 skipped; 0 failed across Apple M5 Ultra, Apple M5 Pro, and Apple M3 Ultra (including 3-case GPU conv rollback test; 3 skips are DSpark-gated tests when TF_INKLING2_DSPARK_DIR is unset).
  • CI: Local host, M5 Max contract (52/52 + 52 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 55.7 vs 57.6, c=4 205.9 (st=218.7, +4.6% agg) vs 196.8, c=16 528.4 (st=663.4, +16.7% agg / +20.0% steady) vs 452.7 (st=552.8) tok/s (sha=32ddb869bec4 exact match, alone_unequal=0)
      • code T=0.0: c=1 56.8 vs 53.6 (+6.0%), c=4 213.3 (st=223.9, +7.1% agg) vs 199.1, c=16 588.6 (st=695.6, +19.8% agg / +23.1% steady) vs 491.2 (st=565.1) tok/s (sha=4490e6bbcfbd exact match, alone_unequal=0)
      • chat T=1.0: c=1 33.8 vs 34.7, c=4 59.9 (st=60.4) vs 59.4, c=16 76.6 (st=77.8) vs 71.9; code T=1.0: c=1 33.7 vs 34.4, c=4 58.5 (st=59.6) vs 57.8, c=16 73.6 (st=75.4) 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=9.0876s (min=8.9879s) vs 8.7536s ref, dec=47.7 (rep_max=47.5) 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):
      • code T=0.0: c=1 31.4 vs 31.8, c=4 113.8 (st=121.1, +2.8% agg) vs 110.7 (st=118.0, sha=4490e6bbcfbd exact match, alone_unequal=0)
      • chat T=0.0: c=1 31.1 vs 31.5, c=4 104.9 (st=117.7, +2.2% agg) vs 102.6 (st=114.6, sha=32ddb869bec4 exact match, alone_unequal=0)
      • code T=1.0: c=1 22.7 vs 22.5, c=4 39.5 (st=40.4) vs 39.1; chat T=1.0: c=1 22.9 vs 23.1, c=4 40.8 (st=42.3) vs 40.2 (exact sha set match)
      • bench_cache.py --tokens 32 --repeats 2 --streams 2 --require-cold (pt=2571): qualified=True, cold ttft_s=14.8659s (rep_min=13.3472s) vs 12.6426s ref, dec=27.9 (rep_max=27.9) 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 44.5 vs 45.3, c=4 105.0 (st=113.2, +4.1% agg) vs 100.9 (st=105.5, sha=34819971792d exact match, alone_unequal=0)
      • code T=0.0: c=1 45.0 vs 45.4, c=4 109.9 (st=115.1, +3.0% agg) vs 106.7 (st=111.7, sha=4490e6bbcfbd exact match, alone_unequal=0)
      • chat T=1.0: c=1 27.7 vs 28.4, c=4 42.8 (st=43.8) vs 43.5; code T=1.0: c=1 27.6 vs 28.3, c=4 42.9 (st=43.7) 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.6471s (rep_min=8.6163s) vs 8.7351s ref, dec=37.2 (rep_max=36.9) 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 (single-CB path triggers automatically when rows <= state.batch_rows).
  • Environment: Commit 757c6772b9 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 CB submission, conv staging/rollback, conv_dynamic_segs, loop grid.z roles, and ar_bf16 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, plus 3-case GPU conv rollback verification (beginStage, pre-commit rollback, partial-accept history commit).
  • 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:
    • Added tf_inkling2_ar_bf16 (576 threads, 720 B TG, eliminates separate widen dispatch + barrier before AR).
    • Added tf_inkling2_conv_dynamic_segs (256 threads, 128 B TG, stream-axis grid.y dynamic conv).
    • Updated tf_inkling2_loop_gates / tf_inkling2_loop_zeta / tf_inkling2_loop_blend with grid.z Q/K/V role dispatch.
    • Added tf_ink2_stage_conv, tf_ink2_stage_conv_segs, tf_ink2_stage_conv_static, and tf_ink2_commit_histories (256 threads, 0 B TG).
  • Planted controls and status: All 6 new/changed kernel controls (ar_bf16, conv_dynamic_segs, loop_messages/loop_gates, stage_conv, stage_conv_segs, stage_conv_static, commit_histories) 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 52 kernels: 52 pass gates 1-4, 0 fail, 0 known findings; 52 controls: 52 red as planted, 0 missed; 0 limit problems; gates 6564 ms, limits 17 ms (exit 0).
    • M5 Ultra (applegpu_g17): SUMMARY 52 kernels: 52 pass gates 1-4, 0 fail, 0 known findings; 52 controls: 52 red as planted, 0 missed; 0 limit problems; gates 5960 ms, limits 385 ms (exit 0).
    • M5 Pro (applegpu_g17): SUMMARY 52 kernels: 52 pass gates 1-4, 0 fail, 0 known findings; 52 controls: 52 red as planted, 0 missed; 0 limit problems; gates 6000 ms, limits 7 ms (exit 0).
    • M3 Ultra (applegpu_g15): SUMMARY 47 kernels: 47 pass gates 1-4, 0 fail, 0 known findings; 47 controls: 47 red as planted, 0 missed; 0 limit problems; gates 6264 ms, limits 9 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-decode-fusion branch from 84cc8ea to b6b4cfc Compare November 22, 2026 18:59
@gilby gilby changed the title inkling2 metal: fuse decode attention projections, compact tap state, and batch conv staging and commits inkling2 metal: fix dense_fuse seam, fuse decode ops/conv/AR/loops into one CB, and split forward Nov 22, 2026
… split forward

- Bypass 5-CB cuts for rows <= batch_rows and move verify conv backup into the forward CB with 3-case rollback.

- Fuse grid.y short-conv staging/static conv and batched dynamic conv across segments, compacting taps_bytes to window_rows.

- Fuse grid.z Q/K/V controller gates in loop.metal (256-row stride) and native bf16 tf_inkling2_ar_bf16 on the 576-thread AR.

- Split forward.zig into forward.zig, forward_layers.zig, and forward_conv.zig while keeping dense/logits/experts/attention untouched.

Refs ashhart#4652
@gilby
gilby force-pushed the inkling2-lead-decode-fusion branch from b6b4cfc to 757c677 Compare November 23, 2026 06:08
@gilby gilby changed the title inkling2 metal: fix dense_fuse seam, fuse decode ops/conv/AR/loops into one CB, and split forward inkling2 metal: fuse 0-ULP decode AR/loop/conv, single-CB decode, and split forward Nov 23, 2026
@gilby
gilby marked this pull request as ready for review November 23, 2026 06:08
@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

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.

3 participants