Skip to content

core/picture: patches, the processor geometry out of qwen_vl (torchvision resize and fused normalization as options) - #1584

Merged
ashhart merged 2 commits into
ashhart:mainfrom
jschmied:core-picture-patches
Oct 29, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
jschmied:core-picture-patches

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

core/qwen_vl/geometry.zig is the processor geometry every Qwen-VL-style tower needs (smart_resize, pixel bounds, merge-order patches), but it lives under a Qwen name and takes Qwen's Config. LFM3-VL's processor uses the same geometry (patch 16, merge 2, temporal 2), so this moves it to core/picture/patches.zig before the LFM3-VL CUDA tower (#1491, CUDA side) uses it.

What

  • core/picture/patches.zig: Patches (patch geometry, pixel bounds, rescale, mean, std), plus smartResize, bounds, prepare, prepareRgb and patchify, moved unchanged. The smart_resize test moves with them.
  • core/qwen_vl/geometry.zig keeps its API as a thin wrapper over the new Config.patches(). Every caller (Flash-Next, qwen27, qwen3_5, vision/qwen_cuda.zig) is untouched, and its remaining tests pass through the wrapper.
  • Two options for processors on transformers' torchvision backend, both off by default:
    • resize = .torch: its antialiased uint8 bicubic, already in picture/resample.zig;
    • fused = true: normalizes as (x - mean / rescale) / (std / rescale) in float32, the way TorchvisionBackend.rescale_and_normalize fuses it. The default rescales first and differs by up to 1 ulp.

Verification

  • patches_test.zig runs both options against transformers 5.19.0's Lfm3VlImageProcessor (torchvision 0.29.0) on five synthetic pictures, one upscaled, one wide, a downscaled 2000 x 3000 and two near-square. It compares the sha256 of pixel_values and the grid, and all five are bit-equal.
  • Controls: with Pillow's resize, or with the unfused normalization, the same picture misses the processor's bits.
  • zig build test: RC 0, no errors. Lean shows nothing new.

Not checked here: whether a Qwen-VL processor on current transformers also takes the torchvision path. If it does, the Qwen-VL ports would want these options too. I'll open that as a separate question.

jschmied and others added 2 commits October 29, 2026 23:42
…ut of qwen_vl

smart_resize, the pixel bounds and the merge-order patchify move to
core/picture/patches.zig over a Patches value (patch geometry, bounds,
rescale, mean and std). core/qwen_vl/geometry.zig keeps its API as a thin
wrapper over Config.patches(), so every caller and Qwen-VL's bits stay as
they were.

Two options for processors on transformers' torchvision backend, both off
by default: resize = .torch (its antialiased uint8 bicubic, already in
picture/resample) and fused = true, which normalizes as
(x - mean / rescale) / (std / rescale) in float32. patches_test.zig checks
them against transformers 5.19's Lfm3VlImageProcessor on five synthetic
pictures (sha256 of pixel_values), and shows that Pillow's resize or the
unfused normalization each miss those bits.
@ashhart
ashhart force-pushed the core-picture-patches branch from 1325da3 to 1c298e4 Compare October 29, 2026 23:42
@ashhart
ashhart merged commit 7cc8bd3 into ashhart:main Oct 29, 2026
9 checks passed
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
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.

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