Skip to content

Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo - #4446

Closed
sethforprivacy wants to merge 21 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-serves
Closed

sethforprivacy wants to merge 21 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-serves

Conversation

@sethforprivacy

@sethforprivacy sethforprivacy commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: on #4387's head the native server does not compile; once it does, every Metal reply is token 0, because norm() binds sp_norm's output and its arguments in each other's slots; and with that fixed, every stream after the first in a shared forward is wrong, because its relative rows are read from past the end of their scratch. After: zig build native compiles, the Metal path answers correctly on the released checkpoint, and concurrent replies equal their solo runs.

This is a proposal on top of #4387, opened as a draft so the fixes can be read as commits. Take them into #4387 in whatever form suits you.

The three commits:

  1. The native build. core/checkpoint_metal.zig and metal/model.zig use @import("core").checkpoint_file_cache and @import("core").checkpoint.shardFiles. core/root.zig has both; the native root tensorfold.zig has neither (there checkpoint is checkpoint_metal). The fix exports checkpoint_file_cache from tensorfold.zig and takes shardFiles from checkpoint_host, which both roots name the same.
  2. The norm. sp_norm takes its arguments at buffer 2 and its output at 3. norm() bound the output at 2 and the arguments at 3, so the kernel read a width of 0 from the zeroed output buffer and wrote nothing. Every normed input stayed zero, and so did the logits.
  3. The shared forward. rel_prep holds rel_width (384) BF16 values a row, 768 bytes. attendSegments offset a segment's rows in it by base * 24 * ap.extent * 2, 49,152 bytes a row, which is rel_tab's stride. Segment 0 is at offset 0 either way, so one stream is right; a later segment's tf_ink2_prep wrote, and its tf_ink2_rel_table read, past the end of the buffer. The offset is now base * state.rel_width * 2 in both places.

Checks on this head

  • Head commit: 97c91058f, on Inkling 2 Mini on CUDA and Metal #4387's 3e0e9bcb83.
  • Lean checker, on the base and on this head: 167 and 167, 0 new (lean_new.py, this head's checker on both).
  • Tests run, with the command and pass, fail and skip counts:
    • zig build native -Dcpu=apple_m1: compiles (on 3e0e9bcb83 it stops with the two errors above).
    • zig build test-inkling2-metal-host test-inkling2-host test-inkling2-controls-host test-inkling2-launch-map-host test-inkling2-metal-capabilities compile-inkling2-native-host -Dcpu=apple_m1: exit 0.
    • tf-kernel-contract --only inkling2 (-Doptimize=safe): SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 41 controls: 41 red as planted, 0 missed; 0 limit problems, exit 0.
    • zig fmt --check build.zig zig and git diff --check: clean.
  • CI: not yet reported when this was written.
  • Not run, and why: the whole zig build test test-golden on this exact head. On the same two commits with the later speed commits on top it leaves 7 failed steps, and Inkling 2 Mini on CUDA and Metal #4387's own head leaves the same ones plus its two compile errors (rollback_test lone keep twice, the DeepSeek vision_config test twice, cuda_keep_others_test, contract.registry, and the memcpy link check). No test for the norm binding or the segment offset is added: nothing in the tree runs forward.zig on a device without a checkpoint, and I did not want to invent a fixture for your branch. The two-segment comparison above would make that test once a fixture exists. CUDA, HIP, Linux and Windows are not reached.

Receipt

  • Main against branch: main does not serve this model. Against Inkling 2 Mini on CUDA and Metal #4387's head: it does not compile; with only the build fix it serves token 0.
  • Boxes it reaches: Macs, the inkling2_loop Metal path only.
  • New switch? Default, accepted values, profile row: none.
  • Environment: head c68340d31, Zig 0.17.0, Xcode's Metal toolchain, Mac Studio M5 Ultra (256 GB), macOS 27.0, thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7. The load also needs the pread cap of checkpoint_metal: clamp pread chunks to INT_MAX #4433 or Metal loader: a checkpoint span of 16 GiB or more loads (each pread capped at 1 GiB) #4435, applied locally for every run here.
  • Paths and platforms the change reaches, which I ran and which I could not: Metal on M5 (run). M1 to M4 not run.
  • Exactness:
    • Greedy chat, "What is 17 times 23? Reply with just the number.": 391 in 50 tokens, token_sha 0bf3c7a5bfdb.
    • Against oMLX 0.8.1's model on the same checkpoint, on the start-up warm-up's 64 ids from a fresh cache: the state entering each visit has cosine at least 0.99998 at the first position; over all 64 positions the median is 0.9989 and the minimum 0.967; the last row's logits have cosine 0.99975 and the same top five.
    • Concurrent equals solo with the third commit, and did not before it. Two different greedy chat requests at once on --parallel 4, 16 tokens each, Inkling 2 Mini on CUDA and Metal #4387's kernels untouched: before, the first matches its solo token_sha and the second does not (0f4d5903a542 solo, 99d692cea3cc together); after, both match. How it was found: two caches fed different prompts, then 40 teacher-forced steps each run solo and as the two segments of one runShared, comparing logits. Before: segment 0's worst difference is 0 and segment 1's is 3.7 to 8.9 at every step, with rel_tab the first scratch buffer that differs in the first visit. After: 0 for both over all 40 steps. With the speed commits of Inkling 2 Mini on Metal: experts, gates, router, depth mix, combine, row batching, attention chunks and a concurrent forward (1,159 to 14 ms a row on M5 Ultra) #4448 on top, bench_concurrent.py --alone --serial at four streams gives 12 of 12 equal, plain and with the drafter.
  • Main against this branch, same machine and checkpoint: n/a, see above.
  • Decode speed before and after, from tools/bench_openai.py: not run at this head. A 50-token reply decodes at 0.86 tok/s; the breakdown is in the report on Inkling 2 Mini on CUDA and Metal #4387, and the speed work is its own draft.
  • Prompt speed before and after: a 29-token prompt takes 1.46 s.
  • Licence of any new weights or drafter, or "n/a": n/a.

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. (No new test, see "Not run".)
  • 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. (Concurrent equals solo now. A prompt fed in chunks of 64, 16, 7 or 1 rows gives the same token_sha. Resumed from a kept state not run.)
  • 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. (Main does not serve the model.)

ashhart and others added 20 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.
This was referenced Nov 22, 2026
@ashhart
ashhart force-pushed the lead/inkling2-mini branch 4 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:50
@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

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @sethforprivacy. Every commit this PR adds is now on main inside #4387 with your authorship kept, so it ships with Inkling 2 Mini on Metal in the next release. Closing this one as landed there.

  • Synthena

@ashhart ashhart closed this Nov 24, 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.

2 participants