Repository: huggingface/transformers
Pull request: Update image_processing_perception_lm_fast.py to allow for proper override of vision_input_type

Allow for a proper override of vision_input_type in hf fast image processor, otherwise we need to resort to manually setting the attribute.

# What does this PR do?

Allow for a proper override of vision_input_type in hf fast image processor, otherwise we need to resort to manually setting the attribute.

Fixes #40251 


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?




Changed files:
filename: src/transformers/models/perception_lm/image_processing_perception_lm_fast.py
patch: @@ -272,6 +272,7 @@ def _preprocess(
         do_normalize: Optional[bool],
         image_mean: Optional[Union[float, list[float]]],
         image_std: Optional[Union[float, list[float]]],
+        vision_input_type: str,
         tile_size: int,
         max_num_tiles: int,
         return_tensors: Optional[Union[str, TensorType]],
@@ -283,7 +284,7 @@ def _preprocess(
         resized_images_grouped = {}
         for shape, stacked_images in grouped_images.items():
             if do_resize:
-                if self.vision_input_type == "thumb+tile":
+                if vision_input_type == "thumb+tile":
                     thumbnails, _ = self.resize(stacked_images, tile_size, max_num_tiles=1)
                     images_for_tiling, (tiles_w, tiles_h) = self.resize(
                         stacked_images, tile_size, max_num_tiles=max_num_tiles

filename: src/transformers/models/perception_lm/processing_perception_lm.py
patch: @@ -213,11 +213,12 @@ def _get_num_multimodal_tokens(self, image_sizes=None, **kwargs):
             images_kwargs = PerceptionLMProcessorKwargs._defaults.get("images_kwargs", {})
             images_kwargs.update(kwargs)
             tile_size = images_kwargs.get("tile_size", None) or self.image_processor.tile_size
+            vision_input_type = images_kwargs.get("vision_input_type", None) or self.image_processor.vision_input_type
 
             num_image_tokens = []
             num_image_patches = []
             for height, width in image_sizes:
-                if self.image_processor.vision_input_type == "thumb+tile":
+                if vision_input_type == "thumb+tile":
                     aspect_ratio = self.image_processor._fit_image_to_canvas(
                         img_width=width, img_height=height, tile_size=tile_size
                     )