From 8b4603a6d6123f5031765037ecd77d0764e180e4 Mon Sep 17 00:00:00 2001 From: ZMXJJ Date: Wed, 1 Jul 2026 03:34:46 +0000 Subject: [PATCH] fix(mm_plugin): regularize images before processor in MiniCPMV4_6Plugin MiniCPMV4_6Plugin._get_mm_inputs passed raw image inputs (paths/bytes) straight to the image_processor, unlike every other plugin (e.g. MiniCPMVPlugin) which first calls _regularize_images to load them into PIL objects and apply image_max_pixels/image_min_pixels resizing. Two consequences: - image_max_pixels / image_min_pixels were silently ignored for v4.6. - With transformers >= 5.7 the (torchvision-backed) image_processor decodes path inputs via torchvision, which fails on builds without libjpeg (e.g. the ROCm torchvision wheels) with: "decode_jpeg: torchvision not compiled with libjpeg support". Pre-loading to PIL makes the processor pass images through unchanged, restoring the resize behavior and avoiding the torchvision decode path. The video branch is left untouched (videos use PyAV, not torchvision). Co-Authored-By: Claude Opus 4.8 --- src/llamafactory/data/mm_plugin.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/llamafactory/data/mm_plugin.py b/src/llamafactory/data/mm_plugin.py index 5cf0cca8a4..4a85263ee2 100644 --- a/src/llamafactory/data/mm_plugin.py +++ b/src/llamafactory/data/mm_plugin.py @@ -1458,6 +1458,14 @@ def _get_mm_inputs( mm_inputs = {} if len(images) != 0: + # Pre-load images into PIL objects so the (torchvision-backed) image_processor passes + # them through unchanged, instead of decoding paths via torchvision (which is built + # without libjpeg on ROCm). See _regularize_images. + images = self._regularize_images( + images, + image_max_pixels=getattr(processor, "image_max_pixels", 1024 * 1024), + image_min_pixels=getattr(processor, "image_min_pixels", 32 * 32), + )["images"] # The image_processor ignores downsample_mode; target_sizes are always based on patch_size. # downsample_mode only affects the token divisor in _build_v4_6_placeholder and model forward. mm_inputs.update(image_processor(images, return_tensors="pt"))