Repository navigation
metal: the image towers' bf16 rounding, threadgroup sum and max, softmax and LayerNorm bodies from one source (#2251) - #2948
Conversation
|
Thanks @jschmied. We checked the claim independently: each image tower's library built from
|
…softmax body from one source (ashhart#2251)
7c7226e to
e79c5a6
Compare
|
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. |
Figures and scope corrected to the PRs (#2948, #2863, #2934, #2933, #2921, #2906, #2878, #2892, #2851, #2728, #3072, #2915, #2864, #2854 and others), promises of later work removed (#2903, #2875, #1630, #1720), #3074 and #3047/#3046 said as their PRs scope them, the duplicate #2861, #2585, #2321 and #2719 entries and two copies of released 1.2.5 lines removed, #1953's line named for its PR, and a line for #3255. Released sections unchanged.
|
Thanks @jschmied! This is in TensorFold 1.2.8, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.8
|
The next section-1 group of #2251: the glue the four image towers had each copied. It builds on the gemm_nax macro (#2787, merged):
vision_gluestarts from itsgemm_naxconst. Head 7c7226e, two commits on main a0e2665.What changes
glm_vision), Step-5's (step5/vision), Qwen-VL's (core/qwen_vision) and Gemma 4's (gemma4/vision) towers each defined:*_bf(round to bf16 and back);glmv_group_sum,s5v_group_sumwith an unusedtparameter;g4v_group_sum,qwv_sum);qwv_max).tf_vis_bf,tf_vis_sumandtf_vis_maxin the newprefill/vision_glue.metal.sources.zig'svision_glue(gemm_nax++ it) heads the four towers' sources.TF_VIS_SOFTMAX_BODY(SCALE):TF_VIS_SOFTMAX_BODY(* scale)for GLM and Step-5,TF_VIS_SOFTMAX_BODY()for Gemma 4. Each kernel keeps its own signature and attributes.tf_vis_maxandtf_vis_sum.bf16((x - mean) * rsqrt(var + eps) * w + b)).s5v_layer_norm(bf16 input),qwv_layer_norm(fp32 input) andg4u_norm(input throughg4u_in's add modes) had the same statistics and output loop.TF_VIS_LAYER_NORM_STATS(IN)andTF_VIS_LAYER_NORM_OUT(IN)invision_glue.metal, whereIN(i)reads one input value.glmv_layer_normrounds twice and stays its own.Same code before and after (M3 Pro, main a0e2665 against this branch)
Each source was assembled as
sources.zigembeds it, withnax.hinlined, and compiled withxcrun metal -std=metal4.1 -S -emit-llvm. That ran under-fmetal-math-mode=safe, with-fmetal-math-fp32-functions=fastand with=precise. Gemma 4's source was compiled with theG4V_OUTdefine its loader prepends.core_qwen_vision: the LLVM IR is byte-identical, source path aside.The LayerNorm commit on its own: all three towers' IR is byte-identical to the first commit's.
glm_vision,step5_visionandgemma4_vision:Not run here: these towers run on the tensor units; this Mac has none, so no GPU run. The evidence is the IR above.
Tests: native build;
test-kernel-symbols-host,test-step5-host,compile-step5-host,test-gemma4-contract-host,compile-gemma4-contract-host,compile-gemma4-host,test-qwen-vision-weights-host,test-glm-image-cache-host,test-gemma4-tower-host,test-contract-images-host,test-vision-cli-host,test-qwen35-images-hostpass. Lean 386 vs 386, 0 new;zig fmt --checkandgit diff --checkclean.x86 CI (Linux build + host tests on 7c7226e): green, 700/700 steps;
check-native-cuda-host compile-cuda-testsgreen; pr_check 0 errors; fmt, diff --check clean; lean 386 vs 386, 0 new.Rebased onto a0e2665 after #2787 merged:
git range-diffshows both patches unchanged, onlysources.zigcontext lines moved; all checks above were rerun on the rebased head.Not run: seeded, resume, concurrency and refusal reply checks against main, because the compiled IR is identical, so no served output can change.
Proposed CHANGELOG line (for you to place):