+
    œ°³jÞ]  ã                   ó4  € ^ RI HtHt ^ RIt^ RIHt ^RIH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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!  ! R R]PD                  4      t# ! R R]PD                  4      t$R%R R llt% ! R R]PD                  4      t& ! R R]PD                  4      t' ! R R]4      t( ! R R]PD                  4      t)] ! R R]4      4       t*] ! R R ]*4      4       t+]! R!R"7       ! R# R$]*4      4       t,. R&Ot-R# )'é    )ÚCallableÚIterableN)Únn)Úinitialization)ÚACT2FN)Úcreate_bidirectional_mask)ÚGradientCheckpointingLayer)ÚBaseModelOutputÚBaseModelOutputWithPoolingÚImageClassifierOutput)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚ	torch_int)Úcan_return_tupleÚmerge_with_config_defaults)Úcapture_outputs©Ú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   "€Úi/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/vivit/modeling_vivit.pyÚ__annotate__Ú#VivitTubeletEmbeddings.__annotate__0   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# )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__0   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"   @   s'   ø€ ÷ Hñ H¡E§L¡Lð H±U·\±\ñ Hr#   c                ó†   € VP                  ^^4      pV P                  V4      P                  ^4      P                  ^^4      # )é   )Ú	transposer1   Úflatten)r2   r6   s   &&r    ÚforwardÚVivitTubeletEmbeddings.forward@   s;   € à#×-Ñ-¨a°Ó3ˆØ�‰˜|Ó,×4Ñ4°QÓ7×AÑAÀ!ÀQÓGÐGr#   )r*   r-   r1   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r(   r?   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r3   r   s   @@r    r   r   '   s&   ù‡ € ñ÷
ó 
÷ H÷ Hð Hr#   r   c                   ój   a a€ ] tR t^Ft oRtV3R lV 3R lltV3R lR 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__K   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        \        P                  ! VP                  4      V n        VP                  R,          V n        V P                  P"                  V n        R# )r<   ºr<   NNN)r'   r(   r   Ú	Parameterr9   Úzerosr0   Ú	cls_tokenr   Úpatch_embeddingsr-   Úposition_embeddingsÚDropoutÚhidden_dropout_probÚdropoutr)   Ú
patch_sizer*   )r2   r   r-   r3   s   && €r    r(   ÚVivitEmbeddings.__init__K   s³   ø€ Ü‰ÑÔäŸš¤e§k¢k°!°Q¸×8JÑ8JÓ&KÓLˆŒÜ 6°vÓ >ˆÔØ×+Ñ+×7Ñ7ˆÜ#%§<¢<´·²¸A¸{ÈQ½ÐPV×PbÑPbÓ0cÓ#dˆÔ Ü—z’z &×"<Ñ"<Ó=ˆŒà ×-Ñ-¨bÕ1ˆŒØ×/Ñ/×:Ñ:ˆŽr#   c                óZ   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[ P                  /# )r   Ú
embeddingsÚheightÚwidthr7   )r9   r:   Úint)r   r   s   "€r    r!   rM   W   s;   ø€ ÷ %Dñ %D±5·<±<ð %DÉð %DÑUXð %DÑ]b×]iÑ]iñ %Dr#   c                óú  € V P                   P                  pV P                  P                  ^,          ^,
          p\        P
                  P                  4       '       g   WE8X  d   W#8X  d   V P                  # V P                  R,          pV P                  R,          pVP                  R,          pW P                  ^ ,          ,          p	W0P                  ^,          ,          p
\        VR,          4      pVP                  ^W»V4      pVP                  ^ ^^^4      p\        P                  P                  VWš3RRR7      pVP                  ^ ^^^4      P                  ^RV4      p\        P                  ! Wg3^R7      # )	aÐ  
This method allows to interpolate the pre-trained position encodings, to be able to use the model on higher resolution
images. This method is also adapted to support torch.jit tracing.

Adapted from:
- https://github.com/facebookresearch/dino/blob/de9ee3df6cf39fac952ab558447af1fa1365362a/vision_transformer.py#L174-L194, and
- https://github.com/facebookresearch/dinov2/blob/e1277af2ba9496fbadf7aec6eba56e8d882d1e35/dinov2/models/vision_transformer.py#L179-L211
g      à?ÚbicubicF)ÚsizeÚmodeÚalign_corners©Údim)ºNNN:Nr<   N)rf   rO   éÿÿÿÿ)rS   r-   rT   Úshaper9   ÚjitÚ
is_tracingrX   r   ÚreshapeÚpermuter   Ú
functionalÚinterpolateÚviewÚcat)r2   r[   r\   r]   r-   Únum_positionsÚclass_pos_embedÚpatch_pos_embedre   Ú
new_heightÚ	new_widthÚsqrt_num_positionss   &&&&        r    Úinterpolate_pos_encodingÚ(VivitEmbeddings.interpolate_pos_encodingW   sK  € ð ×+Ñ+×7Ñ7ˆØ×0Ñ0×6Ñ6°qÕ9¸AÕ=ˆô �y‰y×#Ñ#×%Ò%¨+Ô*FÈ6Ì?Ø×+Ñ+Ð+à×2Ñ2°5Õ9ˆØ×2Ñ2°5Õ9ˆà×Ñ˜rÕ"ˆàŸ™¨qÕ1Õ1ˆ
ØŸ_™_¨QÕ/Õ/ˆ	ä& }°cÕ'9Ó:ÐØ)×1Ñ1°!Ð5GÐ]`ÓaˆØ)×1Ñ1°!°Q¸¸1Ó=ˆäŸ-™-×3Ñ3ØØÐ(ØØð	 4ó 
ˆð *×1Ñ1°!°Q¸¸1Ó=×BÑBÀ1ÀbÈ#ÓNˆä�yŠy˜/Ð;ÀÔCÐCr#   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# )r   r6   rw   r7   )r9   r:   Úbool)r   r   s   "€r    r!   rM   ~   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<   rd   zInput image size (Ú*z) doesn't match model (z).rg   )rh   rS   rR   Úexpandr9   rp   rw   r*   Ú
ValueErrorrT   rW   )
r2   r6   rw   Ú
batch_sizer,   r/   r\   r]   r[   Ú
cls_tokenss
   &&&       r    r?   ÚVivitEmbeddings.forward~   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#   )rR   rW   r*   rS   rX   rT   )F)rA   rB   rC   rD   rE   r(   rw   r?   rF   rG   rH   rI   s   @@r    rK   rK   F   s0   ù‡ € ñ÷
;ó 
;÷%Dð %D÷N÷ ò r#   rK   c                ó  € V ^8„  d   QhR\         P                  R\        P                  R\        P                  R\        P                  R\        P                  R,          R\        R,          R\        R	\
        \        ,          /# )
r   ÚmoduleÚqueryÚkeyÚvalueÚattention_maskNÚscalingrW   Úkwargs)r   ÚModuler9   r:   Úfloatr   r   )r   s   "r    r!   r!   •   s{   € ÷ %ñ %Ü�I‰Ið%ä�<‰<ð%ô 
�‰ð%ô �<‰<ð	%ô
 —L‘L 4Õ'ð%ô �T�\ð%ô ð%ô Ô'Õ(ñ%r#   c                 ó  € Vf   VP                  R4      R,          p\        P                  ! WP                  ^^4      4      V,          pVe	   W„,           p\        P
                  P                  VR\        P                  R7      P                  VP                  4      p\        P
                  P                  W†V P                  R7      p\        P                  ! Wƒ4      p	V	P                  ^^4      P                  4       p	W˜3# )N)re   Údtype)ÚpÚtrainingrg   ç      à¿)ra   r9   Úmatmulr=   r   rm   ÚsoftmaxÚfloat32Útor�   rW   r�   Ú
contiguous)
rƒ   r„   r…   r†   r‡   rˆ   rW   r‰   Úattn_weightsÚattn_outputs
   &&&&&&&,  r    Úeager_attention_forwardr˜   •   sÉ   € ð ‚Ø—*‘*˜R“. DÕ(ˆô —<’< §}¡}°Q¸Ó':Ó;¸gÕE€LàÒ!Ø#Õ4ˆä—=‘=×(Ñ(¨¸2ÄUÇ]Á]Ð(ÓS×VÑVÐW\×WbÑWbÓc€LÜ—=‘=×(Ñ(¨È6Ï?É?Ð(Ó[€Lä—,’,˜|Ó3€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€KàÐ$Ð$r#   c                   óT   a a€ ] tR t^±t o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# )ÚVivitAttentionc                ó    <€ V ^8„  d   QhRS[ /# r   r   )r   r   s   "€r    r!   ÚVivitAttention.__annotate__²   s   ø€ ÷ kñ k™{ñ kr#   c                ó`  <€ \         SV `  4        Wn        VP                  V n        \	        VR VP
                  VP                  ,          4      V n        VP                  V n        V P                  R,          V n	        RV n
        \        P                  ! VP
                  VP                  V P                  ,          VP                  R7      V n        \        P                  ! VP
                  VP                  V P                  ,          VP                  R7      V n        \        P                  ! VP
                  VP                  V P                  ,          VP                  R7      V n        \        P                  ! VP                  V P                  ,          VP
                  RR7      V n        R# )Úhead_dimF)ÚbiasTNr�   )r'   r(   r   Únum_attention_headsÚgetattrr0   rž   Úattention_probs_dropout_probÚattention_dropoutrˆ   Ú	is_causalr   ÚLinearÚqkv_biasÚq_projÚk_projÚv_projÚo_proj©r2   r   r3   s   &&€r    r(   ÚVivitAttention.__init__²   s*  ø€ Ü‰ÑÔØŒØ#)×#=Ñ#=ˆÔ Ü ¨
°F×4FÑ4FÈ&×JdÑJdÕ4dÓeˆŒØ!'×!DÑ!DˆÔØ—}‘} dÕ*ˆŒØˆŒä—i’i × 2Ñ 2°F×4NÑ4NÐQU×Q^ÑQ^Õ4^Ðek×etÑetÔuˆŒÜ—i’i × 2Ñ 2°F×4NÑ4NÐQU×Q^ÑQ^Õ4^Ðek×etÑetÔuˆŒÜ—i’i × 2Ñ 2°F×4NÑ4NÐQU×Q^ÑQ^Õ4^Ðek×etÑetÔuˆŒÜ—i’i × :Ñ :¸T¿]¹]Õ JÈF×L^ÑL^ÐeiÔjˆŽr#   c          
      ó¶   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[S[,          RS[S[ P                  S[ P                  3,          /# ©r   Úhidden_statesr‡   Nr‰   r7   )r9   r:   r   r   Útuple)r   r   s   "€r    r!   rœ   À   sX   ø€ ÷ )ñ )á—|‘|ð)ñ Ÿ™ tÕ+ð)ñ Ñ+Õ,ð	)ñ
 
‰u�|‰|™UŸ\™\Ð)Õ	*ñ)r#   c                ó¨  € VP                   R R p. VORNV P                  N5pV P                  V4      P                  V4      P	                  ^^4      pV P                  V4      P                  V4      P	                  ^^4      pV P                  V4      P                  V4      P	                  ^^4      p\        P                  ! V P                  P                  \        4      p	T	! V VVVV3RV P                  '       g   RMV P                  RV P                  /VB w  r«V
P                  ! . VORN5!  P!                  4       p
V P#                  V
4      p
W«3# )NrW   ç        rˆ   rg   )rh   rž   r§   ro   r=   r¨   r©   r   Úget_interfacer   Ú_attn_implementationr˜   r�   r£   rˆ   rk   r•   rª   )r2   r¯   r‡   r‰   Úinput_shapeÚhidden_shapeÚquery_statesÚ
key_statesÚvalue_statesÚattention_interfacer—   r–   s   &&&,        r    r?   ÚVivitAttention.forwardÀ   sN  € ð $×)Ñ)¨#¨2Ð.ˆØ8˜Ð8 bÐ8¨$¯-©-Ñ8ˆà—{‘{ =Ó1×6Ñ6°|ÓD×NÑNÈqÐRSÓTˆØ—[‘[ Ó/×4Ñ4°\ÓB×LÑLÈQÐPQÓRˆ
Ø—{‘{ =Ó1×6Ñ6°|ÓD×NÑNÈqÐRSÓTˆä(?×(MÒ(MØ�K‰K×,Ñ,Ô.Eó)
Ðñ %8ØØØØØñ	%
ð  $Ÿ}Ÿ}˜}‘C°$×2HÑ2Hð	%
ð —L‘Lð	%
ð ñ	%
Ñ!ˆð "×)Ò)Ð;¨;Ð;¸Ó;×FÑFÓHˆØ—k‘k +Ó.ˆàÐ(Ð(r#   )
r£   r   rž   r¤   r¨   r    rª   r§   rˆ   r©   ©N©	rA   rB   rC   rD   r(   r?   rF   rG   rH   rI   s   @@r    rš   rš   ±   s    ù‡ € ÷kó k÷)÷ )ò )r#   rš   c                   óP   a a€ ] tR t^ât oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚVivitMLPc                ó    <€ V ^8„  d   QhRS[ /# r   r   )r   r   s   "€r    r!   ÚVivitMLP.__annotate__ã   s   ø€ ÷ Kñ K™{ñ Kr#   c                ó(  <€ \         SV `  4        Wn        \        VP                  ,          V n        \        P                  ! VP                  VP                  4      V n
        \        P                  ! VP                  VP                  4      V n        R # r¼   )r'   r(   r   r   Ú
hidden_actÚactivation_fnr   r¥   r0   Úintermediate_sizeÚfc1Úfc2r«   s   &&€r    r(   ÚVivitMLP.__init__ã   sb   ø€ Ü‰ÑÔØŒÜ# F×$5Ñ$5Õ6ˆÔÜ—9’9˜V×/Ñ/°×1IÑ1IÓJˆŒÜ—9’9˜V×5Ñ5°v×7IÑ7IÓJˆŽr#   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   r¯   r7   r8   )r   r   s   "€r    r!   rÁ   ê   s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r#   c                ól   € V P                  V4      pV P                  V4      pV P                  V4      pV# r¼   )rÆ   rÄ   rÇ   )r2   r¯   s   &&r    r?   ÚVivitMLP.forwardê   s4   € ØŸ™ Ó/ˆØ×*Ñ*¨=Ó9ˆØŸ™ Ó/ˆàÐr#   )rÄ   r   rÆ   rÇ   r½   rI   s   @@r    r¿   r¿   â   s    ù‡ € ÷Kó K÷÷ ð r#   r¿   c                   óT   a a€ ] tR t^òt o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# )Ú
VivitLayerc                ó    <€ V ^8„  d   QhRS[ /# r   r   )r   r   s   "€r    r!   ÚVivitLayer.__annotate__ó   s   ø€ ÷ >ñ >™{ñ >r#   c                ór  <€ \         SV `  4        \        V4      V n        \        P
                  ! VP                  VP                  R 7      V n        \        P
                  ! VP                  VP                  R 7      V n	        \        V4      V n        \        P                  ! VP                  4      V n        R# )©ÚepsN)r'   r(   rš   Ú	attentionr   Ú	LayerNormr0   Úlayer_norm_epsÚlayernorm_beforeÚlayernorm_afterr¿   ÚmlprU   rV   rW   r«   s   &&€r    r(   ÚVivitLayer.__init__ó   sz   ø€ Ü‰ÑÔÜ'¨Ó/ˆŒÜ "§¢¨V×-?Ñ-?ÀV×EZÑEZÔ [ˆÔÜ!Ÿ|š|¨F×,>Ñ,>ÀF×DYÑDYÔZˆÔÜ˜FÓ#ˆŒÜ—z’z &×"<Ñ"<Ó=ˆŽr#   c                óŒ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[S[,          RS[ P                  /# r®   )r9   r:   r   r   )r   r   s   "€r    r!   rÐ   û   sJ   ø€ ÷ ñ á—|‘|ðñ Ÿ™ tÕ+ðñ Ñ+Õ,ð	ñ
 
�‰ñr#   c                ó  € TpV P                  V4      pV P                  ! W3/ VB w  rV P                  V4      pW,           pTpV P                  V4      pV P	                  V4      pV P                  V4      pW,           pV# r¼   )r×   rÔ   rW   rØ   rÙ   )r2   r¯   r‡   r‰   ÚresidualÚ_s   &&&,  r    r?   ÚVivitLayer.forwardû   s†   € ð !ˆØ×-Ñ-¨mÓ<ˆØŸ>š>¨-ÑRÈ6ÑRÑˆØŸ™ ]Ó3ˆØ%Õ0ˆð !ˆØ×,Ñ,¨]Ó;ˆØŸ™ Ó/ˆØŸ™ ]Ó3ˆØ%Õ0ˆàÐr#   )rÔ   rW   rØ   r×   rÙ   r¼   r½   rI   s   @@r    rÎ   rÎ   ò   s   ù‡ € ÷>ó >÷÷ ò r#   rÎ   c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚVivitPooleri  c                ó    <€ V ^8„  d   QhRS[ /# r   r   )r   r   s   "€r    r!   ÚVivitPooler.__annotate__  s   ø€ ÷ 4ñ 4™{ñ 4r#   c                ó¼   <€ \         SV `  4        \        P                  ! VP                  VP
                  4      V n        \        VP                  ,          V n	        R # r¼   )
r'   r(   r   r¥   r0   Úpooler_output_sizeÚdenser   Ú
pooler_actÚ
activationr«   s   &&€r    r(   ÚVivitPooler.__init__  s>   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3LÑ3LÓMˆŒ
Ü  ×!2Ñ!2Õ3ˆŽr#   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rÊ   r8   )r   r   s   "€r    r!   rã     s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r#   c                ó\   € VR,          pV P                  V4      pV P                  V4      pV# )rf   )rf   r   )ræ   rè   )r2   r¯   Úfirst_token_tensorÚpooled_outputs   &&  r    r?   ÚVivitPooler.forward  s2   € ð +¨4Õ0ÐØŸ
™
Ð#5Ó6ˆØŸ™¨Ó6ˆØÐr#   )rè   ræ   r½   rI   s   @@r    rá   rá     s   ù‡ € ÷4ó 4÷
÷ ð r#   rá   c                   ó¢   a a€ ] tR tRt oRtRtRtRtRR.tRt	Rt
RtRtRtR]R]/tR	t]P&                  ! 4       V 3R
 l4       tV3R ltRtVtV ;t# )ÚVivitPreTrainedModeli!  Úvivitr6   TrK   rÎ   r¯   Ú
attentionsrS   c                óÖ   <€ \         SV `  V4       \        V\        4      '       dC   \        P
                  ! VP                  4       \        P
                  ! VP                  4       R# R# )zInitialize the weightsN)r'   Ú_init_weightsr+   rK   ÚinitÚzeros_rR   rT   )r2   rƒ   r3   s   &&€r    rô   Ú"VivitPreTrainedModel._init_weights4  sH   ø€ ô 	‰Ñ˜fÔ%Ü�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#   © )Úvideo)rA   rB   rC   rD   Úbase_model_prefixÚmain_input_nameÚinput_modalitiesÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_supports_sdpaÚ_supports_flash_attnÚ_supports_flex_attnÚ_supports_attention_backendÚ_can_compile_fullgraphrÎ   rš   Ú_can_record_outputsÚ_input_embed_layerr9   Úno_gradrô   Ú__annotate_func__rF   rG   rH   rI   s   @@r    rð   rð   !  s   ù‡ € ð  ÐØ$€OØ!ÐØ&*Ð#Ø*¨LÐ9ÐØ€NØÐØÐØ"&ÐØ!Ðà˜Ø�nðÐð ,Ðà
‡]‚]ƒ_ô4ó ð4÷) … r#   rð   c                   ó„   a a€ ] tR tR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# )Ú
VivitModeli=  c                ó&   <€ V ^8„  d   QhRS[ RS[/# )r   r   Úadd_pooling_layer)r   rz   )r   r   s   "€r    r!   ÚVivitModel.__annotate__?  s   ø€ ÷ ñ ™{ð ¹tñ r#   c                ó   <€ \         SV `  V4       Wn        \        V4      V n        \
        P                  ! \        VP                  4       Uu. uF  p\        V4      NK  	  up4      V n
        \
        P                  ! VP                  VP                  R7      V n        V'       d   \        V4      MRV n        V P#                  4        R# u upi )z^
add_pooling_layer (bool, *optional*, defaults to `True`):
    Whether to add a pooling layer
rÒ   N)r'   r(   r   rK   r[   r   Ú
ModuleListÚrangeÚnum_hidden_layersrÎ   ÚlayersrÕ   r0   rÖ   Ú	layernormrá   ÚpoolerÚ	post_init)r2   r   r  rÞ   r3   s   &&& €r    r(   ÚVivitModel.__init__?  s’   ø€ ô
 	‰Ñ˜Ô ØŒÜ)¨&Ó1ˆŒÜ—m’mÄÀv×G_ÑG_ÔA`Ó$aÑA`¸A¤Z°Ö%7ÑA`Ñ$aÓbˆŒÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒß->”k &Ô)ÀDˆŒà�‰Öùò	 %bs   ÁC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   r6   Nrw   r‡   r‰   r7   )r9   ÚFloatTensorrz   r:   r   r   r   )r   r   s   "€r    r!   r  P  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]
```)rw   )r   Úinputs_embedsr‡   N)Úlast_hidden_stateÚpooler_output)r[   r   r   r  r  r  r   )
r2   r6   rw   r‡   r‰   Úembedding_outputr¯   ÚlayerÚsequence_outputrí   s
   &&&&,     r    r?   ÚVivitModel.forwardM  s„   € ðj  Ÿ?™?¨<˜?ÓkÐÜ2Ø—;‘;Ø*Ø)ô
ˆð
 )ˆØ—[”[ˆEÙ! -ÑJÀ6ÑJŠMñ !àŸ.™.¨Ó7ˆØ8<¿¹Ò8O˜Ÿ™ OÔ4ÐUYˆä)¸OÔiÐir#   )r   r[   r  r  r  )T)NFN)rA   rB   rC   rD   r(   r   r   r   r?   rF   rG   rH   rI   s   @@r    r  r  =  sJ   ù‡ € ÷õ ð  Ù¨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   r¥   r0   ÚIdentityÚ
classifierr  r«   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   r6   NÚlabelsrw   r‰   r7   )r9   r  Ú
LongTensorrz   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
```rw   N)ÚlossÚlogitsr¯   rò   )rf   r   rf   )rñ   r  r+  Úloss_functionr   r   r¯   rò   )	r2   r6   r.  rw   r‰   Úoutputsr!  r2  r1  s	   &&&&,    r    r?   Ú#VivitForVideoClassification.forwardÌ  s‘   € ðx $(§:¢:Øñ$
Ø3Kð$
ØOUñ$
ˆð "×3Ñ3ˆØ—‘ °Õ!9Ó:ˆàˆØÒØ×%Ò% f°d·k±kÑLÀVÑLˆDä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r#   )r+  r)  rñ   )NNF)rA   rB   rC   rD   r(   r   r   r?   rF   rG   rH   rI   s   @@r    r%  r%  ±  s9   ù‡ € ÷
ó 
ð Ø÷i
ñ i
ó ó ÷i
ð i
r#   r%  )Nr²   )r  rð   r%  ).Úcollections.abcr   r   r9   r   Ú r   rõ   Úactivationsr   Úmasking_utilsr   Úmodeling_layersr	   Úmodeling_outputsr
   r   r   Úmodeling_utilsr   r   Úprocessing_utilsr   Úutilsr   r   r   Úutils.genericr   r   Úutils.output_capturingr   Úconfiguration_vivitr   rŠ   r   rK   r˜   rš   r¿   rÎ   rá   rð   r  r%  Ú__all__rú   r#   r    Ú<module>rC     s  ð÷* /ã Ý å &Ý !Ý 6Ý 9ß bÑ bß FÝ &ß BÑ Bß IÝ 5Ý ,ôH˜RŸY™Yô Hô>L�b—i‘iô L÷^%ô8.)�R—Y‘Yô .)ôbˆr�y‰yô ô Ð+ô ô@�"—)‘)ô ð ô4˜?ó 4ó ð4ð6 ôpjÐ%ó pjó ðpjñf ðôôx
Ð"6ó x
óðx
òv P‚r#   