Module vision_preprocess_glm

Module vision_preprocess_glm 

Source
Expand description

2026-09-25: GLM image geometry: smart_resize to a canvas aligned to patch_size × spatial_merge_size, an aspect-preserving fit that never upscales, a black pad to the canvas, and the 2×2-block-major patch order. vision_preprocess uses it when VisionConfig::block_major_patches is set.

Owner: model-layers (vision input). Invariants: none beyond the types.

Functions§

block_major_patch_index
2026-09-25: Index of the patch at (patch_row, patch_col) in the 2×2-block-major stream the GLM tower expects.
pixel_bounds
2026-09-25: (min_pixels, max_pixels) for smart_resize, as pixel areas.
resize_and_pad
2026-09-25: Fit img inside the smart_resize canvas preserving aspect, then zero-pad right/bottom to the canvas exactly. Returns the padded canvas.
smart_resize
2026-09-25: Snap each side to the nearest multiple of factor, then rescale by the area bounds if the snapped canvas violates them.