Skip to content

inkling2 metal: zero-split-K 64-pair NVFP4 prefill units (0 B TG, 0 barriers) - #4784

Open
cwschroeder wants to merge 22 commits into
ashhart:mainfrom
cwschroeder:pr/inkling2-m5max-nvfp4-prefill-zsk
Open

cwschroeder wants to merge 22 commits into
ashhart:mainfrom
cwschroeder:pr/inkling2-m5max-nvfp4-prefill-zsk

Conversation

@cwschroeder

Copy link
Copy Markdown
Contributor

What this changes

Stacked on #4777 (88c45204f, over lead/inkling2-mini 3e0e9bcb8). Note: modifies experts_units.metal, which is also touched by #4689.

  • Zero-split-K 64-pair NVFP4 prefill units (tf_ink2_nvfp4_gu_units, tf_ink2_nvfp4_down_units in experts_units.metal, experts.zig, inkling2_units_metal_records.zig):
    • Replaces 8-way split-K (256 threads, 8 KiB TG scratch, 2 barriers per 8 pairs, 32-pair bands) on NVFP4 prefill with 4 simdgroups along N (128 weight rows per TG, 128 threads, 0 B TG memory, 0 barriers) accumulating 64-pair bands (lo0..3, hi0..3) with direct register-to-global bfloat2/bfloat4 stores.
    • Halves NVFP4 weight reads and dequantization for every expert receiving 33-64 pairs per 512-token chunk, increases L1 reuse of X 4x across the 4 simdgroups, and removes all split-K barrier and epilogue stalls.
  • Preserves 8-way split-K on MXFP8 (tf_ink2_mxfp8_gu_units, tf_ink2_mxfp8_down_units):
    • Interleaved A/B benchmarking showed bandwidth-heavier MXFP8 (2x weight bytes vs NVFP4) regressed +12.8%/+18.4% without 8-way split-K; keeping MXFP8 on 256 threads / 8 KiB TG preserves full MXFP8 speed (-1.2%/-2.6%).
  • Leaves verify/decode untouched: _1 and _active kernels are unchanged, preserving 100% bit-exact width invariance (--no-drafts vs drafted verify).

Checks on this head

  • zig fmt --check build.zig zig: PASS (Zig 0.17.0)
  • tools/pr_check.py --base origin/lead/inkling2-mini: 0 errors (lean 167 vs 167, 0 new, all modified files <= 600 lines)
  • zig build native -Doptimize=Debug: PASS
  • zig build test-inkling2-controls-host test-inkling2-metal-host test-metal-launch-map-host: PASS (1235 registered launches, 2 controls, 0 missing)
  • GPU contract suite on Apple M5 Max (applegpu_g17, tensor units true):
    • tf-kernel-contract --only "inkling2 units": 4/4 kernels pass Gates 1-4, 4/4 controls red as planted, 0 limit problems (128 threads / 0 B TG for NVFP4; 256 threads / 8192 B TG for MXFP8)

Receipt

  • Environment: Apple M5 Max (40-core GPU, Metal 4, 128 GiB), Zig 0.17.0, thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7 (unmodified BF16+NVFP4+MXFP8), AC power, powermode 0.
  • Exactness: 100% bit-exact greedy decode (sha=22ca50f2d47b) and bit-exact width invariance (plain == draft greedy 4ee138579f02 and temp=1.0 cf570e19b8bb).
  • Interleaved ctl -> cand -> ctl A/B (beats_both=True on prefill and decode, no regression):
    • Clock-normalized Metal 4 prefill timeline (normalized to untouched tf_ink2_attn_prompt_sliding):
      • tf_ink2_nvfp4_gu_units: -21.1% (~-26.4 ms/chunk at cold clock)
      • tf_ink2_nvfp4_down_units: -11.1% (~-6.0 ms/chunk at cold clock)
      • tf_ink2_mxfp8_gu_units: -1.2% / tf_ink2_mxfp8_down_units: -2.6% (0 regression)

@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @cwschroeder for the Inkling 2 Metal work. I found one small cleanup to make here.

  • In zig/src/families/deepseek_v41/metal/mv_mma.zig:30-33, loadSource creates both pipelines inside the return literal. If the BF16 pipeline fails after the f32 one succeeds, the f32 pipeline leaks. Inkling 2 now reaches this from zig/src/families/inkling2/metal/model.zig:277, and the errdefer on the next line isn't registered yet. Please create f32 in a local, add errdefer f32_pipe.deinit(), then create BF16 and return both.

  • Synthena

@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:47
@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

@cwschroeder
cwschroeder force-pushed the pr/inkling2-m5max-nvfp4-prefill-zsk branch 2 times, most recently from f09ccef to 78ea28c Compare November 24, 2026 10:16
sethforprivacy and others added 17 commits November 24, 2026 12:06
…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.
…size prompt part_o by capacity, and widen glue/loop scratch to 512

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