Skip to content

Inkling 2 Mini on Metal: 512-row prefill chunks, sliding NAX prompt attention, and mv_mma dense prefill (620 to 1,287 tok/s on M5 Ultra) - #4543

Closed
gilby wants to merge 33 commits into
ashhart:lead/inkling2-minifrom
gilby:inkling2-lead-prefill-512
Closed

gilby wants to merge 33 commits into
ashhart:lead/inkling2-minifrom
gilby:inkling2-lead-prefill-512

Conversation

@gilby

@gilby gilby commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

What this changes

Before: on #4523 (stacked on lead/inkling2-mini), state.zig capped prefill chunks at max_rows = 64, attention_plan.zig:usePrompt restricted tf_ink2_attn_prompt to global layers (l.window == 0), and forward.zig:dense() looped 32-row scalar matvecs even during prefill (~620 tok/s 20.5K cold prefill on Apple M5 Ultra). After: widens max_rows / prompt_rows to 512 (with logits_all capped at batch_rows = 32 to save 384 MiB), extends tf_ink2_attn_prompt with register-cached Q and sliding-window (window > 0, partials_rh = 1) support for rows > 64, and routes dense() (rows > 32) through bit-exact dsv41_metal.mv_mma, raising 20.8K cold prefill from 620.3 to 1,286.7 tok/s (2.07x) while preserving decode speeds (49.7 tok/s plain c=1, 156.0 tok/s plain c=4 steady, 63.1 tok/s DSpark c=1, 144.3 tok/s DSpark c=4 steady).

Checks on this head

Receipt

  • Main against branch (vs #4523 + #4465 baseline on thinkingmachines/Inkling-2-Mini ed40e7da625f594fc9c4990f5f66be24873c22d7, Apple M5 Ultra 512 GiB, --prompt-cache-gib 0, T=0.0):
    • Cold prefill (512/2K/8K/16K unique-salt sweep):
      • L~512 (~830 tok): 447.5 tok/s → 696.4 tok/s (+56%)
      • L~2048 (~2,780 tok): 592.0 tok/s → 1,057.5 tok/s (+79%)
      • L~8192 (~10,530 tok): 630.9 tok/s → 1,286.7 tok/s (2.04x)
      • L~16384 (~20,810 tok): 620.3 tok/s (33.1s TTFT) → 1,285.6 tok/s (16.2s TTFT, 2.07x)
    • Decode & concurrent (zero regression):
      • Plain c=1 gpu-chat: 49.7 tok/s → 49.65 tok/s; Plain c=4 steady: 156.3 → 156.0 tok/s
      • DSpark c=1 gpu-chat: 63.11 tok/s → 63.11 tok/s; DSpark c=4 agg: 136.4 → 138.4 tok/s
  • Boxes it reaches: inkling2 Metal prompt_attention.metal, attention_plan.zig, attention.zig, state.zig, experts.zig, forward.zig, model.zig.
  • New switch? No.
  • Environment: Base #4523 (ee248f9e3c), head d800406adc, Zig 0.17.0, Xcode Metal 4.0 toolchain, Apple M5 Ultra 512 GiB / M5 Pro 64 GiB (macOS 27.2.1) & M3 Ultra 512 GiB (macOS 26.6.2), thinkingmachines/Inkling-2-Mini ed40e7da625f594fc9c4990f5f66be24873c22d7.
  • Paths and platforms the change reaches: Metal inkling2 prompt prefill (rows > 32 for mv_mma, rows > 64 for sliding/global tf_ink2_attn_prompt); verified on M5 Ultra, M5 Pro, and M3 Ultra.
  • Exactness: mv_mma is bit-equal to mv; sliding tf_ink2_attn_prompt uses the same BF16 P@V contract as global tf_ink2_attn_prompt; plain == DSpark == warm_cached verified bit-identical (sha=2fb59b60ffd3).
  • Main against this branch: Same-machine before/after numbers posted above.
  • Decode speed before and after: Posted above from tools/bench_openai.py.
  • Prompt speed before and after: Posted above from cold unique-salt sweep (--prompt-cache-gib 0).
  • 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 the kernel each one replaces:
    • tf_ink2_attn_prompt (extended to sliding window > 0 for rows > 64 and register-cached Q; already registered in inkling2_attention_metal_records.zig and tested in metal_inkling2_attention.zig)
    • tf_dsv41_mv_mma_bf16 (already registered & contract-verified across M1–M5)
  • A planted control for each new kernel, and each one fails as planted:
    • Existing metal_inkling2_attention_controls.zig controls all remain red as planted (45/45 on M5, 41/41 on M3).
  • Each backend's SUMMARY line and exit status:
    • Apple M5 Ultra (applegpu_g17, tensor units true): SUMMARY 45 kernels: 45 pass gates 1-4, 0 fail, 0 known findings; 45 controls: 45 red as planted, 0 missed; 0 limit problems; gates 5664 ms, limits 389 ms (exit 0)
    • Apple M5 Pro (applegpu_g17, tensor units true): SUMMARY 45 kernels: 45 pass gates 1-4, 0 fail, 0 known findings; 45 controls: 45 red as planted, 0 missed; 0 limit problems; gates 5602 ms, limits 7 ms (exit 0)
    • Apple M3 Ultra (applegpu_g15, tensor units false): SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 41 controls: 41 red as planted, 0 missed; 0 limit problems; gates 5641 ms, limits 566 ms (exit 0)
  • Chips I could not run: Apple M1, M2, M4 (static Gate 5 limits verified across M1–M5 with 0 problems).

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.
  • 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.
sethforprivacy and others added 3 commits November 21, 2026 22:42
…t attention, and use mv_mma for prompt dense projections
@gilby

gilby commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded on lead/inkling2-mini: its exact 32-row logits_all scratch cap was extracted into #4594, its sliding NAX prompt attention was rejected on #4652 for BF16 rounding drift, and wide prompt prefill is covered by #4631, #4644 (1,024-row chunks and ~12 MB scratch taps), and #4756.

@gilby gilby closed this Nov 23, 2026
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