@@ -1081,6 +1081,7 @@ def forward(
10811081 use_cache : bool | None = None ,
10821082 image_position_ids : torch .LongTensor | None = None ,
10831083 video_position_ids : torch .LongTensor | None = None ,
1084+ num_frames_per_video : torch .LongTensor | None = None ,
10841085 mm_encoder_outputs : dict [str , BaseModelOutputWithPooling ] | None = None ,
10851086 ** kwargs : Unpack [TransformersKwargs ],
10861087 ) -> Gemma4UnifiedModelOutputWithPast :
@@ -1093,6 +1094,9 @@ def forward(
10931094 video_position_ids (`torch.LongTensor` of shape `(total_num_frames, max_patches, 2)`, *optional*):
10941095 2D patch position coordinates from the video processor, with `(-1, -1)` indicating padding.
10951096 Passed through to the vision encoder for positional embedding computation.
1097+ num_frames_per_video (`torch.LongTensor` of shape `(num_videos,)`, *optional*):
1098+ Number of frames belonging to each video. Required whenever `pixel_values_videos` is passed,
1099+ since the frames of all videos are concatenated along a single axis.
10961100 """
10971101 if (input_ids is None ) ^ (inputs_embeds is not None ):
10981102 raise ValueError ("You must specify exactly one of input_ids or inputs_embeds" )
@@ -1137,7 +1141,7 @@ def forward(
11371141
11381142 if mm_encoder_outputs .get ("video" ) is None and pixel_values_videos is not None :
11391143 mm_encoder_outputs ["video" ] = self .get_video_features (
1140- pixel_values_videos , video_position_ids , return_dict = True
1144+ pixel_values_videos , video_position_ids , num_frames_per_video = num_frames_per_video , return_dict = True
11411145 )
11421146
11431147 if mm_encoder_outputs .get ("video" ) is not None :
@@ -1279,6 +1283,7 @@ def forward(
12791283 use_cache = use_cache ,
12801284 image_position_ids = image_position_ids ,
12811285 video_position_ids = video_position_ids ,
1286+ num_frames_per_video = num_frames_per_video ,
12821287 mm_encoder_outputs = mm_encoder_outputs ,
12831288 return_dict = True ,
12841289 ** kwargs ,
0 commit comments