nemo_automodel.components.models.glm5_next.image_processing

View as Markdown

Image-only backport of the GLM-5.3 dynamic patch processor.

Module Contents

Classes

NameDescription
Glm5NextImageProcessorDynamically resize, normalize and flatten GLM-5.3 image patches.
Glm5NextImageProcessorKwargsAdditional dynamic resize and patchification options.

Functions

NameDescription
smart_resizeReturn an aligned H/W canvas inside the configured token budget.

Data

__all__

API

class nemo_automodel.components.models.glm5_next.image_processing.Glm5NextImageProcessor()

Bases: TorchvisionBackend

Dynamically resize, normalize and flatten GLM-5.3 image patches.

max_image_tokens
= 8000
merge_size
= 2
min_image_tokens
= 16
model_input_names
= ['pixel_values', 'image_grid_thw']
patch_expand_factor
= 1
patch_size
= 14
resample
= PILImageResampling.BICUBIC
rescale_factor
= 1 / 255
size
= {'longest_edge': 1}
temporal_patch_size
= 2
nemo_automodel.components.models.glm5_next.image_processing.Glm5NextImageProcessor._preprocess(
images: list[torch.Tensor],
do_resize: bool,
size: transformers.image_utils.SizeDict,
resample,
do_rescale: bool,
rescale_factor: float,
do_normalize: bool,
image_mean,
image_std,
patch_size: int,
temporal_patch_size: int,
merge_size: int,
patch_expand_factor: int,
min_image_tokens: int,
max_image_tokens: int,
disable_grouping: bool | None,
return_tensors,
kwargs = {}
) -> transformers.image_processing_utils.BatchFeature

Implement TorchvisionBackend’s grouped preprocessing contract.

nemo_automodel.components.models.glm5_next.image_processing.Glm5NextImageProcessor.get_number_of_image_patches(
height: int,
width: int,
images_kwargs: dict | None = None
) -> int

Return the number of unmerged vision patches for one source image.

nemo_automodel.components.models.glm5_next.image_processing.Glm5NextImageProcessor.patchify(
images: torch.Tensor,
patch_size: int,
merge_size: int,
temporal_patch_size: int
) -> tuple[torch.Tensor, int, int]
staticmethod

Flatten block-major duplicated temporal patches.

nemo_automodel.components.models.glm5_next.image_processing.Glm5NextImageProcessor.resize(
images: torch.Tensor,
resample,
factor: int,
temporal_factor: int,
min_image_tokens: int,
max_image_tokens: int,
kwargs = {}
) -> torch.Tensor

Aspect-preserving resize followed by right/bottom zero padding.

class nemo_automodel.components.models.glm5_next.image_processing.Glm5NextImageProcessorKwargs()

Bases: ImagesKwargs

Additional dynamic resize and patchification options.

max_image_tokens
int
merge_size
int
min_image_tokens
int
patch_expand_factor
int
patch_size
int
temporal_patch_size
int
nemo_automodel.components.models.glm5_next.image_processing.smart_resize(
num_frames: int,
height: int,
width: int,
temporal_factor: int = 2,
factor: int = 28,
min_pixels: int = 16,
max_pixels: int = 8000
) -> tuple[int, int]

Return an aligned H/W canvas inside the configured token budget.

nemo_automodel.components.models.glm5_next.image_processing.__all__ = ['Glm5NextImageProcessor', 'smart_resize']