[Bugfix] Fix models and tests for transformers v5 (#33977)

Signed-off-by: raushan <raushan@huggingface.co>
Signed-off-by: Raushan Turganbay <raushan.turganbay@alumni.nu.edu.kz>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Raushan Turganbay
2026-02-06 21:47:41 +08:00
committed by GitHub
co-authored by Cyrus Leung Harry Mellor
parent 51a7bda625
commit 85ee1d962b
12 changed files with 70 additions and 55 deletions
+11 -6
View File
@@ -43,9 +43,7 @@ class OvisProcessorKwargs(ProcessingKwargs, total=False): # type: ignore[call-a
"padding": False,
},
"images_kwargs": {
"max_partition": 9,
"covering_threshold": 0.9,
"convert_to_rgb": True,
"do_convert_rgb": True,
"return_tensors": "pt",
},
}
@@ -143,6 +141,10 @@ class OvisProcessor(ProcessorMixin):
- **video_grid_thw** -- List of video 3D grid in LLM. Returned when `videos` is not `None`.
- **second_per_grid_ts** -- List of video seconds per time grid. Returned when `videos` is not `None`.
"""
max_partition = kwargs.pop("max_partition", 9)
covering_threshold = kwargs.pop("covering_threshold", 0.9)
output_kwargs = self._merge_kwargs(
OvisProcessorKwargs,
tokenizer_init_kwargs=self.tokenizer.init_kwargs,
@@ -159,7 +161,10 @@ class OvisProcessor(ProcessorMixin):
# Process each image
for image in images if isinstance(images, list) else [images]:
pixel_values, image_placeholders, grid = self.preprocess_image(
image=image, **output_kwargs["images_kwargs"]
image=image,
max_partition=max_partition,
covering_threshold=covering_threshold,
**output_kwargs["images_kwargs"],
)
processed_images.append(pixel_values)
image_placeholders_list.append(image_placeholders)
@@ -300,7 +305,7 @@ class OvisProcessor(ProcessorMixin):
image: PIL.Image.Image,
max_partition,
covering_threshold,
convert_to_rgb,
do_convert_rgb,
return_tensors,
):
def _preprocess(img: PIL.Image.Image, side):
@@ -394,7 +399,7 @@ class OvisProcessor(ProcessorMixin):
# pick the partition with maximum covering_ratio and break the tie using #sub_images
return sorted(all_grids, key=lambda x: (-x[1], x[0][0] * x[0][1]))[0][0]
if convert_to_rgb:
if do_convert_rgb:
image = convert_image_mode(image, "RGB")
sides = self.get_image_size()