Skip to content

Commit 28c21de

Browse files
committed
Fix style
1 parent ae66b5d commit 28c21de

5 files changed

Lines changed: 182 additions & 23 deletions

File tree

src/transformers/models/videollama3/configuration_videollama3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class Videollama3Config(PretrainedConfig):
7474
The config object or dictionary of the text backbone.
7575
vision_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `Videollama3VisionConfig`):
7676
The config object or dictionary of the vision backbone.
77-
image_token_id (`int`, *optional*, defaults to -1):
77+
image_token_id (`int`, *optional*, defaults to 151655):
7878
The image token index to encode the image prompt.
79-
video_token_id (`int`, *optional*, defaults to -1):
79+
video_token_id (`int`, *optional*, defaults to 151656):
8080
The video token index to encode the image prompt.
8181
"""
8282

src/transformers/models/videollama3/image_processing_videollama3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ class Videollama3ImageProcessor(BaseImageProcessor):
8686
The max pixels of the image to resize the image.
8787
patch_size (`int`, *optional*, defaults to 14):
8888
The spatial patch size of the vision encoder.
89-
temporal_patch_size (`int`, *optional*, defaults to 2):
89+
temporal_patch_size (`int`, *optional*, defaults to 1):
9090
The temporal patch size of the vision encoder.
91-
merge_size (`int`, *optional*, defaults to 2):
91+
merge_size (`int`, *optional*, defaults to 1):
9292
The merge size of the vision encoder to llm encoder.
9393
"""
9494

src/transformers/models/videollama3/modeling_videollama3.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from transformers.models.auto.modeling_auto import AutoModel
1919
from transformers.processing_utils import Unpack
2020
from transformers.utils import auto_docstring, can_return_tuple
21+
from transformers.utils.generic import check_model_inputs
2122

2223
from ...activations import ACT2FN
2324
from ...generation import GenerationMixin
@@ -33,7 +34,7 @@
3334
"""
3435
)
3536
class Videollama3ModelOutputWithPast(ModelOutput):
36-
"""
37+
r"""
3738
past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
3839
Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
3940
`(batch_size, num_heads, sequence_length, embed_size_per_head)`)
@@ -63,7 +64,7 @@ class Videollama3ModelOutputWithPast(ModelOutput):
6364
"""
6465
)
6566
class Videollama3CausalLMOutputWithPast(ModelOutput):
66-
"""
67+
r"""
6768
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
6869
Language modeling loss (for next-token prediction).
6970
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
@@ -375,7 +376,7 @@ def forward(
375376
position_embeddings: tuple[torch.Tensor, torch.Tensor],
376377
**kwargs: Unpack[TransformersKwargs],
377378
) -> Union[tuple, BaseModelOutput]:
378-
"""
379+
r"""
379380
cu_seqlens (`torch.Tensor` of shape `(num_images_or_videos + 1,)`):
380381
The cumulative sequence lengths of each image or video feature.
381382
position_embeddings (`tuple(torch.Tensor, torch.Tensor)` of shape `(num_patches, head_dim // 2)`):
@@ -408,6 +409,7 @@ class Videollama3PreTrainedModel(PreTrainedModel):
408409

409410
class Videollama3VisionModel(Videollama3PreTrainedModel):
410411
config: Videollama3VisionConfig
412+
main_input_name = "pixel_values"
411413
_no_split_modules = ["Videollama3VisionEncoderLayer"]
412414
_can_record_outputs = {
413415
"hidden_states": Videollama3VisionEncoderLayer,
@@ -425,6 +427,9 @@ def __init__(self, config: Videollama3VisionConfig):
425427

426428
self.post_init()
427429

430+
def get_input_embeddings(self) -> Videollama3VisionEmbeddings:
431+
return self.embeddings.patch_embedding
432+
428433
def rot_pos_emb(self, grid_thw, merge_sizes):
429434
pos_ids = []
430435
for (t, h, w), merge_size in zip(grid_thw, merge_sizes):
@@ -479,7 +484,7 @@ def pixel_unshuffle(
479484

480485
return torch.cat(outputs, dim=0)
481486

482-
@can_return_tuple
487+
@check_model_inputs
483488
@auto_docstring
484489
def forward(
485490
self,
@@ -488,7 +493,7 @@ def forward(
488493
merge_sizes: torch.Tensor,
489494
**kwargs: Unpack[TransformersKwargs],
490495
) -> Union[tuple, BaseModelOutput]:
491-
"""
496+
r"""
492497
grid_thw (`torch.LongTensor` of shape `(num_images_or_videos, 3)`):
493498
The temporal, height and width dimensions of feature shape for each image. Each row contains [t, h, w] values.
494499
merge_sizes (`torch.Tensor` of shape `(num_images_or_videos,)`):
@@ -690,9 +695,9 @@ def forward(
690695
cache_position: Optional[torch.LongTensor] = None,
691696
**kwargs: Unpack[TransformersKwargs],
692697
) -> Union[tuple, Videollama3ModelOutputWithPast]:
693-
"""
698+
r"""
694699
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
695-
The temporal, height and width of feature shape of each image in LLM.
700+
The temporal, height and width of feature shape of each image in LLM.
696701
image_merge_sizes (`torch.Tensor` of shape `(num_images,)`):
697702
The spatial downsampling ratio of each image feature.
698703
video_grid_thw (`torch.Tensor` of shape `(num_videos, 3)`):
@@ -824,7 +829,7 @@ def forward(
824829
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
825830
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
826831
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
827-
The temporal, height and width of feature shape of each image in LLM.
832+
The temporal, height and width of feature shape of each image in LLM.
828833
image_merge_sizes (`torch.Tensor` of shape `(num_images,)`):
829834
The spatial downsampling ratio of each image feature.
830835
video_grid_thw (`torch.Tensor` of shape `(num_videos, 3)`):
@@ -1133,4 +1138,9 @@ def vision_model(self):
11331138
return self.model.vision_model
11341139

11351140

1136-
__all__ = ["Videollama3VisionModel", "Videollama3Model", "Videollama3ForConditionalGeneration"]
1141+
__all__ = [
1142+
"Videollama3VisionModel",
1143+
"Videollama3PreTrainedModel",
1144+
"Videollama3Model",
1145+
"Videollama3ForConditionalGeneration",
1146+
]

src/transformers/models/videollama3/modular_videollama3.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
can_return_tuple,
6464
logging,
6565
)
66+
from transformers.utils.generic import check_model_inputs
6667
from transformers.video_utils import (
6768
VideoInput,
6869
group_videos_by_shape,
@@ -172,9 +173,9 @@ class Videollama3Config(PretrainedConfig):
172173
The config object or dictionary of the text backbone.
173174
vision_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `Videollama3VisionConfig`):
174175
The config object or dictionary of the vision backbone.
175-
image_token_id (`int`, *optional*, defaults to -1):
176+
image_token_id (`int`, *optional*, defaults to 151655):
176177
The image token index to encode the image prompt.
177-
video_token_id (`int`, *optional*, defaults to -1):
178+
video_token_id (`int`, *optional*, defaults to 151656):
178179
The video token index to encode the image prompt.
179180
"""
180181

@@ -223,7 +224,7 @@ def __init__(
223224
"""
224225
)
225226
class Videollama3ModelOutputWithPast(ModelOutput):
226-
"""
227+
r"""
227228
past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
228229
Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
229230
`(batch_size, num_heads, sequence_length, embed_size_per_head)`)
@@ -253,7 +254,7 @@ class Videollama3ModelOutputWithPast(ModelOutput):
253254
"""
254255
)
255256
class Videollama3CausalLMOutputWithPast(ModelOutput):
256-
"""
257+
r"""
257258
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
258259
Language modeling loss (for next-token prediction).
259260
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
@@ -456,7 +457,7 @@ def forward(
456457
position_embeddings: tuple[torch.Tensor, torch.Tensor],
457458
**kwargs: Unpack[TransformersKwargs],
458459
) -> Union[tuple, BaseModelOutput]:
459-
"""
460+
r"""
460461
cu_seqlens (`torch.Tensor` of shape `(num_images_or_videos + 1,)`):
461462
The cumulative sequence lengths of each image or video feature.
462463
position_embeddings (`tuple(torch.Tensor, torch.Tensor)` of shape `(num_patches, head_dim // 2)`):
@@ -480,6 +481,7 @@ class Videollama3PreTrainedModel(Qwen2VLPreTrainedModel):
480481

481482
class Videollama3VisionModel(Videollama3PreTrainedModel):
482483
config: Videollama3VisionConfig
484+
main_input_name = "pixel_values"
483485
_no_split_modules = ["Videollama3VisionEncoderLayer"]
484486
_can_record_outputs = {
485487
"hidden_states": Videollama3VisionEncoderLayer,
@@ -497,6 +499,9 @@ def __init__(self, config: Videollama3VisionConfig):
497499

498500
self.post_init()
499501

502+
def get_input_embeddings(self) -> Videollama3VisionEmbeddings:
503+
return self.embeddings.patch_embedding
504+
500505
def rot_pos_emb(self, grid_thw, merge_sizes):
501506
pos_ids = []
502507
for (t, h, w), merge_size in zip(grid_thw, merge_sizes):
@@ -551,7 +556,7 @@ def pixel_unshuffle(
551556

552557
return torch.cat(outputs, dim=0)
553558

554-
@can_return_tuple
559+
@check_model_inputs
555560
@auto_docstring
556561
def forward(
557562
self,
@@ -560,7 +565,7 @@ def forward(
560565
merge_sizes: torch.Tensor,
561566
**kwargs: Unpack[TransformersKwargs],
562567
) -> Union[tuple, BaseModelOutput]:
563-
"""
568+
r"""
564569
grid_thw (`torch.LongTensor` of shape `(num_images_or_videos, 3)`):
565570
The temporal, height and width dimensions of feature shape for each image. Each row contains [t, h, w] values.
566571
merge_sizes (`torch.Tensor` of shape `(num_images_or_videos,)`):
@@ -708,9 +713,9 @@ def forward(
708713
cache_position: Optional[torch.LongTensor] = None,
709714
**kwargs: Unpack[TransformersKwargs],
710715
) -> Union[tuple, Videollama3ModelOutputWithPast]:
711-
"""
716+
r"""
712717
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
713-
The temporal, height and width of feature shape of each image in LLM.
718+
The temporal, height and width of feature shape of each image in LLM.
714719
image_merge_sizes (`torch.Tensor` of shape `(num_images,)`):
715720
The spatial downsampling ratio of each image feature.
716721
video_grid_thw (`torch.Tensor` of shape `(num_videos, 3)`):
@@ -823,7 +828,7 @@ def forward(
823828
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
824829
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
825830
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
826-
The temporal, height and width of feature shape of each image in LLM.
831+
The temporal, height and width of feature shape of each image in LLM.
827832
image_merge_sizes (`torch.Tensor` of shape `(num_images,)`):
828833
The spatial downsampling ratio of each image feature.
829834
video_grid_thw (`torch.Tensor` of shape `(num_videos, 3)`):
@@ -1493,6 +1498,7 @@ def _preprocess(
14931498
"Videollama3VisionConfig",
14941499
"Videollama3Config",
14951500
"Videollama3VisionModel",
1501+
"Videollama3PreTrainedModel",
14961502
"Videollama3Model",
14971503
"Videollama3ForConditionalGeneration",
14981504
"Videollama3Processor",

0 commit comments

Comments
 (0)