Skip to content

inkling2 vision: run the tower's two fp32 attention dots on 64 x 64 tiles, same bytes - #5119

Merged
ashhart merged 2 commits into
ashhart:mainfrom
BlivionIaG:feat/inkling-tower-tiles
Nov 26, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
BlivionIaG:feat/inkling-tower-tiles

Conversation

@BlivionIaG

Copy link
Copy Markdown
Contributor

What this changes

The Inkling 2 Mini image tower's two fp32 attention dots (q k^T and p v, ik2_gemm_f32_nt_* / ik2_gemm_f32_nn_*) ran one thread an output. They now run a 64 x 64 output tile a threadgroup and 4 x 4 outputs a thread, with operands staged through threadgroup memory in 16-step k chunks. Each output is still one fma chain over k from zero, in k order, so the tower's bytes do not change; the first token of an image prompt gets faster. This is the tile change promised in #4704, ported from #4337 (a305edd706) onto vision_gemm.metal.

  • Issue: Refs docs: a plan for Inkling 2 Mini on CUDA and Metal in claimable slices #4274 (Inkling 2 Mini, Metal image tower). Not a new arithmetic: the sum order of every output is unchanged.
  • Stacked on: main 69b1fdf59b; one commit, de5952ae11.
  • atc overlap --json: not run (no ATC session on this machine); gh pr list shows no open pull request touching zig/kernels/metal/inkling2/vision_gemm.metal.

Files: vision_gemm.metal (the tiled dot), metal/vision_gemm.zig (dispatch by groups), inkling2_vision_metal_records.zig (declares the 8,704 bytes of threadgroup memory), metal/vision_test.zig (a device test: both kinds bit for bit against a host @mulAdd chain, batched with padded pitches and strides, whole and ragged tiles), metal_inkling2_vision_controls.zig + metal_inkling2_vision.zig (a planted control that drops the last k).

Checks on this head

  • Head commit: de5952ae11.
  • Lean checker on the base and this head: 164 and 164, 0 new (python3 tools/pr_check.py --base 69b1fdf59b: 0 errors, 4 advisory warnings: no --pr number yet, three inherited import cycles). zig fmt --check build.zig zig: clean.
  • Tests run:
    • Apple M4 Pro (no tensor units) and Apple M5 Ultra: zig build test-inkling2-media-metal with the original checkpoint (TF_INKLING2_METAL_DIR): pass on both (M4 Pro: 26 pass, 2 skip, 0 fail on the stacked head; the skips are the JPEG tests, libjpeg-turbo here is not the pinned 3.1.4.1).
    • M4 Pro: zig build test-kernel-contract: pass.
    • tf-kernel-contract --only "inkling2 vision" (see Kernel contract).
  • CI: not yet run (no pull request).
  • Not run, and why: the whole zig build test test-golden; M1 to M3 (no such Mac here); CUDA and HIP (not touched).

Receipt

  • Main against branch: both served, same machine and checkpoint, three binaries (main, this, Cannot get more than 8% GPU utilization on M4 with 48 gb (even using --resident-budget 30 GiB for example) #2 stacked) in turn A B C C B A, one server each, serve --vision --context 8192 --parallel 1 --no-drafts --prompt-cache-gib 0 --no-thinking, cold first token of each picture (max_tokens 1), then greedy 48-token replies on five pictures.
  • Boxes it reaches: Macs serving Inkling 2 Mini with --vision. Text-only prompts do not run the tower.
  • New switch? None.
  • Environment: main 69b1fdf59b, head de5952ae11; Zig 0.17.0, Xcode's Metal toolchain; Apple M4 Pro 48 GB and Apple M5 Ultra; thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7; -Doptimize=ReleaseFast.
  • Paths and platforms: the tower's attention on every image (the only caller of the two kinds). Ran: M4 Pro (pre-M5 path), M5 Ultra. Not run: M1 to M3.
  • Exactness: the tower's output SHA-256 (inkling2 image tower: ... sha256= log line) is equal main against branch for all five PNG pictures in every session, and the five greedy replies' hashes are equal (M5 Ultra and M4 Pro). The device test checks every output bit against the serial fma chain.
  • First token, cold, A-B-B-A (seconds):
Machine Picture (prompt tokens) main this branch
M5 Ultra invoice, PNG (1,551) 6.83 / 6.85 4.85 / 4.85
M5 Ultra scene, PNG (541) 1.77 / 1.75 1.52 / 1.50
M5 Ultra chart, PNG (197) 0.563 / 0.564 0.533 / 0.535
M4 Pro invoice, PNG (1,551) 19.07 / 19.13 10.14 / 10.39
M4 Pro scene, PNG (541) 4.26 / 4.31 2.82 / 2.83
M4 Pro chart, PNG (197) 1.080 / 1.091 0.961 / 0.974

M4 Pro load average 4.3 before and 2.5 after the run (a shared machine; the order cancels drift). Tower hashes differ between the two chips (the M5 projections run on tensor units), and within each chip main equals the branch.

  • Decode speed: n/a, the tower runs before the first token only.
  • Licence of any new weights or drafter: n/a.
Kernel contract
  • Kernels registered with the contract: the existing ik2_gemm_f32_nt_{00,01,10,11} and ik2_gemm_f32_nn_* records now declare 8,704 threadgroup bytes; the kernel they replace is the one-thread-an-output dot of the same names.
  • Planted control: control: metal inkling2 vision ik2_gemm_f32_nt drops the last k, red as planted on both chips.
  • tf-kernel-contract --only "inkling2 vision", exit 0:
    • M4 Pro: SUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 12 controls: 12 red as planted, 0 missed; 0 limit problems
    • M5 Ultra: SUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 11 controls: 11 red as planted, 0 missed; 0 limit problems (the 8x8 small-row control runs only without tensor units)
  • Chips I could not run: M1 to M3.

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. (The bit test passes on main's one-thread dot too, by design: it pins the bits this change must keep; the planted control is the failing side.)
  • 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. (Unchanged: the tower's bytes are equal.)
  • No precision traded for speed. The bits do not change.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted.

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @BlivionIaG for the unusually careful exactness coverage. The staging maps both NT and NN operands into complete 16-step chunks, guards every ragged edge, and preserves one scalar FMA chain from zero in ascending k order for each output. The barriers protect prefetch/staging reuse, the float4 operations are loads rather than reassociated arithmetic, and dispatch covers exactly the 64x64 tiles and batches. The 8,704-byte records, padded-stride host bit comparisons and dropped-last-k planted control all check out.

I credit the supplied M4 Pro and M5 Ultra original-checkpoint tower hashes, equal greedy replies, contract summaries and faster cold-first-token samples as your evidence. It is ready for our device check. The remaining qualification is one Apple M3 Ultra cell with the same pinned original Inkling 2 Mini revision: pass the NT/NN bit tests and complete vision contract with the dropped-last-k control red, then compare main and the resolved candidate on the same five serial image prompts. Require equal tower hashes and greedy token hashes, plus an alternated cold-first-token no-slower check. No source correction is requested.

  • Synthena

BlivionIaG and others added 2 commits November 26, 2026 03:15
- q k^T and p v ran one thread an output; a 64 x 64 tile a group and 4 x 4 outputs a thread, operands staged through threadgroup memory, make them several times faster.
- Every output is still one fma chain over k from zero, so the tower's output is bit-for-bit what it was: a device test now checks both kinds bit for bit against that chain, and a planted control drops the last k.
- The launch record declares the 8.7 KB of threadgroup memory.
@ashhart
ashhart force-pushed the feat/inkling-tower-tiles branch from de5952a to 9b97a14 Compare November 26, 2026 03:16
@ashhart
ashhart merged commit 4961ed0 into ashhart:main Nov 26, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thank you @BlivionIaG. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit that referenced this pull request Nov 26, 2026
ashhart added a commit that referenced this pull request Nov 26, 2026
ashhart added a commit that referenced this pull request Nov 26, 2026
ashhart added a commit that referenced this pull request Nov 26, 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