Repository navigation
inkling2 vision: keep the tower's attention scores in bf16, same bytes - #5120
Conversation
|
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.
|
ce75508 to
8c7d22f
Compare
- 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.
8c7d22f to
b57317a
Compare
|
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. |
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 storedbf16(p)on exit), so it now stores bf16: q k^T's epilogue writesbf16(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).feat/inkling-tower-tiles,de5952ae11, the tiled dot this edits); one commit,ce75508a29. Against main69b1fdf59bthe stack is two commits.atc overlap --json: not run (no ATC session on this machine); no open pull request touches these files besides inkling2 vision: run the tower's two fp32 attention dots on 64 x 64 tiles, same bytes #5119.Files:
vision_gemm.metal(the dot is templated on operand and output type;score_ntstores the scaled bf16 score,prob_nnreads bf16 probabilities),vision.metal(ik2v_softmaxon bf16, the scale argument moves to the GEMM),metal/vision.zigandmetal/vision_gemm.zig(kindsf32_nt/f32_nnbecomescore_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
ce75508a29.python3 tools/pr_check.py --base de5952ae11: 0 errors, 4 advisory warnings: no--prnumber yet, three inherited import cycles).zig fmt --check build.zig zig: clean.zig build test-inkling2-media-metalwith the original checkpoint: 26 pass, 2 skip (JPEG, libjpeg-turbo not the pinned 3.1.4.1), 0 fail. M5 Ultra: pass.zig build test-kernel-contract --summary all: success.tf-kernel-contract --only "inkling2 vision"(see Kernel contract).zig build test test-golden; M1 to M3; CUDA and HIP (not touched).Receipt
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.--vision.69b1fdf59b, parentde5952ae11, headce75508a29; Zig 0.17.0, Xcode's Metal toolchain; Apple M4 Pro 48 GB and Apple M5 Ultra;thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7;-Doptimize=ReleaseFast.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.
Kernel contract
ik2_gemm_score_nt_*andik2_gemm_prob_nn_*replaceik2_gemm_f32_nt_*andik2_gemm_f32_nn_*;ik2v_softmaxtakes bf16 scores. The GEMM probe stores the scores scaled (1/8) and fills the probabilities as bf16; the softmax probe takes bf16 scores.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:SUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 13 controls: 13 red as planted, 0 missed; 0 limit problemsSUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 12 controls: 12 red as planted, 0 missed; 0 limit problemsChecklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Unchanged: the tower's bytes are equal.)