Skip to content

Commit 0fa02c9

Browse files
committed
Fix
1 parent b272364 commit 0fa02c9

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/transformers/models/videollama3/image_processing_videollama3.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,6 @@ def preprocess(
445445
}
446446
)
447447

448-
if videos is not None:
449-
raise ValueError(
450-
"`Videollama3ImageProcessor` works only with image inputs and doesn't process videos anymore. "
451-
"Your videos should be forwarded to `Videollama3VideoProcessor`. "
452-
)
453-
454448
return BatchFeature(data=data, tensor_type=return_tensors)
455449

456450
def get_number_of_image_patches(self, height: int, width: int, images_kwargs=None):

src/transformers/models/videollama3/modeling_videollama3.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ class Videollama3PreTrainedModel(PreTrainedModel):
409409
class Videollama3VisionModel(Videollama3PreTrainedModel):
410410
config: Videollama3VisionConfig
411411
_no_split_modules = ["Videollama3VisionEncoderLayer"]
412-
# _can_compile_fullgraph = False
413412
_can_record_outputs = {
414413
"hidden_states": Videollama3VisionEncoderLayer,
415414
"attentions": Videollama3VisionAttention,
@@ -514,7 +513,6 @@ def forward(
514513
hidden_states,
515514
cu_seqlens=cu_seqlens,
516515
position_embeddings=position_embeddings,
517-
return_dict=True,
518516
**kwargs,
519517
)
520518

@@ -1083,8 +1081,12 @@ def _repeat_interleave_samples(x, lengths, repeat_times):
10831081
dict_to_expand[key], lengths=lengths, repeat_times=expand_size
10841082
)
10851083
elif key == "video_compression_mask":
1086-
samples = torch.split(video_compression_mask, list(video_nums))
1087-
lengths = [mask.sum() for mask in samples]
1084+
samples = torch.split(video_grid_thw, list(video_nums))
1085+
merge_sizes = torch.split(video_merge_sizes, list(video_nums))
1086+
lengths = [
1087+
(torch.prod(sample, dim=1) // merge_size**2).sum()
1088+
for sample, merge_size in zip(samples, merge_sizes)
1089+
]
10881090
dict_to_expand[key] = _repeat_interleave_samples(
10891091
dict_to_expand[key], lengths=lengths, repeat_times=expand_size
10901092
)

src/transformers/models/videollama3/modular_videollama3.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ class Videollama3PreTrainedModel(Qwen2VLPreTrainedModel):
481481
class Videollama3VisionModel(Videollama3PreTrainedModel):
482482
config: Videollama3VisionConfig
483483
_no_split_modules = ["Videollama3VisionEncoderLayer"]
484-
# _can_compile_fullgraph = False
485484
_can_record_outputs = {
486485
"hidden_states": Videollama3VisionEncoderLayer,
487486
"attentions": Videollama3VisionAttention,
@@ -586,7 +585,6 @@ def forward(
586585
hidden_states,
587586
cu_seqlens=cu_seqlens,
588587
position_embeddings=position_embeddings,
589-
return_dict=True,
590588
**kwargs,
591589
)
592590

@@ -1082,8 +1080,12 @@ def _repeat_interleave_samples(x, lengths, repeat_times):
10821080
dict_to_expand[key], lengths=lengths, repeat_times=expand_size
10831081
)
10841082
elif key == "video_compression_mask":
1085-
samples = torch.split(video_compression_mask, list(video_nums))
1086-
lengths = [mask.sum() for mask in samples]
1083+
samples = torch.split(video_grid_thw, list(video_nums))
1084+
merge_sizes = torch.split(video_merge_sizes, list(video_nums))
1085+
lengths = [
1086+
(torch.prod(sample, dim=1) // merge_size**2).sum()
1087+
for sample, merge_size in zip(samples, merge_sizes)
1088+
]
10871089
dict_to_expand[key] = _repeat_interleave_samples(
10881090
dict_to_expand[key], lengths=lengths, repeat_times=expand_size
10891091
)

0 commit comments

Comments
 (0)