+
    œ°³j=  ã                   óø  € R t ^ RIHt ^ RIt^ RIHt ^RIHt ^RIH	t	 ^RI
HtHtHt ^RIHt ^RIHtHtHt ^R	IHtHt ^R
IHt ^RIHtHtHtHtHtHtH t H!t! ^RI"H#t# ]PH                  ! ]%4      t& ! R R]PN                  4      t( ! R R]4      t) ! R R]4      t* ! R R]4      t+ ! R R]4      t, ! R R] 4      t-] ! R R]!4      4       t.] ! R R]4      4       t/]! RR7       ! R R ].4      4       t0. R!Ot1R# )"zHPyTorch ViViT model - modular file inheriting transformer core from ViT.)ÚIterableN)Únn)Úinitialization)Úcreate_bidirectional_mask)ÚBaseModelOutputÚBaseModelOutputWithPoolingÚImageClassifierOutput)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚlogging)Úcan_return_tupleÚmerge_with_config_defaults)Úcapture_outputs)ÚPreTrainedModelÚViTAttentionÚViTEmbeddingsÚViTLayerÚViTMLPÚViTModelÚ	ViTPoolerÚViTPreTrainedModel©ÚVivitConfigc                   óT   a a€ ] tR t^,t oRtV3R lV 3R lltV3R lR ltRtVtV ;t	# )ÚVivitTubeletEmbeddingsae  
This class turns `pixel_values` of shape `(batch_size, num_frames, num_channels, height, width)` into the initial
`hidden_states` (tubelet embeddings) of shape `(batch_size, seq_length, hidden_size)` to be consumed by a
Transformer encoder.

The seq_length equals (num_frames // tubelet_size[0]) * (height // tubelet_size[1]) * (width // tubelet_size[2]).
c                ó    <€ V ^8„  d   QhRS[ /# ©é   Úconfigr   )ÚformatÚ__classdict__s   "€Úh/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/vivit/modular_vivit.pyÚ__annotate__Ú#VivitTubeletEmbeddings.__annotate__5   s   ø€ ÷ 
ñ 
™{ñ 
ó    c                ó¨  <€ \         SV `  4        VP                  pVP                  p\	        V\
        4      '       d   TMW33pVP                  V^ ,          ,          V^ ,          V^,          ,          ,          V^,          V^,          ,          ,          V n        W0n        \        P                  ! VP                  VP                  W"R7      V n        R# )é    )Úkernel_sizeÚstrideN)ÚsuperÚ__init__Útubelet_sizeÚ
image_sizeÚ
isinstancer   Ú
num_framesÚnum_patchesr   ÚConv3dÚnum_channelsÚhidden_sizeÚ
projection)Úselfr   r,   r-   Ú	__class__s   &&  €r"   r+   ÚVivitTubeletEmbeddings.__init__5   sª   ø€ Ü‰ÑÔØ×*Ñ*ˆØ×&Ñ&ˆ
Ü#-¨j¼(×#CÒ#C‘ZÈ*ÐIaˆ
ð ×Ñ ,¨q¥/Õ1Ø˜!�} ¨Q¥Õ/õ1à˜!�} ¨Q¥Õ/õ1ð 	Ôð
 %ŒÜŸ)š)Ø×Ñ ×!3Ñ!3Àô
ˆŽr%   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   Úpixel_valuesÚreturn)ÚtorchÚTensor)r    r!   s   "€r"   r#   r$   E   s'   ø€ ÷ Hñ H¡E§L¡Lð H±U·\±\ñ Hr%   c                ó†   € VP                  ^^4      pV P                  V4      P                  ^4      P                  ^^4      # )é   )Ú	transposer4   Úflatten)r5   r9   s   &&r"   ÚforwardÚVivitTubeletEmbeddings.forwardE   s;   € à#×-Ñ-¨a°Ó3ˆØ�‰˜|Ó,×4Ñ4°QÓ7×AÑAÀ!ÀQÓGÐGr%   )r-   r0   r4   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r+   rA   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r6   r!   s   @@r"   r   r   ,   s&   ù‡ € ñ÷
ó 
÷ H÷ Hð Hr%   r   c                   óp   a a€ ] tR t^Kt oRtV3R lV 3R lltV3R lV 3R lltR	V3R lR lltRtVt	V ;t
# )
ÚVivitEmbeddingszQ
Construct the CLS token, position and tubelet patch embeddings for video input.
c                ó    <€ V ^8„  d   QhRS[ /# r   r   )r    r!   s   "€r"   r#   ÚVivitEmbeddings.__annotate__P   s   ø€ ÷ 	ñ 	™{ñ 	r%   c                óž  <€ \         SV `  4        \        P                  ! \        P
                  ! ^^VP                  4      4      V n        \        V4      V n	        V P                  P                  p\        P                  ! \        P
                  ! ^V^,           VP                  4      4      V n        VP                  R,          V n        V =R# )r>   :r>   NNN)r*   r+   r   Ú	Parameterr;   Úzerosr3   Ú	cls_tokenr   Úpatch_embeddingsr0   Úposition_embeddingsr,   Ú
patch_sizeÚ
mask_token)r5   r   r0   r6   s   && €r"   r+   ÚVivitEmbeddings.__init__P   s�   ø€ Ü‰ÑÔäŸš¤e§k¢k°!°Q¸×8JÑ8JÓ&KÓLˆŒÜ 6°vÓ >ˆÔØ×+Ñ+×7Ñ7ˆÜ#%§<¢<´·²¸A¸{ÈQ½ÐPV×PbÑPbÓ0cÓ#dˆÔ à ×-Ñ-¨bÕ1ˆŒØŠOr%   c                óZ   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[ P                  /# )r   Ú
embeddingsÚheightÚwidthr:   )r;   r<   Úint)r    r!   s   "€r"   r#   rO   [   s5   ø€ ÷ 0ñ 0±5·<±<ð 0Éð 0ÑUXð 0Ñ]b×]iÑ]iñ 0r%   c                óŒ   <€ \         SV `  WV4       W P                  ^ ,          ,          pW0P                  ^,          ,          pR# )r'   N)r*   Úinterpolate_pos_encodingrV   )r5   rZ   r[   r\   Ú
new_heightÚ	new_widthr6   s   &&&&  €r"   r_   Ú(VivitEmbeddings.interpolate_pos_encoding[   s4   ø€ Ü‰Ñ(¨¸UÔCàŸ™¨qÕ1Õ1ˆ
ØŸ_™_¨QÕ/Õ/Š	r%   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# )r   r9   r_   r:   )r;   r<   Úbool)r    r!   s   "€r"   r#   rO   a   s-   ø€ ÷ ñ ¡E§L¡Lð ÉDð Ñ]b×]iÑ]iñ r%   c                ó  € VP                   w  r4rVpV P                  V4      pV P                  P                  VRR4      p	\        P
                  ! W˜3^R7      pV'       d   W€P                  W†V4      ,           pMzW`P                  ^ ,          8w  g   WpP                  ^,          8w  d;   \        RV RV RV P                  ^ ,           RV P                  ^,           R2	4      hW€P                  ,           pV P                  V4      pV# )r>   )ÚdimzInput image size (Ú*z) doesn't match model (z).éÿÿÿÿ)ÚshaperT   rS   Úexpandr;   Úcatr_   r-   Ú
ValueErrorrU   Údropout)
r5   r9   r_   Ú
batch_sizer/   r2   r[   r\   rZ   Ú
cls_tokenss
   &&&       r"   rA   ÚVivitEmbeddings.forwarda   sñ   € Ø>J×>PÑ>PÑ;ˆ
 °eØ×*Ñ*¨<Ó8ˆ
ð —^‘^×*Ñ*¨:°r¸2Ó>ˆ
Ü—Y’Y 
Ð7¸QÔ?ˆ
ç#Ø#×&CÑ&CÀJÐX]Ó&^Õ^‰JàŸ™¨Õ+Ô+¨u¿¹ÈÕ8JÔ/JÜ Ø(¨¨°°%°ð 9ØŸ™¨Õ+Ð,¨A¨d¯o©o¸aÕ.@Ð-AÀðEóð ð $×&>Ñ&>Õ>ˆJà—\‘\ *Ó-ˆ
àÐr%   )rS   rT   rV   rU   )F)rC   rD   rE   rF   rG   r+   r_   rA   rH   rI   rJ   rK   s   @@r"   rM   rM   K   s-   ù‡ € ñ÷	ó 	÷0ó 0÷÷ ò r%   rM   c                   ó   € ] tR t^xtRtR# )ÚVivitAttention© N©rC   rD   rE   rF   rH   rs   r%   r"   rr   rr   x   ó   † Ûr%   rr   c                   ó   € ] tR t^|tRtR# )ÚVivitMLPrs   Nrt   rs   r%   r"   rw   rw   |   ru   r%   rw   c                   ó   € ] tR t^€tRtR# )Ú
VivitLayerrs   Nrt   rs   r%   r"   ry   ry   €   ru   r%   ry   c                   ó   € ] tR t^„tRtR# )ÚVivitPoolerrs   Nrt   rs   r%   r"   r{   r{   „   ru   r%   r{   c                   ój   a € ] tR t^ˆt o RtRtRR.t]P                  ! 4       R 4       t	V 3R lt
RtV tR# )	ÚVivitPreTrainedModelÚvivitrM   ry   c                óâ   € \         P                  ! W4       \        V\        4      '       dC   \        P
                  ! VP                  4       \        P
                  ! VP                  4       R# R# )zInitialize the weightsN)r   Ú_init_weightsr.   rM   ÚinitÚzeros_rS   rU   )r5   Úmodules   &&r"   r€   Ú"VivitPreTrainedModel._init_weights�   sH   € ô 	×%Ò% dÔ3Ü�fœo×.Ò.Ü�KŠK˜×(Ñ(Ô)Ü�KŠK˜×2Ñ2Ö3ñ /r%   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # r   r   )r    r!   s   "€r"   r#   Ú!VivitPreTrainedModel.__annotate__ˆ   s   ø‡ ‚ áÑò r%   rs   N)Úvideo)rC   rD   rE   rF   Úbase_model_prefixÚinput_modalitiesÚ_no_split_modulesr;   Úno_gradr€   Ú__annotate_func__rH   rI   )r!   s   @r"   r}   r}   ˆ   s=   ø‡ € ð  ÐØ!ÐØ*¨LÐ9Ðà
‡]‚]ƒ_ñ4ó ð4÷ ƒ r%   r}   c                   ó„   a a€ ] tR t^˜t oRV3R lV 3R lllt]]! RR7      ]R	V3R lR ll4       4       4       tRt	Vt
V ;t# )
Ú
VivitModelc                ó&   <€ V ^8„  d   QhRS[ RS[/# )r   r   Úadd_pooling_layer)r   rd   )r    r!   s   "€r"   r#   ÚVivitModel.__annotate__š   s   ø€ ÷ 2ñ 2™{ð 2¹tñ 2r%   c                óF   <€ \         SV `  V4       \        V4      V n        R# )z^
add_pooling_layer (bool, *optional*, defaults to `True`):
    Whether to add a pooling layer
N)r*   r+   rM   rZ   )r5   r   r�   r6   s   &&&€r"   r+   ÚVivitModel.__init__š   s   ø€ ô
 	‰Ñ˜Ô Ü)¨&Ó1ˆŽr%   F)Útie_last_hidden_statesc          
      óŒ   <€ V ^8„  d   QhRS[ P                  R,          RS[RS[ P                  R,          RS[S[,          RS[/# )r   r9   Nr_   Úattention_maskÚkwargsr:   )r;   ÚFloatTensorrd   r<   r	   r
   r   )r    r!   s   "€r"   r#   r‘   ¥   se   ø€ ÷ ^jñ ^já×'Ñ'¨$Õ.ð^jñ #'ð^jñ Ÿ™ tÕ+ð	^jñ
 Ñ+Õ,ð^jñ 
$ñ^jr%   c                ó  € V P                  WR7      p\        V P                  VVR7      pTpV P                   F  pV! Wc3/ VB pK  	  V P	                  V4      pV P
                  e   V P                  V4      MRp	\        W‰R7      # )a(
  
Examples:

```python
>>> import av
>>> import numpy as np

>>> from transformers import VivitImageProcessor, VivitModel
>>> from huggingface_hub import hf_hub_download

>>> np.random.seed(0)


>>> def read_video_pyav(container, indices):
...     '''
...     Decode the video with PyAV decoder.
...     Args:
...         container (`av.container.input.InputContainer`): PyAV container.
...         indices (`list[int]`): List of frame indices to decode.
...     Returns:
...         result (np.ndarray): np array of decoded frames of shape (num_frames, height, width, 3).
...     '''
...     frames = []
...     container.seek(0)
...     start_index = indices[0]
...     end_index = indices[-1]
...     for i, frame in enumerate(container.decode(video=0)):
...         if i > end_index:
...             break
...         if i >= start_index and i in indices:
...             frames.append(frame)
...     return np.stack([x.to_ndarray(format="rgb24") for x in frames])


>>> def sample_frame_indices(clip_len, frame_sample_rate, seg_len):
...     '''
...     Sample a given number of frame indices from the video.
...     Args:
...         clip_len (`int`): Total number of frames to sample.
...         frame_sample_rate (`int`): Sample every n-th frame.
...         seg_len (`int`): Maximum allowed index of sample's last frame.
...     Returns:
...         indices (`list[int]`): List of sampled frame indices
...     '''
...     converted_len = int(clip_len * frame_sample_rate)
...     end_idx = np.random.randint(converted_len, seg_len)
...     start_idx = end_idx - converted_len
...     indices = np.linspace(start_idx, end_idx, num=clip_len)
...     indices = np.clip(indices, start_idx, end_idx - 1).astype(np.int64)
...     return indices


>>> # video clip consists of 300 frames (10 seconds at 30 FPS)
>>> file_path = hf_hub_download(
...     repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
... )
>>> container = av.open(file_path)

>>> # sample 32 frames
>>> indices = sample_frame_indices(clip_len=32, frame_sample_rate=1, seg_len=container.streams.video[0].frames)
>>> video = read_video_pyav(container=container, indices=indices)

>>> image_processor = VivitImageProcessor.from_pretrained("google/vivit-b-16x2-kinetics400")
>>> model = VivitModel.from_pretrained("google/vivit-b-16x2-kinetics400")

>>> # prepare video for the model
>>> inputs = image_processor(list(video), return_tensors="pt")

>>> # forward pass
>>> outputs = model(**inputs)
>>> last_hidden_states = outputs.last_hidden_state
>>> list(last_hidden_states.shape)
[1, 3137, 768]
```)r_   )r   Úinputs_embedsr–   N)Úlast_hidden_stateÚpooler_output)rZ   r   r   ÚlayersÚ	layernormÚpoolerr   )
r5   r9   r_   r–   r—   Úembedding_outputÚhidden_statesÚlayerÚsequence_outputÚpooled_outputs
   &&&&,     r"   rA   ÚVivitModel.forward¢   s„   € ðj  Ÿ?™?¨<˜?ÓkÐÜ2Ø—;‘;Ø*Ø)ô
ˆð
 )ˆØ—[”[ˆEÙ! -ÑJÀ6ÑJŠMñ !àŸ.™.¨Ó7ˆØ8<¿¹Ò8O˜Ÿ™ OÔ4ÐUYˆä)¸OÔiÐir%   )rZ   )T)NFN)rC   rD   rE   rF   r+   r   r   r   rA   rH   rI   rJ   rK   s   @@r"   rŽ   rŽ   ˜   sJ   ù‡ € ÷2õ 2ð  Ù¨EÔ2Ø÷^jñ ^jó ó 3ó  ÷^jð ^jr%   rŽ   aý  
        ViViT Transformer model with a video classification head on top (a linear layer on top of the final hidden state of the
    [CLS] token) e.g. for Kinetics-400.

        <Tip>

            Note that it's possible to fine-tune ViT on higher resolution images than the ones it has been trained on, by
            setting `interpolate_pos_encoding` to `True` in the forward of the model. This will interpolate the pre-trained
            position embeddings to the higher resolution.

        </Tip>
    )Úcustom_introc                   óh   a a€ ] tR tRt oV3R lV 3R llt]]RV3R lR ll4       4       tRtVt	V ;t
# )ÚVivitForVideoClassificationi  c                ó    <€ V ^8„  d   QhRS[ /# r   r   )r    r!   s   "€r"   r#   Ú(VivitForVideoClassification.__annotate__  s   ø€ ÷ 
ñ 
™{ñ 
r%   c                ó8  <€ \         SV `  V4       VP                  V n        \        VR R7      V n        VP                  ^ 8”  d,   \
        P                  ! VP                  VP                  4      M\
        P                  ! 4       V n	        V P                  4        R# )F)r�   N)r*   r+   Ú
num_labelsrŽ   r~   r   ÚLinearr3   ÚIdentityÚ
classifierÚ	post_init)r5   r   r6   s   &&€r"   r+   Ú$VivitForVideoClassification.__init__  ss   ø€ Ü‰Ñ˜Ô à ×+Ñ+ˆŒÜ ¸%Ô@ˆŒ
ð OU×N_ÑN_ÐbcÔNcœ"Ÿ)š) F×$6Ñ$6¸×8IÑ8IÔJÔik×itÒitÓivˆŒð 	�‰Ör%   c          
      óŒ   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[RS[S[,          RS[/# )r   r9   NÚlabelsr_   r—   r:   )r;   r˜   Ú
LongTensorrd   r	   r
   r   )r    r!   s   "€r"   r#   rª   #  s`   ø€ ÷ i
ñ i
á×'Ñ'¨$Õ.ði
ñ × Ñ  4Õ'ði
ñ #'ð	i
ñ
 Ñ+Õ,ði
ñ 
ñi
r%   c                ó  € V P                   ! V3RV/VB pVP                  pV P                  VR,          4      pRpVe   V P                  ! W'V P                  3/ VB p\        VVVP                  VP                  R7      # )a  
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
    Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
    config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
    `config.num_labels > 1` a classification loss is computed (Cross-Entropy).

Examples:

```python
>>> import av
>>> import numpy as np
>>> import torch

>>> from transformers import VivitImageProcessor, VivitForVideoClassification
>>> from huggingface_hub import hf_hub_download

>>> np.random.seed(0)


>>> def read_video_pyav(container, indices):
...     '''
...     Decode the video with PyAV decoder.
...     Args:
...         container (`av.container.input.InputContainer`): PyAV container.
...         indices (`list[int]`): List of frame indices to decode.
...     Returns:
...         result (np.ndarray): np array of decoded frames of shape (num_frames, height, width, 3).
...     '''
...     frames = []
...     container.seek(0)
...     start_index = indices[0]
...     end_index = indices[-1]
...     for i, frame in enumerate(container.decode(video=0)):
...         if i > end_index:
...             break
...         if i >= start_index and i in indices:
...             frames.append(frame)
...     return np.stack([x.to_ndarray(format="rgb24") for x in frames])


>>> def sample_frame_indices(clip_len, frame_sample_rate, seg_len):
...     '''
...     Sample a given number of frame indices from the video.
...     Args:
...         clip_len (`int`): Total number of frames to sample.
...         frame_sample_rate (`int`): Sample every n-th frame.
...         seg_len (`int`): Maximum allowed index of sample's last frame.
...     Returns:
...         indices (`list[int]`): List of sampled frame indices
...     '''
...     converted_len = int(clip_len * frame_sample_rate)
...     end_idx = np.random.randint(converted_len, seg_len)
...     start_idx = end_idx - converted_len
...     indices = np.linspace(start_idx, end_idx, num=clip_len)
...     indices = np.clip(indices, start_idx, end_idx - 1).astype(np.int64)
...     return indices


>>> # video clip consists of 300 frames (10 seconds at 30 FPS)
>>> file_path = hf_hub_download(
...     repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
... )
>>> container = av.open(file_path)

>>> # sample 32 frames
>>> indices = sample_frame_indices(clip_len=32, frame_sample_rate=4, seg_len=container.streams.video[0].frames)
>>> video = read_video_pyav(container=container, indices=indices)

>>> image_processor = VivitImageProcessor.from_pretrained("google/vivit-b-16x2-kinetics400")
>>> model = VivitForVideoClassification.from_pretrained("google/vivit-b-16x2-kinetics400")

>>> inputs = image_processor(list(video), return_tensors="pt")

>>> with torch.no_grad():
...     outputs = model(**inputs)
...     logits = outputs.logits

>>> # model predicts one of the 400 Kinetics-400 classes
>>> predicted_label = logits.argmax(-1).item()
>>> print(model.config.id2label[predicted_label])
LABEL_116
```r_   N)ÚlossÚlogitsr¡   Ú
attentions)ºNNNr'   r¹   )r~   r›   r¯   Úloss_functionr   r   r¡   r¸   )	r5   r9   r³   r_   r—   Úoutputsr£   r·   r¶   s	   &&&&,    r"   rA   Ú#VivitForVideoClassification.forward!  s‘   € ðx $(§:¢:Øñ$
Ø3Kð$
ØOUñ$
ˆð "×3Ñ3ˆØ—‘ °Õ!9Ó:ˆàˆØÒØ×%Ò% f°d·k±kÑLÀVÑLˆDä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r%   )r¯   r¬   r~   )NNF)rC   rD   rE   rF   r+   r   r   rA   rH   rI   rJ   rK   s   @@r"   r¨   r¨     s9   ù‡ € ÷
ó 
ð Ø÷i
ñ i
ó ó ÷i
ð i
r%   r¨   )rŽ   r}   r¨   )2rG   Úcollections.abcr   r;   r   Ú r   r�   Úmasking_utilsr   Úmodeling_outputsr   r   r   Úprocessing_utilsr	   Úutilsr
   r   r   Úutils.genericr   r   Úutils.output_capturingr   Úvit.modeling_vitr   r   r   r   r   r   r   r   Úconfiguration_vivitr   Ú
get_loggerrC   ÚloggerÚModuler   rM   rr   rw   ry   r{   r}   rŽ   r¨   Ú__all__rs   r%   r"   Ú<module>rË      s  ðñ Oå $ã Ý å &Ý 6ß bÑ bÝ &ß @Ñ @ß IÝ 5÷	÷ 	ó 	õ -ð 
×	Ò	˜HÓ	%€ôH˜RŸY™Yô Hô>*�mô *ôZ	�\ô 	ô	ˆvô 	ô	�ô 	ô	�)ô 	ð ô4Ð-ó 4ó ð4ð ôjj�ó jjó ðjjñZ ðôôx
Ð"6ó x
óðx
òv P‚r%   