6363 can_return_tuple ,
6464 logging ,
6565)
66+ from transformers .utils .generic import check_model_inputs
6667from 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)
225226class 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)
255256class 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
481482class 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