Skip to content

inkling2 vision: keep the tower's attention scores in bf16, same bytes - #5120

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

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

Conversation

@BlivionIaG

Copy link
Copy Markdown
Contributor

What this changes

The Inkling 2 Mini image tower kept its attention score matrix in fp32 between q k^T, the softmax and p v. Every value it held there was already a bf16 number (the softmax rounded bf16(bf16(qk) * scale) on entry and stored bf16(p) on exit), so it now stores bf16: q k^T's epilogue writes bf16(bf16(sum) * scale), the softmax reads and writes bf16 with the same max, exponentials and sum order, and p v reads the bf16 probabilities (exact in fp32). The bytes the tower hands to the text model do not change; the score traffic halves. Ported from #4337 (aff3d5fc55).

Files: vision_gemm.metal (the dot is templated on operand and output type; score_nt stores the scaled bf16 score, prob_nn reads bf16 probabilities), vision.metal (ik2v_softmax on bf16, the scale argument moves to the GEMM), metal/vision.zig and metal/vision_gemm.zig (kinds f32_nt / f32_nn become score_nt / prob_nn, Shape.scale, the score scratch is bf16 so a query chunk holds twice the rows), the records, the device test (both kinds bit for bit against the host fma chain and its two roundings), the contract's GEMM and softmax probes, and a planted control that drops the score scale.

Checks on this head

  • Head commit: ce75508a29.
  • Lean checker on the base and this head: 164 and 164, 0 new (python3 tools/pr_check.py --base de5952ae11: 0 errors, 4 advisory warnings: no --pr number yet, three inherited import cycles). zig fmt --check build.zig zig: clean.
  • Tests run:
    • M4 Pro: zig build test-inkling2-media-metal with the original checkpoint: 26 pass, 2 skip (JPEG, libjpeg-turbo not the pinned 3.1.4.1), 0 fail. M5 Ultra: pass.
    • M4 Pro: zig build test-kernel-contract --summary all: success.
    • 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; CUDA and HIP (not touched).

Receipt

  • Main against branch: same session as inkling2 vision: run the tower's two fp32 attention dots on 64 x 64 tiles, same bytes #5119's receipt: main, inkling2 vision: run the tower's two fp32 attention dots on 64 x 64 tiles, same bytes #5119 and this head served in turn A B C C B A, serve --vision --context 8192 --parallel 1 --no-drafts --prompt-cache-gib 0 --no-thinking, cold first token per picture, then greedy 48-token replies on five pictures.
  • Boxes it reaches: Macs serving Inkling 2 Mini with --vision.
  • New switch? None.
  • Environment: main 69b1fdf59b, parent de5952ae11, head ce75508a29; 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. Ran: M4 Pro, M5 Ultra. Not run: M1 to M3.
  • Exactness: the tower's output SHA-256 is equal main against this head for all five PNG pictures in every session, and the five greedy replies' hashes are equal (M5 Ultra and M4 Pro).
  • First token, cold, A-B-B-A (seconds):
Machine Picture (prompt tokens) main #5119 this head
M5 Ultra invoice, PNG (1,551) 6.83 / 6.85 4.85 / 4.85 4.54 / 4.54
M5 Ultra scene, PNG (541) 1.77 / 1.75 1.52 / 1.50 1.46 / 1.47
M5 Ultra chart, PNG (197) 0.563 / 0.564 0.533 / 0.535 0.530 / 0.529
M4 Pro invoice, PNG (1,551) 19.07 / 19.13 10.14 / 10.39 9.93 / 9.92
M4 Pro scene, PNG (541) 4.26 / 4.31 2.82 / 2.83 2.78 / 2.80
M4 Pro chart, PNG (197) 1.080 / 1.091 0.961 / 0.974 0.962 / 0.961

M4 Pro load average 4.3 before and 2.5 after (shared machine). Against #5119 alone: invoice -6.4 % on the M5 Ultra and -3.3 % on the M4 Pro; scene and chart are within the noise.

  • Decode speed: n/a, the tower runs before the first token only.
  • Licence of any new weights or drafter: n/a.
Kernel contract
  • Kernels: ik2_gemm_score_nt_* and ik2_gemm_prob_nn_* replace ik2_gemm_f32_nt_* and ik2_gemm_f32_nn_*; ik2v_softmax takes bf16 scores. The GEMM probe stores the scores scaled (1/8) and fills the probabilities as bf16; the softmax probe takes bf16 scores.
  • Planted controls: control: metal inkling2 vision ik2_gemm_score_nt drops the score scale (new) and ... ik2_gemm_score_nt drops the last k; both red as planted.
  • tf-kernel-contract --only "inkling2 vision", exit 0:
    • M4 Pro: SUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 13 controls: 13 red as planted, 0 missed; 0 limit problems
    • M5 Ultra: SUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 12 controls: 12 red as planted, 0 missed; 0 limit problems
  • 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.
  • 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. The QK epilogue preserves both BF16 roundings, softmax keeps the same max/exp/sum order, and PV widens the BF16 probabilities exactly before the unchanged serial FMA chain. The scratch sizes, query strides, kernel renames, launch records, probes, and both planted controls are consistent. The supplied exact-output and focused-contract evidence closes the review.

It is ready for our device check once #5119 lands. The remaining qualification is one Apple M3 Ultra stacked-head cell with the pinned original Inkling 2 Mini revision: both exact dot tests, the complete vision contract including the scale and dropped-last-k controls, equal tower and greedy-token hashes on the five serial image prompts, and an alternated cold-first-token no-slower check. No source correction is requested.

  • Synthena

@ashhart
ashhart force-pushed the feat/inkling-tower-bf16-scores branch from ce75508 to 8c7d22f Compare November 26, 2026 08:41
BlivionIaG and others added 2 commits November 26, 2026 11:52
- q k^T's epilogue stores bf16(bf16(sum) * scale), the softmax reads and writes bf16 with the same max, exps and sum order, p v reads the bf16 probabilities.
- Every value the score matrix held between the kernels was already a bf16 number, so the bytes are the same and the softmax's memory traffic halves.
- The dot kinds f32_nt / f32_nn become score_nt / prob_nn; the device test checks both bit for bit against one fma chain and its roundings; the softmax probe takes bf16 scores; a planted control drops the score scale.
@ashhart
ashhart force-pushed the feat/inkling-tower-bf16-scores branch from 8c7d22f to b57317a Compare November 26, 2026 11:52
@ashhart
ashhart merged commit 3c52cf3 into ashhart:main Nov 26, 2026
2 of 12 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.

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