Skip to content

Commit b272364

Browse files
committed
Fix
1 parent 761fe31 commit b272364

7 files changed

Lines changed: 762 additions & 383 deletions

File tree

src/transformers/models/videollama3/configuration_videollama3.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ class Videollama3Config(PretrainedConfig):
7878
The image token index to encode the image prompt.
7979
video_token_id (`int`, *optional*, defaults to -1):
8080
The video token index to encode the image prompt.
81-
use_token_compression (`bool`, *optional*, defaults to `False`):
82-
Whether to use temporal token compression to reduce the number of video tokens.
8381
"""
8482

8583
model_type = "videollama3"
@@ -92,22 +90,30 @@ def __init__(
9290
vision_config=None,
9391
image_token_id=151655,
9492
video_token_id=151656,
95-
use_token_compression=False,
9693
**kwargs,
9794
):
9895
if isinstance(vision_config, dict):
9996
self.vision_config = self.sub_configs["vision_config"](**vision_config)
97+
elif isinstance(vision_config, PretrainedConfig):
98+
self.vision_config = vision_config
10099
elif vision_config is None:
101100
self.vision_config = self.sub_configs["vision_config"]()
101+
else:
102+
raise ValueError(
103+
f"vision_config must be of type `dict` or `PretrainedConfig`, but got {type(vision_config)}."
104+
)
102105

103106
if isinstance(text_config, dict):
104107
self.text_config = CONFIG_MAPPING[text_config["model_type"]](**text_config)
108+
elif isinstance(text_config, PretrainedConfig):
109+
self.text_config = text_config
105110
elif text_config is None:
106111
self.text_config = CONFIG_MAPPING["qwen2"]()
112+
else:
113+
raise ValueError(f"text_config must be of type `dict` or `PretrainedConfig`, but got {type(text_config)}.")
107114

108115
self.image_token_id = image_token_id
109116
self.video_token_id = video_token_id
110-
self.use_token_compression = use_token_compression
111117

112118
super().__init__(**kwargs)
113119

src/transformers/models/videollama3/image_processing_videollama3.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
validate_preprocess_arguments,
1919
)
2020
from transformers.utils import TensorType, logging
21-
from transformers.video_utils import VideoInput, make_batched_videos
21+
from transformers.video_utils import VideoInput
2222

2323
from ...image_processing_utils import BaseImageProcessor
2424
from ...image_transforms import convert_to_rgb, resize, to_channel_dimension_format
@@ -445,42 +445,11 @@ def preprocess(
445445
}
446446
)
447447

448-
# kept for BC only and should be removed after v5.0
449448
if videos is not None:
450-
logger.warning(
449+
raise ValueError(
451450
"`Videollama3ImageProcessor` works only with image inputs and doesn't process videos anymore. "
452-
"This is a deprecated behavior and will be removed in v5.0. "
453451
"Your videos should be forwarded to `Videollama3VideoProcessor`. "
454452
)
455-
videos = make_batched_videos(videos)
456-
pixel_values_videos, vision_grid_thws_videos = [], []
457-
for images in videos:
458-
patches, video_grid_thw = self._preprocess(
459-
images,
460-
do_resize=do_resize,
461-
size=size,
462-
resample=resample,
463-
do_rescale=do_rescale,
464-
rescale_factor=rescale_factor,
465-
do_normalize=do_normalize,
466-
image_mean=image_mean,
467-
image_std=image_std,
468-
patch_size=patch_size,
469-
temporal_patch_size=temporal_patch_size,
470-
merge_size=merge_size,
471-
data_format=data_format,
472-
do_convert_rgb=do_convert_rgb,
473-
input_data_format=input_data_format,
474-
)
475-
pixel_values_videos.extend(patches)
476-
vision_grid_thws_videos.append(video_grid_thw)
477-
data.update(
478-
{
479-
"pixel_values_videos": np.array(pixel_values_videos),
480-
"video_grid_thw": np.array(vision_grid_thws_videos),
481-
"video_merge_sizes": np.array([merge_size] * len(vision_grid_thws_videos)),
482-
}
483-
)
484453

485454
return BatchFeature(data=data, tensor_type=return_tensors)
486455

0 commit comments

Comments
 (0)