Module vision_preprocess_glm

Module vision_preprocess_glm 

Source
Expand description

GLM-5.3 (Glm5NextImageProcessor) image geometry: smart_resize to a patch × merge-aligned canvas, aspect-preserving fit, zero pad.

Split from vision_preprocess.rs for the file-size cap, and because the resize POLICY differs from the Qwen family’s in a way that is not a parameter: Qwen resizes straight onto the snapped canvas (accepting a sub-grid-unit aspect distortion), GLM fits the content inside it and pads the remainder. Two policies, two functions.

Functions§

block_major_patch_index
Index of the patch at (patch_row, patch_col) in the 2×2-block-major stream the GLM tower expects.
pixel_bounds
The area bounds this checkpoint permits, in pixels.
resize_and_pad
Fit img inside the smart_resize canvas preserving aspect, then zero-pad right/bottom to the canvas exactly. Returns the padded canvas.
smart_resize
Qwen2-VL-family smart_resize, which GLM inherits: snap each side to the nearest multiple of factor, then rescale by the area bound if the snapped canvas violates it.