Skip to content

metal: the image steps' threadgroup sums and the bf16 bias from the vision glue (#2251) - #5047

Merged
ashhart merged 2 commits into
ashhart:mainfrom
jschmied:dedup-2251-vision
Nov 25, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
jschmied:dedup-2251-vision

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

Part of #2251 (group: the vision sums and bias). Head 0814748, one commit on main 0a5c699.

What changes

  • Sums and max. Seven helpers were copies of prefill/vision_glue.metal's tf_vis_sum and tf_vis_max:
    • Qwen-Image's qi_sum, MOSS-Image's mi_sum;
    • Unlimited-OCR-2's uv_sum (image encoder), ud_sum and ud_max (decoder);
    • Idol's id_sum, DINOv3's dn_sum.
  • They are deleted. Those libraries now start with the vision glue (after their template, where they have one) and call tf_vis_sum / tf_vis_max. vision_glue.metal now includes metal_stdlib itself, so it can also head the two OCR libraries, which have no template ahead of it.
  • Bias. GLM's glmv_bias and Qwen-VL's qwv_bias had the same body, bf16(y + b) after the rounded product. Both come from TF_VIS_BIAS(NAME) in the vision glue; qwv_bias keeps its max_total_threads_per_threadgroup(256).
    • Not merged, because the math differs: s5v_bias and uv_bias check bounds, and uv_bias and mi_bias round once from fp32 sums.
  • The per-file *_bf one-liners stay: MOSS-Image's planted controls edit text that names mi_bf.
  • One contract control changes its text, not its edit: metal_uocr_vision.zig's norm_mean_over_threads named uv_sum. Its line alone now also matches the vision glue's LayerNorm macro in the assembled OCR source, so the edit includes the line before; it still matches once and still goes red.
  • Kernel names and signatures are unchanged. 12 files, +49 −158.

Core vs backend-only: the shared Metal piece is prefill/vision_glue.metal (already shared by the four towers and Inkling 2's image tower); the rest is each family's Metal source and its assembly in sources.zig. No CUDA files.

Same bits (M3 Pro, no tensor units; macOS 27.2, metal 32023.921, Zig 0.17.0; main 0a5c699 against this head)

  • IR, -std=metal4.1 -S -emit-llvm under each library's flags, from zig build emit-metal-runtime-sources with and without tensor units. Idol, DINOv3, MOSS-Image, Qwen-Image and both OCR libraries were assembled through frags.source, as this Mac compiles them.

    • glm_vision (94 functions), core_qwen_vision (92), step5_vision (93), both Gemma 4 vision libraries (94), qwen_image (41; fp32-PV 34), idol (111), idol_dino (72), uocr (13), uocr_decoder (13), moss_image (42; fp32-PV 35): every function identical, in the same order.
    • Inkling 2's image tower (inkling2/vision_sources.zig, which also starts with vision_glue.metal), through frags.source as its loader and contract compile it: 85 functions without tensor units, 84 with, identical.
    • Only ModuleID and the source path differ.
  • Kernel contract, tf-kernel-contract --only, main = head (logs identical apart from timings):

    • uocr: 30 pass gates 1-4, 0 fail; 30/30 controls red, including the edited norm_mean_over_threads; 0 limit problems;
    • idol: 13 pass, 0 fail; 12/12 red; 0 limit problems;
    • vision: 40 pass, 0 fail; 33/33 red; 0 limit problems;
    • inkling2 vision: 13 pass, 0 fail; 11/11 red; 0 limit problems;
    • image: 31 pass, 0 fail; 34/34 red;
    • moss: 0 gated kernels on this Mac, limits 28 launches, 0 problems.
    • The Idol, DINOv3, Idol decoder and MOSS-Image contracts are M5-only, so not run here. The GLM, Qwen-VL, Step-5, Gemma 4 towers and Qwen-Image have no gated contract on this Mac; for those the IR above is the evidence.
  • Family checks: test-contract-images-host test-qwen-vision-weights-host test-glm-image-cache-host test-gemma4-tower-host test-vision-cli-host test-kernel-symbols-host test-inkling2-controls-host test-inkling2-metal-host, the MOSS-Image rotary, teacher and generate host tests, and test-idol-cuda-host: 54/54 steps, 322/328 tests (6 skipped). test-inkling2-media-metal (the tower on this GPU): 24/27 (3 skipped) on head and main. test-uocr does not compile on main 0a5c699 either (std.mem.zeroes in uocr/serve.zig), so it is not in this list.

  • Served hash: not run. Every served library's IR is identical, so no reply can change; for the same reason no seeded, resume, concurrency or refusal checks against main.

  • x86 CI green on this head: zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths: 2622/2622 steps, 26970/27137 tests (167 skipped); check-native-cuda-host compile-cuda-tests 21/21; pr_check 0 errors; lean 164 vs 164 on main, 0 new; zig fmt --check and git diff --check clean.

Proposed CHANGELOG line (for you to place):

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. The seven reduction helpers and both bias bodies keep their existing arithmetic. Qwen-VL's thread reservation and the bias rounding are retained, and the revised OCR control still matches once.

This looks ready to land through the usual checks. The compiler evidence and the limits of the chip coverage are recorded.

  • Synthena

jschmied and others added 2 commits November 25, 2026 16:28
…ision glue (ashhart#2251)

Qwen-Image's qi_sum, MOSS-Image's mi_sum, Unlimited-OCR-2's uv_sum, ud_sum and ud_max, Idol's id_sum and
DINOv3's dn_sum were copies of vision_glue.metal's tf_vis_sum and tf_vis_max. Those libraries now start with the
vision glue and call its helpers; vision_glue.metal includes metal_stdlib itself, so the OCR libraries, which
have no template ahead of it, compile it too.
GLM's glmv_bias and Qwen-VL's qwv_bias had the same body, bf16(y + b) after the rounded product: both come
from TF_VIS_BIAS, qwv_bias keeping its 256-thread reservation. Kernel names and signatures are unchanged.
@ashhart
ashhart merged commit cdf98d9 into ashhart:main Nov 25, 2026
0 of 10 checks passed
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. 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 to jschmied/TensorFold that referenced this pull request Nov 25, 2026
ashhart added a commit that referenced this pull request Nov 25, 2026
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 25, 2026
ashhart added a commit that referenced this pull request Nov 25, 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