Repository navigation
core/picture: normalize, the processors' u8-to-float arithmetic as one table a channel (stacked on #1584) - #1592
Merged
Merged
Conversation
3 of 8 tasks
…e table a channel Six places turned a pixel's u8 into the tower's float on their own: core/picture/patches, Qwen-VL's video, LFM2's tiles, GLM5-Next's images and video, and Step-5. They compute four different expressions, now named modes of core/picture/normalize.zig: - unfused: transformers' PIL processors, x * rescale in f64 to f32, then (x - mean) / std; - fused: torchvision's, (x - f32(mean / rescale)) / f32(std / rescale); - fused_f32: GLM5-Next's video, mean and std times f32(1 / rescale) in f32; - rescale_f32: GLM5-Next's images, x * f32(rescale) in f32. Step-5's ToTensor, x / 255 in f32, is unfused's value for every u8, so it takes unfused. GLM's fused_f32 gives fused's bits for CLIP's and 0.5's mean and std; it stays its own mode because the checkpoint's mean and std are read at run time. normalize_test.zig checks each mode against the expression its family computed in place, all 256 values of every channel, bit for bit, with the families' means and stds, and that unfused, fused and rescale_f32 differ. Every patch value is unchanged; the loops now index the table. (cherry picked from commit 9d8f165de09129a53946d5263c92f523a02cdf4f)
(cherry picked from commit 5001d17e5fac53806913a0d936c1d8fb95641668)
ashhart
force-pushed
the
picture-normalize
branch
from
October 29, 2026 23:43
b835271 to
5f3696a
Compare
Owner
|
Thank you @jschmied. This is in TensorFold 1.2.0, released today: https://github.com/ashhart/TensorFold/releases/tag/v1.2.0 It landed with your commits under your own name, so you're listed as a TensorFold contributor, and it's credited to you in the release notes and the changelog. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1584: only the top commit is new here.
What
Six places turned a pixel's u8 into the tower's float on their own:
core/picture/patches.zig;Between them they computed four different expressions.
core/picture/normalize.zignames them as modes and builds a 256-entry table per channel, which each patch loop now indexes:unfusedx * rescalein f64 to f32, then(x - mean) / std(transformers' PIL processors)fused(x - f32(mean / rescale)) / f32(std / rescale)(torchvision, the fast processors)fused), Qwen-VL video, LFM2fused_f32f32(1 / rescale), in f32rescale_f32x * f32(rescale)in f32, then(x - mean) / stdTwo findings came out of the exhaustive tests:
x / 255in f32) givesunfused's value for every u8, independent of mean and std. So Step-5 takesunfusedand needs no mode of its own.fused_f32givesfused's bits for CLIP's and 0.5's mean and std. It stays separate because GLM reads its mean and std from the checkpoint at run time.Gemma 4's
[0, 1]isunfusedwith mean 0 and std 1. It follows once #1589 lands, since that PR rewrites the same file.Checks
normalize_test.zigchecks each mode against the expression its family computed in place before this change. It covers all 256 values of every channel, bit for bit, with the families' own means and stds, and also checks thatunfused,fusedandrescale_f32differ.zig build test: passes.