+
    œ°³j‹Ô  ã                   ó„  € ^ RI t^ RIt^ RI Ht ^ RIHt ^ RIt^ RIt^ RI	H
u Ht ^ RIHt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 ^R
IHt ^RIHtH t H!t! ^RI"H#t# ^RI$H%t% ^RI&H't' ]! 4       '       d   ^ RI(H)t) ]!! 4       '       d   ^ RI*H+t+ ^ RI,H-t-  ! R R]
P\                  4      t/ ! R R]
P\                  4      t0 ! R R]
P\                  4      t1 ! R R]
P\                  4      t2RER R llt3 ! R R]
P\                  4      t4 ! R R]
P\                  4      t5 ! R  R!]
P\                  4      t6 ! R" R#]4      t7 ! R$ R%]
P\                  4      t8] ! R&R'7      ] ! R( R)]4      4       4       t9RFR* R+ llt:R, R- lt;R. R/ lt< ! R0 R1]
P\                  4      t=R2 R3 lt>R4 R5 lt? ! R6 R7]
P\                  4      t@]  ! R8 R9]4      4       tA ! R: R;]
P„                  4      tC ! R< R=]
P\                  4      tD ! R> R?]
P\                  4      tE ! R@ RA]
P\                  4      tF] ! RBR'7       ! RC RD]A4      4       tGR9RD.tHR# )Gé    N)ÚCallable)Ú	dataclass)ÚTensorÚnn)Úinitialization)ÚACT2FN)ÚModelOutputÚis_scipy_availableÚrequires_backends)ÚGradientCheckpointingLayer)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚis_accelerate_available)Úmerge_with_config_defaults)Úcapture_outputs©ÚVideomtConfig)Úlinear_sum_assignment)ÚPartialState)Úreducec                   óH   a a€ ] tR t^3t oRtV 3R ltV3R lR ltRtVtV ;t	# )ÚVideomtPatchEmbeddingszÜ
This class turns `pixel_values` of shape `(batch_size, num_channels, height, width)` into the initial
`hidden_states` (patch embeddings) of shape `(batch_size, seq_length, hidden_size)` to be consumed by a
Transformer.
c                ó  <€ \         SV `  4        VP                  VP                  r2VP                  VP
                  rT\        V\        P                  P                  4      '       d   TMW"3p\        V\        P                  P                  4      '       d   TMW33pV^,          V^,          ,          V^ ,          V^ ,          ,          ,          pW n        W0n        W@n        W`n
        \        P                  ! WEW3R7      V n        R# )é   ©Úkernel_sizeÚstrideN)ÚsuperÚ__init__Ú
image_sizeÚ
patch_sizeÚnum_channelsÚhidden_sizeÚ
isinstanceÚcollectionsÚabcÚIterableÚnum_patchesr   ÚConv2dÚ
projection)ÚselfÚconfigr#   r$   r%   r&   r+   Ú	__class__s   &&     €Úm/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/videomt/modeling_videomt.pyr"   ÚVideomtPatchEmbeddings.__init__:   sÃ   ø€ Ü‰ÑÔØ!'×!2Ñ!2°F×4EÑ4E�JØ$*×$7Ñ$7¸×9KÑ9K�kä#-¨j¼+¿/¹/×:RÑ:R×#SÒ#S‘ZÐZdÐYqˆ
Ü#-¨j¼+¿/¹/×:RÑ:R×#SÒ#S‘ZÐZdÐYqˆ
Ø! !•}¨
°1­Õ5¸*ÀQ½-È:ÐVWÍ=Õ:XÕYˆØ$ŒØ$ŒØ(ÔØ&ÔäŸ)š) LÈ:ÔiˆŽó    c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )é   Úpixel_valuesÚreturn©Útorchr   )ÚformatÚ__classdict__s   "€r1   Ú__annotate__Ú#VideomtPatchEmbeddings.__annotate__I   s#   ø€ ÷ 
ñ 
¡E§L¡Lð 
±U·\±\ñ 
r3   c                óD  € VP                   ^,          pW P                  8w  d   \        RV P                   RV R24      hVP                  V P                  P
                  P                  R7      pV P	                  V4      P                  ^4      P                  ^^4      pV# )r   zoMake sure that the channel dimension of the pixel values match with the one set in the configuration. Expected z	 but got Ú.©Údtype)	Úshaper%   Ú
ValueErrorÚtor-   ÚweightrA   ÚflattenÚ	transpose)r.   r6   r%   Ú
embeddingss   &&  r1   ÚforwardÚVideomtPatchEmbeddings.forwardI   s˜   € Ø#×)Ñ)¨!Õ,ˆØ×,Ñ,Ô,ÜðØ!×.Ñ.Ð/¨y¸¸ÀaðIóð ð
 $—‘¨T¯_©_×-CÑ-C×-IÑ-I�ÓJˆØ—_‘_ \Ó2×:Ñ:¸1Ó=×GÑGÈÈ1ÓMˆ
ØÐr3   )r#   r%   r+   r$   r-   ©
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r"   rI   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r0   r;   s   @@r1   r   r   3   s   ù‡ € ñõj÷
÷ 
ð 
r3   r   c                   óX   a a€ ] tR t^Vt oR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	# )ÚVideomtEmbeddingszE
Construct the CLS token, mask token, position and patch embeddings.
c                ó$   <€ V ^8„  d   QhRS[ RR/# ©r5   r/   r7   Nr   )r:   r;   s   "€r1   r<   ÚVideomtEmbeddings.__annotate__[   s   ø€ ÷ Nñ N™}ð N°ñ Nr3   c                óX  <€ \         SV `  4        Wn        VP                  V n        \        P
                  ! \        P                  ! ^^VP                  4      4      V n	        \        P
                  ! \        P                  ! ^VP                  VP                  4      4      V n        \        V4      V n        V P                  P                  p\        P                   ! VP"                  4      V n        ^VP                  ,           V n        \        P(                  ! W!P                  4      V n        \        P,                  ! \        P.                  ! V4      P1                  R4      RR7      V n        \        P
                  ! \        P                  ! ^^VP                  4      4      V n        R# )r   F)Ú
persistentN©r   éÿÿÿÿ)r!   r"   r/   r$   r   Ú	Parameterr9   Úrandnr&   Ú	cls_tokenÚzerosÚnum_register_tokensÚregister_tokensr   Úpatch_embeddingsr+   ÚDropoutÚhidden_dropout_probÚdropoutÚnum_prefix_tokensÚ	EmbeddingÚposition_embeddingsÚBufferÚarangeÚexpandÚposition_idsÚ
mask_token)r.   r/   r+   r0   s   && €r1   r"   ÚVideomtEmbeddings.__init__[   s  ø€ Ü‰ÑÔàŒØ ×+Ñ+ˆŒäŸš¤e§k¢k°!°Q¸×8JÑ8JÓ&KÓLˆŒÜ!Ÿ|š|¬E¯KªK¸¸6×;UÑ;UÐW]×WiÑWiÓ,jÓkˆÔÜ 6°vÓ >ˆÔØ×+Ñ+×7Ñ7ˆÜ—z’z &×"<Ñ"<Ó=ˆŒØ!" V×%?Ñ%?Õ!?ˆÔÜ#%§<¢<°×=OÑ=OÓ#PˆÔ ÜŸIšI¤e§l¢l°;Ó&?×&FÑ&FÀwÓ&OÐ\aÔbˆÔÜŸ,š,¤u§{¢{°1°a¸×9KÑ9KÓ'LÓMˆŽr3   c                óv   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[ P                  /# )r5   r6   Úbool_masked_posNr7   r8   )r:   r;   s   "€r1   r<   rY   k   s7   ø€ ÷ ñ ¡E§L¡Lð Á5Ç<Á<ÐRVÕCVð Ñbg×bnÑbnñ r3   c                ó6  € VP                   ^8X  dG   VP                  w  r4rVpVP                  W4,          WVV4      pVe   VP                  W4,          R4      pM8Ve5   VP                   ^8”  d$   VP                  VP                  ^ ,          R4      pVP                  ^ ,          pV P                  V4      pVe\   VP	                  VP
                  \        P                  R7      P                  R4      p	\        P                  ! W�P                  V4      pV P                  P                  VRR4      p
V P                  P                  VRR4      pW€P                  V P                  4      ,           p\        P                   ! W«V.^R7      pV P#                  V4      pV# )é   )ÚdevicerA   ©Údimr]   )ÚndimrB   Úreshaperd   rD   ru   r9   ÚboolÚ	unsqueezeÚwherero   r`   rm   rc   rj   rn   Úcatrg   )r.   r6   rr   Ú
batch_sizeÚ
num_framesr%   ÚheightÚwidthrH   ÚmaskÚ
cls_tokensrc   s   &&&         r1   rI   ÚVideomtEmbeddings.forwardk   sa  € Ø×Ñ Ô!ØBN×BTÑBTÑ?ˆJ L¸%Ø'×/Ñ/°
Õ0GÈÐ_dÓeˆLàÒ*Ø"1×"9Ñ"9¸*Õ:QÐSUÓ"V�øØÒ(¨_×-AÑ-AÀAÔ-EØ-×5Ñ5°o×6KÑ6KÈAÕ6NÐPRÓSˆOà!×'Ñ'¨Õ*ˆ
Ø×*Ñ*¨<Ó8ˆ
àÒ&Ø"×%Ñ%¨Z×->Ñ->ÄeÇjÁjÐ%ÓQ×[Ñ[Ð\^Ó_ˆDÜŸš T¯?©?¸JÓGˆJà—^‘^×*Ñ*¨:°r¸2Ó>ˆ
Ø×.Ñ.×5Ñ5°jÀ"ÀbÓIˆà×":Ñ":¸4×;LÑ;LÓ"MÕMˆ
Ü—Y’Y 
¸ZÐHÈaÔPˆ
Ø—\‘\ *Ó-ˆ
ØÐr3   )
r`   r/   rg   ro   rh   rd   r$   rj   rn   rc   ©NrK   rT   s   @@r1   rV   rV   V   s%   ù‡ € ñ÷Nó N÷ ÷ ò r3   rV   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# )Ú
VideomtMLPc                ó   <€ V ^8„  d   QhRR/# ©r5   r7   N© )r:   r;   s   "€r1   r<   ÚVideomtMLP.__annotate__†   s   ø€ ÷ 	Gñ 	G $ñ 	Gr3   c                óš  <€ \         SV `  4        VP                  ;r#\        VP                  VP                  ,          4      p\
        P                  ! W$R R7      V n        \        VP                  \        4      '       d   \        VP                  ,          V n        MVP                  V n        \
        P                  ! WCR R7      V n        R# )T©ÚbiasN)r!   r"   r&   ÚintÚ	mlp_ratior   ÚLinearÚfc1r'   Ú
hidden_actÚstrr   Ú
activationÚfc2©r.   r/   Úin_featuresÚout_featuresÚhidden_featuresr0   s   &&   €r1   r"   ÚVideomtMLP.__init__†   s�   ø€ Ü‰ÑÔØ%+×%7Ñ%7Ð7ˆÜ˜f×0Ñ0°6×3CÑ3CÕCÓDˆÜ—9’9˜[ÀÔEˆŒÜ�f×'Ñ'¬×-Ò-Ü$ V×%6Ñ%6Õ7ˆD�Oà$×/Ñ/ˆDŒOÜ—9’9˜_ÀÔFˆŽr3   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r5   Úhidden_stater7   r8   )r:   r;   s   "€r1   r<   r‹   ‘   ó#   ø€ ÷ ñ ¡E§L¡Lð ±U·\±\ñ r3   c                ól   € V P                  V4      pV P                  V4      pV P                  V4      pV# r…   )r’   r•   r–   ©r.   rž   s   &&r1   rI   ÚVideomtMLP.forward‘   s2   € Ø—x‘x Ó-ˆØ—‘ |Ó4ˆØ—x‘x Ó-ˆØÐr3   )r•   r’   r–   ©	rL   rM   rN   rO   r"   rI   rQ   rR   rS   rT   s   @@r1   r‡   r‡   …   s    ù‡ € ÷	Gó 	G÷÷ ð r3   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# )ÚVideomtGatedMLPc                ó   <€ V ^8„  d   QhRR/# r‰   rŠ   )r:   r;   s   "€r1   r<   ÚVideomtGatedMLP.__annotate__™   ó   ø€ ÷ Oñ O $ñ Or3   c                ój  <€ \         SV `  4        VP                  ;r#\        VP                  VP                  ,          4      p\        V^,          ^,          4      ^,           ^,          ^,          p\
        P                  ! V^V,          RR7      V n        \
        P                  ! WCRR7      V n        R# ©r5   Tr�   N©	r!   r"   r&   r�   r�   r   r‘   Ú
weights_inÚweights_outr—   s   &&   €r1   r"   ÚVideomtGatedMLP.__init__™   ó†   ø€ Ü‰ÑÔØ%+×%7Ñ%7Ð7ˆÜ˜f×0Ñ0°6×3CÑ3CÕCÓDˆÜ˜°Õ2°QÕ6Ó7¸!Õ;ÀÕAÀAÕEˆäŸ)š) K°°_Õ1DÈ4ÔPˆŒÜŸ9š9 _ÈÔNˆÖr3   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r�   r8   )r:   r;   s   "€r1   r<   r§   ¢   ó#   ø€ ÷ (ñ (¡E§L¡Lð (±U·\±\ñ (r3   c                ó¼   € V P                  V4      pVP                  ^RR7      w  r#\        P                  P	                  V4      V,          pV P                  V4      # ©r5   rv   r]   ©r¬   Úchunkr   Ú
functionalÚsilur­   ©r.   rž   Úx1Úx2Úhiddens   &&   r1   rI   ÚVideomtGatedMLP.forward¢   óQ   € Ø—‘ |Ó4ˆØ×#Ñ# A¨2Ð#Ó.‰ˆÜ—‘×#Ñ# BÓ'¨"Õ,ˆØ×Ñ Ó'Ð'r3   ©r¬   r­   r£   rT   s   @@r1   r¥   r¥   ˜   ó    ù‡ € ÷Oó O÷(÷ (ð (r3   r¥   c                óÞ   € V ^8„  d   QhR\         P                  R\        P                  R\        P                  R\        P                  R\        P                  R,          R\        R\        /# )	r5   ÚmoduleÚqueryÚkeyÚvalueÚattention_maskNÚscalingrg   )r   ÚModuler9   r   Úfloat)r:   s   "r1   r<   r<   ©   sg   € ÷ %ñ %Ü�I‰Ið%ä�<‰<ð%ô 
�‰ð%ô �<‰<ð	%ô
 —L‘L 4Õ'ð%ô ð%ô ñ%r3   c                 óÎ  € \         P                  ! WP                  RR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# )r   )rw   rA   )ÚpÚtrainingr]   éþÿÿÿ)r9   ÚmatmulrG   r   r¶   ÚsoftmaxÚfloat32rD   rA   rg   rË   Ú
contiguous)
rÁ   rÂ   rÃ   rÄ   rÅ   rÆ   rg   ÚkwargsÚattn_weightsÚattn_outputs
   &&&&&&&,  r1   Úeager_attention_forwardrÔ   ©   s°   € ô —<’< §}¡}°R¸Ó'<Ó=ÀÕG€LØÒ!Ø#Õ4ˆä—=‘=×(Ñ(¨¸2ÄUÇ]Á]Ð(ÓS×VÑVÐW\×WbÑWbÓc€LÜ—=‘=×(Ñ(¨È6Ï?É?Ð(Ó[€Lä—,’,˜|Ó3€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€KàÐ$Ð$r3   c                   óL   a a€ ] tR t^Àt oRtV 3R ltRV3R lR lltRtVtV ;t	# )ÚVideomtAttentionz=Multi-headed attention from 'Attention Is All You Need' paperc                ó<  <€ \         SV `  4        Wn        VP                  V n        VP
                  V n        V P                  V P                  ,          V n        V P                  V P                  ,          V P                  8w  d'   \        R V P                   RV P                   R24      hV P                  R,          V n	        VP                  V n        RV n        \        P                  ! V P                  V P                  4      V n        \        P                  ! V P                  V P                  4      V n        \        P                  ! V P                  V P                  4      V n        \        P                  ! V P                  V P                  4      V n        R# )z;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).FNg      à¿)r!   r"   r/   r&   Ú	embed_dimÚnum_attention_headsÚ	num_headsÚhead_dimrC   ÚscaleÚattention_dropoutrg   Ú	is_causalr   r‘   Úk_projÚv_projÚq_projÚout_proj©r.   r/   r0   s   &&€r1   r"   ÚVideomtAttention.__init__Ã   s  ø€ Ü‰ÑÔØŒØ×+Ñ+ˆŒØ×3Ñ3ˆŒØŸ™¨$¯.©.Õ8ˆŒØ�=‰=˜4Ÿ>™>Õ)¨T¯^©^Ô;ÜØMÈdÏnÉnÐM]ð ^Ø—N‘NÐ# 2ð'óð ð —]‘] DÕ(ˆŒ
Ø×/Ñ/ˆŒØˆŒä—i’i §¡°·±Ó?ˆŒÜ—i’i §¡°·±Ó?ˆŒÜ—i’i §¡°·±Ó?ˆŒÜŸ	š	 $§.¡.°$·.±.ÓAˆŽr3   c          	      ó®   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[S[ P                  S[ P                  R,          3,          /# ©r5   Úhidden_statesrÅ   Nr7   )r9   r   Útuple)r:   r;   s   "€r1   r<   ÚVideomtAttention.__annotate__×   sM   ø€ ÷ !)ñ !)á—|‘|ð!)ñ Ÿ™ tÕ+ð!)ñ
 
‰u�|‰|™UŸ\™\¨DÕ0Ð0Õ	1ñ!)r3   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	! T TTTTV P                  V P                  V P                  '       g   RMV P                  R7      w  r«V
P                   ! . VORN5!  P#                  4       p
V P%                  V
4      p
W«3# )z#Input shape: Batch x Time x ChannelNç        )rÞ   rÆ   rg   r]   )rB   rÛ   rá   ÚviewrG   rß   rà   r   Úget_interfacer/   Ú_attn_implementationrÔ   rÞ   rÜ   rË   rg   ry   rÐ   râ   )r.   rç   rÅ   rÑ   Úinput_shapeÚhidden_shapeÚqueriesÚkeysÚvaluesÚattention_interfacerÓ   rÒ   s   &&&,        r1   rI   ÚVideomtAttention.forward×   s8  € ð $×)Ñ)¨#¨2Ð.ˆà8˜Ð8 bÐ8¨$¯-©-Ñ8ˆØ—+‘+˜mÓ,×1Ñ1°,Ó?×IÑIÈ!ÈQÓOˆØ�{‰{˜=Ó)×.Ñ.¨|Ó<×FÑFÀqÈ!ÓLˆØ—‘˜]Ó+×0Ñ0°Ó>×HÑHÈÈAÓNˆä(?×(MÒ(MØ�K‰K×,Ñ,Ô.Eó)
Ðñ %8ØØØØØØ—n‘nØ—J‘JØ#Ÿ}Ÿ}˜}‘C°$·,±,ô	%
Ñ!ˆð "×)Ò)Ð;¨;Ð;¸Ó;×FÑFÓHˆØ—m‘m KÓ0ˆàÐ(Ð(r3   )r/   rg   rØ   rÛ   rÞ   rß   rÚ   râ   rá   rÜ   rà   r…   rK   rT   s   @@r1   rÖ   rÖ   À   s   ù‡ € ÙGõB÷(!)÷ !)ò !)r3   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# )ÚVideomtSwiGLUFFNc                ó   <€ V ^8„  d   QhRR/# r‰   rŠ   )r:   r;   s   "€r1   r<   ÚVideomtSwiGLUFFN.__annotate__ü   r¨   r3   c                ój  <€ \         SV `  4        VP                  ;r#\        VP                  VP                  ,          4      p\        V^,          ^,          4      ^,           ^,          ^,          p\
        P                  ! V^V,          RR7      V n        \
        P                  ! WCRR7      V n        R# rª   r«   r—   s   &&   €r1   r"   ÚVideomtSwiGLUFFN.__init__ü   r¯   r3   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r�   r8   )r:   r;   s   "€r1   r<   rù     r±   r3   c                ó¼   € V P                  V4      pVP                  ^RR7      w  r#\        P                  P	                  V4      V,          pV P                  V4      # r³   r´   r¸   s   &&   r1   rI   ÚVideomtSwiGLUFFN.forward  r½   r3   r¾   r£   rT   s   @@r1   r÷   r÷   û   r¿   r3   r÷   c                   ój   a a€ ] tR tRt oRtR
V3R lV 3R llltV3R lR ltV3R lR ltR	tVt	V ;t
# )ÚVideomtDropPathi  zÃStochastic depth (DropPath) per sample, for residual blocks.

Identity when ``drop_prob`` is 0 or outside training. See `Deep Networks with Stochastic Depth
<https://arxiv.org/abs/1603.09382>`_.
c                ó$   <€ V ^8„  d   QhRS[ RR/# )r5   Ú	drop_probr7   N)rÈ   )r:   r;   s   "€r1   r<   ÚVideomtDropPath.__annotate__  s   ø€ ÷ #ñ #¡%ð #°$ñ #r3   c                ó0   <€ \         SV `  4        Wn        R # r…   )r!   r"   r  )r.   r  r0   s   &&€r1   r"   ÚVideomtDropPath.__init__  s   ø€ Ü‰ÑÔØ"Žr3   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r5   rç   r7   r8   )r:   r;   s   "€r1   r<   r    s#   ø€ ÷ <ñ <¡U§\¡\ð <±e·l±lñ <r3   c                ó˜  € V P                   R 8X  g   V P                  '       g   V# ^V P                   ,
          pVP                  ^ ,          3RVP                  ^,
          ,          ,           p\        P
                  ! W1P                  VP                  R7      p\        P                  ! WB,           4      pVP                  V4      V,          # )rë   ©rA   ru   )r   )
r  rË   rB   rx   r9   ÚrandrA   ru   ÚfloorÚdiv)r.   rç   Ú	keep_probrB   Úrandom_tensors   &&   r1   rI   ÚVideomtDropPath.forward  s•   € Ø�>‰>˜SÔ ¨¯¯¨Ø Ð Ø˜Ÿ™Õ&ˆ	Ø×$Ñ$ QÕ'Ð)¨D°M×4FÑ4FÈÕ4JÕ,KÕKˆÜŸ
š
 5×0CÑ0CÈM×L`ÑL`ÔaˆÜŸš MÕ$=Ó>ˆØ× Ñ  Ó+¨mÕ;Ð;r3   c                ó    <€ V ^8„  d   QhRS[ /# )r5   r7   )r”   )r:   r;   s   "€r1   r<   r     s   ø€ ÷ %ñ %™Cñ %r3   c                ó    € R V P                    2# )zp=©r  ©r.   s   &r1   Ú
extra_reprÚVideomtDropPath.extra_repr   s   € Ø�D—N‘NÐ#Ð$Ð$r3   r  ©rë   )rL   rM   rN   rO   rP   r"   rI   r  rQ   rR   rS   rT   s   @@r1   r   r     s-   ù‡ € ñ÷#õ #÷<ð <÷%÷ %ð %r3   r   c                   óX   a a€ ] tR tRt oR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	# )	ÚVideomtLayeri$  zCThis corresponds to the Block class in the original implementation.c                ó$   <€ V ^8„  d   QhRS[ RR/# rX   r   )r:   r;   s   "€r1   r<   ÚVideomtLayer.__annotate__'  s   ø€ ÷ 6ñ 6™}ð 6°ñ 6r3   c                ó.  <€ \         SV `  4        \        P                  ! VP                  VP
                  R 7      V n        \        V4      V n        \        V4      V n
        VP                  R8”  d   \        VP                  4      M\        P                  ! 4       V n        \        P                  ! VP                  VP
                  R 7      V n        VP                   '       d   \#        V4      V n        M\'        V4      V n        \        V4      V n        R# )©Úepsrë   N)r!   r"   r   Ú	LayerNormr&   Úlayer_norm_epsÚnorm1rÖ   Ú	attentionÚVideomtLayerScaleÚlayer_scale1Údrop_path_rater   ÚIdentityÚ	drop_pathÚnorm2Úuse_swiglu_ffnr÷   Úmlpr‡   Úlayer_scale2rã   s   &&€r1   r"   ÚVideomtLayer.__init__'  sÀ   ø€ Ü‰ÑÔä—\’\ &×"4Ñ"4¸&×:OÑ:OÔPˆŒ
Ü)¨&Ó1ˆŒÜ-¨fÓ5ˆÔØCI×CXÑCXÐ[^ÔC^œ¨×)>Ñ)>Ô?Ôdf×doÒdoÓdqˆŒä—\’\ &×"4Ñ"4¸&×:OÑ:OÔPˆŒ
à× × Ð Ü'¨Ó/ˆD�Hä! &Ó)ˆDŒHÜ-¨fÓ5ˆÖr3   c                óv   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[ P                  /# ræ   r8   )r:   r;   s   "€r1   r<   r  7  s:   ø€ ÷ ñ á—|‘|ðñ Ÿ™ tÕ+ðñ 
�‰ñ	r3   c                ó6  € V P                  V4      pV P                  W24      w  rEV P                  V4      pV P                  V4      V,           pV P	                  V4      pV P                  V4      pV P                  V4      pV P                  V4      V,           pV# r…   )r   r!  r#  r&  r'  r)  r*  )r.   rç   rÅ   Úhidden_states_normÚself_attention_outputÚ_Úlayer_outputs   &&&    r1   rI   ÚVideomtLayer.forward7  s—   € ð
 "ŸZ™Z¨Ó6ÐØ#'§>¡>Ð2DÓ#UÑ ÐØ $× 1Ñ 1Ð2GÓ HÐð Ÿ™Ð'<Ó=ÀÕMˆð —z‘z -Ó0ˆØ—x‘x Ó-ˆØ×(Ñ(¨Ó6ˆð —~‘~ lÓ3°mÕCˆàÐr3   )r!  r&  r#  r*  r)  r   r'  r…   rK   rT   s   @@r1   r  r  $  s!   ù‡ € ÙM÷6ó 6÷ ÷ ò r3   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# )r"  iN  c                ó   <€ V ^8„  d   QhRR/# r‰   rŠ   )r:   r;   s   "€r1   r<   ÚVideomtLayerScale.__annotate__O  s   ø€ ÷ ^ñ ^ $ñ ^r3   c                ó¸   <€ \         SV `  4        \        P                  ! VP                  \
        P                  ! VP                  4      ,          4      V n        R # r…   )	r!   r"   r   r^   Úlayerscale_valuer9   Úonesr&   Úlambda1rã   s   &&€r1   r"   ÚVideomtLayerScale.__init__O  s8   ø€ Ü‰ÑÔÜ—|’| F×$;Ñ$;¼e¿jºjÈ×I[ÑI[Ó>\Õ$\Ó]ˆŽr3   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r�   r8   )r:   r;   s   "€r1   r<   r5  S  s#   ø€ ÷ +ñ +¡E§L¡Lð +±U·\±\ñ +r3   c                ó&   € WP                   ,          # r…   ©r9  r¡   s   &&r1   rI   ÚVideomtLayerScale.forwardS  s   € ØŸl™lÕ*Ð*r3   r=  r£   rT   s   @@r1   r"  r"  N  s    ù‡ € ÷^ó ^÷+÷ +ð +r3   r"  a¨  
    Class for outputs of [`VideomtForUniversalSegmentationOutput`].

    This output can be directly passed to [`~VideomtVideoProcessor.post_process_semantic_segmentation`] or
    [`~VideomtVideoProcessor.post_process_instance_segmentation`] or
    [`~VideomtVideoProcessor.post_process_panoptic_segmentation`] to compute final segmentation maps. Please, see
    [`~VideomtVideoProcessor`] for details regarding usage.
    )Úcustom_introc                   óH   a € ] tR tRt o RtRtRtRtRtRt	Rt
V 3R ltRtV tR# )Ú%VideomtForUniversalSegmentationOutputiW  a<  
loss (`torch.Tensor`, *optional*):
    The computed loss, returned when labels are present.
class_queries_logits (`torch.FloatTensor`):
    A tensor of shape `(batch_size, num_queries, num_labels + 1)` representing the proposed classes for each
    query. Note the `+ 1` is needed because we incorporate the null class.
masks_queries_logits (`torch.FloatTensor`):
    A tensor of shape `(batch_size, num_queries, height, width)` representing the proposed masks for each
    query.
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
    Last hidden states (final feature map) of the last layer.
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
    Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each stage) of
    shape `(batch_size, sequence_length, hidden_size)`. Hidden-states all layers of the model.
attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
    Tuple of `tuple(torch.FloatTensor)` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
    sequence_length)`. Self and Cross Attentions weights from transformer decoder.
Nc                óN  <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   # )r5   NÚlossÚclass_queries_logitsÚmasks_queries_logitsÚlast_hidden_staterç   Ú
attentions)r9   ÚFloatTensorrè   )r:   r;   s   "€r1   r<   Ú2VideomtForUniversalSegmentationOutput.__annotate__W  s©   ø‡ ‚ ñ> ×
Ñ
˜dÕ
"Ñ)ñ? ñ@  ×+Ñ+¨dÕ2Ñ9ñA ñB  ×+Ñ+¨dÕ2Ñ9ñC ñD ×(Ñ(¨4Õ/Ñ6ñE ñF ™×*Ñ*Õ+¨dÕ2Ñ9ñG ñH ‘e×'Ñ'Õ(¨4Õ/Ñ6òI r3   rŠ   )rL   rM   rN   rO   rP   rC  rD  rE  rF  rç   rG  Ú__annotate_func__rQ   rR   )r;   s   @r1   rA  rA  W  s5   ø‡ € ñð& &*€DØ59ÐØ59ÐØ26ÐØ59€MØ26€J÷I ƒ r3   rA  c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r5   Úinput_featuresÚpoint_coordinatesr7   r8   )r:   s   "r1   r<   r<     s0   € ÷ ñ Ü—L‘LðÜ5:·\±\ðä
‡\�\ñr3   c                óü   € VP                  4       ^8X  d   RpVP                  ^4      p\        P                  P                  P
                  ! V RV,          R,
          3/ VB pV'       d   VP                  ^4      pV# )að  
A wrapper around `torch.nn.functional.grid_sample` to support 3D point_coordinates tensors.

Args:
    input_features (`torch.Tensor` of shape (batch_size, channels, height, width)):
        A tensor that contains features map on a height * width grid
    point_coordinates (`torch.Tensor` of shape (batch_size, num_points, 2) or (batch_size, grid_height, grid_width,:
    2)):
        A tensor that contains [0, 1] * [0, 1] normalized point coordinates
    add_dim (`bool`):
        boolean value to keep track of added dimension

Returns:
    point_features (`torch.Tensor` of shape (batch_size, channels, num_points) or (batch_size, channels,
    height_grid, width_grid):
        A tensor that contains features for points in `point_coordinates`.
Tg       @ç      ð?)rw   r{   r9   r   r¶   Úgrid_sampleÚsqueeze)rL  rM  Úadd_dimrÑ   Úpoint_featuress   &&&, r1   Úsample_pointrT    st   € ð( ×ÑÓ !Ô#ØˆØ-×7Ñ7¸Ó:Ðô —X‘X×(Ñ(×4Ò4°^ÀSÐK\ÕE\Ð_bÕEbÑmÐflÑm€NßØ'×/Ñ/°Ó2ˆàÐr3   c                ó<   € V ^8„  d   QhR\         R\         R\         /# ©r5   ÚinputsÚlabelsr7   )r   )r:   s   "r1   r<   r<   Ÿ  s!   € ÷ ñ ¤ð ´ð ¼6ñ r3   c                ó8  € V P                  4       P                  ^4      p ^\        P                  ! WP                  4      ,          pV P                  R4      R,          VP                  R4      R,          ,           p^V^,           V^,           ,          ,
          pV# )a   
A pair wise version of the dice loss, see `dice_loss` for usage.

Args:
    inputs (`torch.Tensor`):
        A tensor representing a mask
    labels (`torch.Tensor`):
        A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
        (0 for the negative class and 1 for the positive class).

Returns:
    `torch.Tensor`: The computed loss between each pairs.
r]   ©ºNNNN)Nr[  )ÚsigmoidrF   r9   rÍ   ÚTÚsum)rW  rX  Ú	numeratorÚdenominatorrC  s   &&   r1   Úpair_wise_dice_lossra  Ÿ  sr   € ð �^‰^Ó×%Ñ% aÓ(€FØ”E—L’L ¯©Ó2Õ2€Ià—*‘*˜R“. Õ)¨F¯J©J°r«N¸7Õ,CÕC€KØ�	˜A• +°¥/Õ2Õ2€DØ€Kr3   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# rV  r8   )r:   s   "r1   r<   r<   µ  s0   € ÷ ñ ´·±ð ÄuÇ|Á|ð ÔX]×XdÑXdñ r3   c                óˆ  € V P                   ^,          p\        P                  ! RR7      pV! V \        P                  ! V 4      4      pV! V \        P
                  ! V 4      4      p\        P                  ! WB,          VP                  4      p\        P                  ! WR,          ^V,
          P                  4      pWg,           pV# )aÂ  
A pair wise version of the cross entropy loss, see `sigmoid_cross_entropy_loss` for usage.

Args:
    inputs (`torch.Tensor`):
        A tensor representing a mask.
    labels (`torch.Tensor`):
        A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
        (0 for the negative class and 1 for the positive class).

Returns:
    loss (`torch.Tensor`): The computed loss between each pairs.
Únone©Ú	reduction)rB   r   ÚBCEWithLogitsLossr9   Ú	ones_likeÚ
zeros_likerÍ   r]  )	rW  rX  Úheight_and_widthÚ	criterionÚcross_entropy_loss_posÚcross_entropy_loss_negÚloss_posÚloss_negrC  s	   &&       r1   Ú$pair_wise_sigmoid_cross_entropy_lossrp  µ  s‘   € ð —|‘| A•Ðä×$Ò$¨vÔ6€IÙ& v¬u¯ª¸vÓ/FÓGÐÙ& v¬u×/?Ò/?ÀÓ/GÓHÐä�|Š|Ð2ÕEÀvÇxÁxÓP€HÜ�|Š|Ð2ÕEÈÈFÍ
Ç~Á~ÓV€HØÕ€DØ€Kr3   c                   ó€   a a€ ] tR tRt oRtRV3R lV 3R lllt]P                  ! 4       V3R lR l4       tRt	Vt
V ;t# )	ÚVideomtHungarianMatcheriÑ  aa  This class computes an assignment between the labels and the predictions of the network.

For efficiency reasons, the labels don't include the no_object. Because of this, in general, there are more
predictions than labels. In this case, we do a 1-to-1 matching of the best predictions, while the others are
un-matched (and thus treated as non-objects).
c                ó2   <€ V ^8„  d   QhRS[ RS[ RS[ RS[/# )r5   Ú
cost_classÚ	cost_maskÚ	cost_diceÚ
num_points)rÈ   r�   )r:   r;   s   "€r1   r<   Ú$VideomtHungarianMatcher.__annotate__Ù  s-   ø€ ÷ #ñ #Ùð#Ù27ð#ÙJOð#Ùcfñ#r3   c                ó”   <€ \         SV `  4        V^ 8X  d   V^ 8X  d   V^ 8X  d   \        R4      hW@n        Wn        W n        W0n        R# )aè  Creates the matcher

Params:
    cost_class (`float`, *optional*, defaults to 1.0):
        Relative weight of the classification error in the matching cost.
    cost_mask (`float`, *optional*,  defaults to 1.0):
        This is the relative weight of the focal loss of the binary mask in the matching cost.
    cost_dice (`float`, *optional*, defaults to 1.0):
        This is the relative weight of the dice loss of the binary mask in the matching cost.
    num_points (`int`, *optional*, defaults to 12544):
        No. of points to sample on which the mask loss will be calculated. The same set of K points are
        uniformly sampled for all prediction and ground truth masks to construct the cost matrix for bipartite
        matching.
zAll costs can't be 0N)r!   r"   rC   rw  rt  ru  rv  )r.   rt  ru  rv  rw  r0   s   &&&&&€r1   r"   Ú VideomtHungarianMatcher.__init__Ù  sC   ø€ ô" 	‰ÑÔØ˜Œ?˜y¨Aœ~°)¸q´.ÜÐ3Ó4Ð4à$ŒØ$ŒØ"ŒØ"Žr3   c                ó¨   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[ P                  RS[S[S[,          ,          /# )r5   rE  rD  Úmask_labelsÚclass_labelsr7   )r9   r   Úlistrè   )r:   r;   s   "€r1   r<   rx  ô  s]   ø€ ÷ Dñ Dá#Ÿl™lðDñ $Ÿl™lðDñ —\‘\ð	Dñ
 —l‘lðDñ 
‰e‘F�mÕ	ñDr3   c           
     ó  € . pVP                   ^ ,          p\        V4       EFü  pW',          P                  R4      pW,          p	VRWG,          3,          ) p
W7,          P                  V	4      pVR,          pV	R,          p	\        P
                  ! ^V P                  ^V	P                  R7      pVP                  VP                   ^ ,          ^^4      p\        W½RR7      P                  ^4      pVP                  V	P                   ^ ,          ^^4      p\        WžRR7      P                  ^4      p	\        W›4      p\        W›4      pV P                  V,          V P                  V
,          ,           V P                  V,          ,           p\        P                   ! V\        P"                  ! R4      4      p\        P$                  ! V\        P"                  ! R	4      4      p\        P&                  ! V^ 4      p\)        VP+                  4       4      pVP-                  V4       EKÿ  	  V UUu. uFR  w  pp\        P.                  ! V\        P0                  R7      \        P.                  ! V\        P0                  R7      3NKT  	  pppV# u uppi )
aß  
Params:
    masks_queries_logits (`torch.Tensor`):
        A tensor of dim `batch_size, num_queries, num_labels` with the classification logits.
    class_queries_logits (`torch.Tensor`):
        A tensor of dim `batch_size, num_queries, height, width` with the predicted masks.
    class_labels (`torch.Tensor`):
        A tensor of dim `num_target_boxes` (where num_target_boxes is the number of ground-truth objects in the
        target) containing the class labels.
    mask_labels (`torch.Tensor`):
        A tensor of dim `num_target_boxes, height, width` containing the target masks.

Returns:
    matched_indices (`list[tuple[Tensor]]`): A list of size batch_size, containing tuples of (index_i, index_j)
    where:
        - index_i is the indices of the selected predictions (in order)
        - index_j is the indices of the corresponding selected labels (in order)
    For each batch element, it holds:
        len(index_i) = len(index_j) = min(num_queries, num_target_boxes).
r[  ©ru   F©Úalign_cornersg    _ Br@   r]   rZ  g    _ Â)rB   ÚrangerÎ   rD   r9   r
  rw  ru   ÚrepeatrT  rQ  rp  ra  ru  rt  rv  ÚminimumÚtensorÚmaximumÚ
nan_to_numr   ÚcpuÚappendÚ	as_tensorÚint64)r.   rE  rD  r|  r}  Úindicesr~   ÚiÚ
pred_probsÚ	pred_maskrt  Útarget_maskrM  Útarget_coordinatesÚpred_coordinatesru  rv  Úcost_matrixÚassigned_indicesÚjÚmatched_indicess   &&&&&                r1   rI   ÚVideomtHungarianMatcher.forwardó  s  € ð8 *,ˆð *×/Ñ/°Õ2ˆ
Ü�z×"ˆAØ-Õ0×8Ñ8¸Ó<ˆJØ,Õ/ˆIð % Q¨­Ð%7Õ8Ð8ˆJØ%�.×+Ñ+¨IÓ6ˆKØ% gÕ.ˆKØ! 'Õ*ˆIô !&§
¢
¨1¨d¯o©o¸qÈ×IYÑIYÔ ZÐà!2×!9Ñ!9¸+×:KÑ:KÈAÕ:NÐPQÐSTÓ!UÐÜ& {ÐV[Ô\×dÑdÐefÓgˆKà0×7Ñ7¸	¿¹ÈÕ8JÈAÈqÓQÐÜ$ YÐPUÔV×^Ñ^Ð_`ÓaˆIô =¸YÓTˆIä+¨IÓCˆIàŸ.™.¨9Õ4°t·±ÈÕ7SÕSÐVZ×VdÑVdÐgpÕVpÕpˆKäŸ-š-¨´U·\²\À$Ó5GÓHˆKÜŸ-š-¨´U·\²\À%Ó5HÓIˆKÜ×*Ò*¨;¸Ó:ˆKä0EÀkÇoÁoÓFWÓ0XÐØ�N‰NÐ+×,ñ? #ñF hoô
ÙgnÑ_cÐ_`ÐbcŒU�_Š_˜Q¤e§k¡kÔ2´E·O²OÀAÌUÏ[É[Ô4YÓZÑgnð 	ñ 
ð Ðùó
s   È'AJ©rt  rv  ru  rw  )rO  rO  rO  i 1  )rL   rM   rN   rO   rP   r"   r9   Úno_gradrI   rQ   rR   rS   rT   s   @@r1   rr  rr  Ñ  s6   ù‡ € ñ÷#õ #ð4 ‡]‚]ƒ_÷Dó ÷Dð Dr3   rr  c                óH   € V ^8„  d   QhR\         R\         R\        R\         /# ©r5   rW  rX  Ú	num_masksr7   )r   r�   )r:   s   "r1   r<   r<   ;  s(   € ÷ ñ ”fð ¤fð ¼ð Äñ r3   c                ó8  € V P                  4       P                  ^4      p^W1,          P                  R4      ,          pVP                  R4      VP                  R4      ,           p^V^,           V^,           ,          ,
          pVP                  4       V,          pV# )aø  
Compute the DICE loss, similar to generalized IOU for masks as follows:

$$ \mathcal{L}_{\text{dice}(x, y) = 1 - \frac{2 * x \cap y }{x \cup y + 1}} $$

In practice, since `labels` is a binary mask, (only 0s and 1s), dice can be computed as follow

$$ \mathcal{L}_{\text{dice}(x, y) = 1 - \frac{2 * x * y }{x + y + 1}} $$

Args:
    inputs (`torch.Tensor`):
        A tensor representing a mask.
    labels (`torch.Tensor`):
        A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
        (0 for the negative class and 1 for the positive class).
    num_masks (`int`):
        The number of masks present in the current batch, used for normalization.

Returns:
    `torch.Tensor`: The computed loss.
r]   )r\  rF   r^  )rW  rX  r�  Úprobsr_  r`  rC  s   &&&    r1   Ú	dice_lossr   ;  sx   € ð, �N‰NÓ×$Ñ$ QÓ'€EØ�U•^×(Ñ(¨Ó,Õ,€IØ—)‘)˜B“- &§*¡*¨R£.Õ0€KØ�	˜A• +°¥/Õ2Õ2€DØ�8‰8‹:˜	Õ!€DØ€Kr3   c                ó„   € V ^8„  d   QhR\         P                  R\         P                  R\        R\         P                  /# rœ  )r9   r   r�   )r:   s   "r1   r<   r<   Y  s8   € ÷ ñ ¤u§|¡|ð ¼U¿\¹\ð ÔVYð Ô^c×^jÑ^jñ r3   c                ó�   € \         P                  ! RR7      pV! W4      pVP                  ^4      P                  4       V,          pV# )aX  
Args:
    inputs (`torch.Tensor`):
        A float tensor of arbitrary shape.
    labels (`torch.Tensor`):
        A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
        (0 for the negative class and 1 for the positive class).

Returns:
    loss (`torch.Tensor`): The computed loss.
rd  re  )r   rg  Úmeanr^  )rW  rX  r�  rk  Úcross_entropy_lossrC  s   &&&   r1   Úsigmoid_cross_entropy_lossr¥  Y  sB   € ô ×$Ò$¨vÔ6€IÙ" 6Ó2Ðà×"Ñ" 1Ó%×)Ñ)Ó+¨iÕ7€DØ€Kr3   c                   óÞ   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V3R lR ltV3R lR	 ltV3R
 lR ltR t	R t
V3R lR ltV3R lR ltRV3R lR lltV3R lR ltRtVtV ;t# )ÚVideomtLossim  c                ó<   <€ V ^8„  d   QhRS[ RS[S[S[3,          /# )r5   r/   Úweight_dict)r   Údictr”   rÈ   )r:   r;   s   "€r1   r<   ÚVideomtLoss.__annotate__n  s$   ø€ ÷ !
ñ !
™}ð !
¹4ÁÁUÀ
Õ;Kñ !
r3   c                ó  <€ \         SV `  4        \        V R.4       VP                  V n        W n        VP
                  V n        \        P                  ! V P                  ^,           4      pV P                  VR&   \        P                  ! V4      V n        VP                  V n        VP                  V n        VP                  V n        \!        VP"                  VP$                  VP&                  V P                  R7      V n        R# )a	  
The Videomt Loss. The loss is computed very similar to DETR. The process happens in two steps: 1) we
compute hungarian assignment between ground truth masks and the outputs of the model 2) we supervise each pair
of matched ground-truth / prediction (supervise class and mask)

Args:
    config (`VideomtConfig`):
        The configuration for Videomt model also containing loss calculation specific parameters.
    weight_dict (`dict[str, float]`):
        A dictionary of weights to be applied to the different losses.
Úscipyr™  Nr]   )r!   r"   r   Ú
num_labelsr©  Úno_object_weightÚeos_coefr9   r8  r   rk   Úempty_weightÚtrain_num_pointsrw  Úoversample_ratioÚimportance_sample_ratiorr  Úclass_weightÚdice_weightÚmask_weightÚmatcher)r.   r/   r©  r±  r0   s   &&& €r1   r"   ÚVideomtLoss.__init__n  sÍ   ø€ ô 	‰ÑÔÜ˜$  	Ô*Ø ×+Ñ+ˆŒØ&Ôð ×/Ñ/ˆŒÜ—z’z $§/¡/°AÕ"5Ó6ˆØŸ=™=ˆ�RÑÜŸIšI lÓ3ˆÔð !×1Ñ1ˆŒØ &× 7Ñ 7ˆÔØ'-×'EÑ'EˆÔ$ä.Ø×*Ñ*Ø×(Ñ(Ø×(Ñ(Ø—‘ô	
ˆŽr3   c                óV   <€ V ^8„  d   QhRS[ S[ S[,          ,          RS[ S[,          /# )r5   Úsizesr7   )r~  r�   )r:   r;   s   "€r1   r<   r«  ‘  s'   ø€ ÷ ñ ¡$¡t©C¥y¥/ð ±d¹3µiñ r3   c                óˆ   € V^ ,          pVR,           F+  p\        V4       F  w  rE\        W$,          V4      W$&   K  	  K-  	  V# )r   :r   NN)Ú	enumerateÚmax)r.   r»  ÚmaxesÚsublistÚindexÚitems   &&    r1   Ú_max_by_axisÚVideomtLoss._max_by_axis‘  sC   € Ø�a•ˆØ˜R—y�yˆGÜ(¨Ö1‘�Ü" 5¥<°Ó6�“ó  2ñ !ð ˆr3   c                óL   <€ V ^8„  d   QhRS[ S[,          RS[S[S[3,          /# )r5   Útensorsr7   )r~  r   rè   )r:   r;   s   "€r1   r<   r«  ™  s)   ø€ ÷ -ñ -±4¹µ<ð -ÁEÉ&ÑRXÈ.ÕDYñ -r3   c                ó¦  € T P                  V Uu. uF  p\        VP                  4      NK  	  up4      p\        V4      .V,           pVw  rVrxV^ ,          P                  p	V^ ,          P
                  p
\        P                  ! WIV
R7      p\        P                  ! WWV3\        P                  V
R7      p\        WV4       F‡  w  r-pVRVP                  ^ ,          1RVP                  ^,          1RVP                  ^,          13,          P                  V4       RVRVP                  ^,          1RVP                  ^,          13&   K‰  	  W¼3# u upi )r   r	  NF)rÃ  r~  rB   ÚlenrA   ru   r9   ra   r8  rz   ÚzipÚcopy_)r.   rÆ  r†  Úmax_sizeÚbatch_shaper~   r0  r€   r�   rA   ru   Úpadded_tensorsÚpadding_masksÚpadded_tensorÚpadding_masks   &&             r1   Ú_pad_images_to_max_in_batchÚ'VideomtLoss._pad_images_to_max_in_batch™  s'  € à×$Ñ$ÁwÓ%OÁw¸V¤d¨6¯<©<Ö&8ÁwÑ%OÓPˆä˜7“|�n xÕ/ˆØ'2Ñ$ˆ
�vØ˜•
× Ñ ˆØ˜•×"Ñ"ˆÜŸš [ÀfÔMˆÜŸ
š
 J¸Ð#>ÄeÇjÁjÐY_Ô`ˆä36°wÐP]Ö3^Ñ/ˆF <ØÐ+˜FŸL™L¨�OÐ+Ð->¨v¯|©|¸A­Ð->Ð@QÀ&Ç,Á,ÈqÅ/Ð@QÐQÕR×XÑXÐY_Ô`ØAFˆLÐ*˜6Ÿ<™<¨�?Ð*Ð,=¨f¯l©l¸1­oÐ,=Ð=Ó>ñ 4_ð Ð,Ð,ùò &Ps   �Ec          
      ó|   <€ V ^8„  d   QhRS[ RS[S[ ,          RS[S[P                  ,          RS[S[S[ 3,          /# )r5   rD  r}  r�  r7   )r   r~  rè   ÚnpÚarrayrª  r”   )r:   r;   s   "€r1   r<   r«  ª  sF   ø€ ÷  ñ  Ù$*ð Ù:>¹v½,ð ÙQVÑWY×W_ÑW_ÕQ`ð á	‰c‘6ˆkÕ	ñ r3   c           	     óÔ  € TpVP                   w  rVp\        P                  ! V P                  R7      pV P	                  V4      p	\
        P                  ! \        W#4       U
UUu. uF  w  p
w  r{W«,          NK  	  uppp
4      p\
        P                  ! WV3V P                  \
        P                  VP                  R7      pWÍV	&   VP                  ^^4      pV! Wí4      pRV/pV# u uppp
i )a-  Compute the losses related to the labels using cross entropy.

Args:
    class_queries_logits (`torch.Tensor`):
        A tensor of shape `batch_size, num_queries, num_labels`
    class_labels (`list[torch.Tensor]`):
        List of class labels of shape `(labels)`.
    indices (`tuple[np.array])`:
        The indices computed by the Hungarian matcher.

Returns:
    `dict[str, Tensor]`: A dict of `torch.Tensor` containing the following key:
    - **loss_cross_entropy** -- The loss computed using cross entropy on the predicted and ground truth labels.
)rE   )Ú
fill_valuerA   ru   Úloss_cross_entropy)rB   r   ÚCrossEntropyLossr±  Ú$_get_predictions_permutation_indicesr9   r}   rÉ  Úfullr®  rŒ  ru   rG   )r.   rD  r}  r�  Úpred_logitsr~   Únum_queriesr0  rk  ÚidxÚtargetr–  Útarget_classes_oÚtarget_classesÚpred_logits_transposedÚloss_ceÚlossess   &&&&             r1   Úloss_labelsÚVideomtLoss.loss_labelsª  sÙ   € ð" +ˆØ%0×%6Ñ%6Ñ"ˆ
 Ü×'Ò'¨t×/@Ñ/@ÔAˆ	Ø×7Ñ7¸Ó@ˆÜ Ÿ9š9Ü-0°Ô-GÕHÑ-G™>˜6¡6 AˆV�YˆYÑ-GÓHó
Ðô ŸšØÐ%°$·/±/ÌÏÉÐ]h×]oÑ]oô
ˆð /�sÑà!,×!6Ñ!6°q¸!Ó!<ÐÙÐ2ÓCˆØ&¨Ð0ˆØˆùô Is   Á#C#c                ó¾   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          RS[S[P
                  ,          RS[RS[S[S[ P                  3,          /# )r5   rE  r|  r�  r�  r7   )	r9   r   r~  rè   rÔ  rÕ  r�   rª  r”   )r:   r;   s   "€r1   r<   r«  Ì  s`   ø€ ÷ <ñ <á#Ÿl™lð<ñ ™%Ÿ,™,Õ'ð<ñ ‘r—x‘x•ð	<ñ
 ð<ñ 
‰c‘5—<‘<ÐÕ	 ñ<r3   c           	     óB  a € S P                  V4      pS P                  V4      pW,          pS P                  V4      w  r‰W†,          pVR,          pVR,          p\        P                  ! 4       ;_uu_ 4        S P                  VV 3R lS P                  S P                  S P                  4      p
\        WŠRR7      P                  ^4      pRRR4       \        VX
RR7      P                  ^4      pR\        VXV4      R\        WËV4      /p??V#   + '       g   i     LL; i)a$  Compute the losses related to the masks using sigmoid_cross_entropy_loss and dice loss.

Args:
    masks_queries_logits (`torch.Tensor`):
        A tensor of shape `(batch_size, num_queries, height, width)`.
    mask_labels (`torch.Tensor`):
        List of mask labels of shape `(labels, height, width)`.
    indices (`tuple[np.array])`:
        The indices computed by the Hungarian matcher.
    num_masks (`int)`:
        The number of masks, used for normalization.

Returns:
    losses (`dict[str, Tensor]`): A dict of `torch.Tensor` containing two keys:
    - **loss_mask** -- The loss computed using sigmoid cross entropy loss on the predicted and ground truth.
      masks.
    - **loss_dice** -- The loss computed using dice loss on the predicted on the predicted and ground truth,
      masks.
Nc                 ó&   <€ SP                  V 4      # r…   )Úcalculate_uncertainty)Úlogitsr.   s   &€r1   Ú<lambda>Ú(VideomtLoss.loss_masks.<locals>.<lambda>÷  s   ø€ ˜t×9Ñ9¸&ÔAr3   Fr�  Ú	loss_maskÚ	loss_dicerZ  )rÚ  Ú _get_targets_permutation_indicesrÑ  r9   rš  Úsample_points_using_uncertaintyrw  r³  r´  rT  rQ  r¥  r   )r.   rE  r|  r�  r�  Úsrc_idxÚtgt_idxÚ
pred_masksÚtarget_masksr0  rM  Úpoint_labelsÚpoint_logitsrä  s   f&&&&         r1   Ú
loss_masksÚVideomtLoss.loss_masksÌ  s  ø€ ð4 ×;Ñ;¸GÓDˆØ×7Ñ7¸Ó@ˆà)Õ2ˆ
ð ×:Ñ:¸;ÓG‰ˆØ#Õ,ˆð   Õ(ˆ
Ø# GÕ,ˆô �]Š]�_�_Ø $× DÑ DØÜAØ—‘Ø×%Ñ%Ø×,Ñ,ó!Ðô (¨ÐW\Ô]×eÑeÐfgÓhˆL÷ ô $ JÐ0AÐQVÔW×_Ñ_Ð`aÓbˆð Ô3°LÀ,ÐPYÓZØœ <¸yÓIð
ˆð
 ØØˆ÷) �_ús   Á6ADÄD	c                ó  € \         P                  ! \        V4       UUUu. uF  w  pw  r4\         P                  ! W24      NK   	  uppp4      p\         P                  ! V UUu. uF  w  r4VNK	  	  upp4      pWV3# u upppi u uppi r…   ©r9   r}   r½  Ú	full_like)r.   r�  rŽ  Úsrcr0  Úbatch_indicesÚpredictions_indicess   &&     r1   rÚ  Ú0VideomtLoss._get_predictions_permutation_indices
  sh   € äŸ	š	ÌiÐX_ÔN`Õ"aÑN`¹{¸qÁ(À3¤5§?¢?°3Ö#:ÑN`Ó"aÓbˆÜ#Ÿiši¹WÔ(E¹W±°#«¹WÒ(EÓFÐØÐ1Ð1ùô #bùÛ(Eó    $A:Á"B
c                ó  € \         P                  ! \        V4       UUUu. uF  w  pw  r4\         P                  ! WB4      NK   	  uppp4      p\         P                  ! V UUu. uF  w  r4VNK	  	  upp4      pWV3# u upppi u uppi r…   rû  )r.   r�  rŽ  r0  Útgtrþ  Útarget_indicess   &&     r1   rð  Ú,VideomtLoss._get_targets_permutation_indices  sg   € äŸ	š	ÌiÐX_ÔN`Õ"aÑN`¹{¸qÁ(À1¤5§?¢?°3Ö#:ÑN`Ó"aÓbˆÜŸš¹Ô#@¹©H¨Q£C¹Ò#@ÓAˆØÐ,Ð,ùô #bùÛ#@r  c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r5   rë  r7   r8   )r:   r;   s   "€r1   r<   r«    s#   ø€ ÷ "ñ "©E¯L©Lð "¹U¿\¹\ñ "r3   c                ó4   € \         P                  ! V4      ) pV# )a5  
In Videomt paper, uncertainty is estimated as L1 distance between 0.0 and the logit prediction in 'logits'
for the foreground class in `classes`.

Args:
    logits (`torch.Tensor`):
    A tensor of shape (R, 1, ...) for class-specific or class-agnostic, where R is the total number of predicted masks in all images and C is:
    the number of foreground classes. The values are logits.

Returns:
    scores (`torch.Tensor`): A tensor of shape (R, 1, ...) that contains uncertainty scores with the most
    uncertain locations having the highest uncertainty score.
)r9   Úabs)r.   rë  Úuncertainty_scoress   && r1   rê  Ú!VideomtLoss.calculate_uncertainty  s   € ô  %Ÿyšy¨Ó0Ð1ÐØ!Ð!r3   c          
      ó`   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[RS[ P                  /# )r5   rë  rw  r³  r´  r7   )r9   r   r�   rÈ   )r:   r;   s   "€r1   r<   r«  '  sE   ø€ ÷ 5!ñ 5!á—‘ð5!ñ ð	5!ñ
 ð5!ñ "'ð5!ñ 
�‰ñ5!r3   c           
     óÄ  € VP                   ^ ,          p\        W4,          4      p\        P                  ! Wg^VP                  R7      p\        WRR7      p	V! V	4      p
\        WS,          4      pW;,
          p\        P                  ! V
R,          V^R7      ^,          pV\        P                  ! V\        P                  VP                  R7      ,          pWÞR	,          ,          pVP                  R
^4      VP                  R
4      R3,          P                  Wk^4      pV^ 8”  d<   \        P                  ! V\        P                  ! Wl^VP                  R7      .^R7      pV# )að  
This function is meant for sampling points in [0, 1] * [0, 1] coordinate space based on their uncertainty. The
uncertainty is calculated for each point using the passed `uncertainty function` that takes points logit
prediction as input.

Args:
    logits (`float`):
        Logit predictions for P points.
    uncertainty_function:
        A function that takes logit predictions for P points and returns their uncertainties.
    num_points (`int`):
        The number of points P to sample.
    oversample_ratio (`int`):
        Oversampling parameter.
    importance_sample_ratio (`float`):
        Ratio of points that are sampled via importance sampling.

Returns:
    point_coordinates (`torch.Tensor`):
        Coordinates for P sampled points.
r€  Fr�  r[  )Úkrw   r	  rv   )r[  r   r[  rZ  r]   )rB   r�   r9   r
  ru   rT  Útopkrl   Úlongrì   r}   )r.   rë  Úuncertainty_functionrw  r³  r´  Ú	num_boxesÚnum_points_sampledrM  r÷  Úpoint_uncertaintiesÚnum_uncertain_pointsÚnum_random_pointsrÞ  Úshifts   &&&&&&         r1   rñ  Ú+VideomtLoss.sample_points_using_uncertainty'  s)  € ð< —L‘L •Oˆ	Ü  Õ!>Ó?Ðô "ŸJšJ yÀaÐPV×P]ÑP]Ô^Ðä# FÈUÔSˆá2°<Ó@Ðä"Ð#:Õ#GÓHÐØ&Õ=Ðä�jŠjÐ,¨WÕ5Ð9MÐSTÔUÐVWÕXˆØ"¤U§\¢\°)Ä5Ç:Á:ÐV\×VcÑVcÔ%dÕdˆØ�W�~ÕˆØ-×2Ñ2°2°qÓ9¸#¿(¹(À2»,È¸/ÕJ×OÑOÐPYÐqrÓsÐà˜qÔ Ü %§	¢	Ø"¤E§J¢J¨yÈQÐW]×WdÑWdÔ$eÐfØô!Ðð !Ð r3   c                ó  <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[S[ P                  ,          RS[S[ P                  ,          RS[S[S[ P                  3,          R,          RS[S[S[ P                  3,          /# )r5   rE  rD  r|  r}  Úauxiliary_predictionsNr7   )r9   r   r~  rª  r”   )r:   r;   s   "€r1   r<   r«  ^  s‚   ø€ ÷ 5ñ 5á#Ÿl™lð5ñ $Ÿl™lð5ñ ™%Ÿ,™,Õ'ð	5ñ
 ™5Ÿ<™<Õ(ð5ñ  $¡C©¯©Ð$5Õ6¸Õ=ð5ñ 
‰c‘5—<‘<ÐÕ	 ñ5r3   c                ó´  € V P                  WW44      pV P                  WD^ ,          P                  R7      p/ V P                  WWg4      CV P	                  W$V4      CpVes   \        V4       Fc  w  ršV
R,          pV
R,          pV P                  WW44      pVP                  4        UUu/ uF  w  rÍV RV	 2VbK  	  pppVP                  V4       Ke  	  V# u uppi )a  
This performs the loss computation.

Args:
    masks_queries_logits (`torch.Tensor`):
        A tensor of shape `(batch_size, num_queries, height, width)`.
    class_queries_logits (`torch.Tensor`):
        A tensor of shape `(batch_size, num_queries, num_labels)`.
    mask_labels (`torch.Tensor`):
        List of mask labels of shape `(labels, height, width)`.
    class_labels (`list[torch.Tensor]`):
        List of class labels of shape `(labels)`.
    auxiliary_predictions (`dict[str, torch.Tensor]`, *optional*):
        if `use_auxiliary_loss` was set to `true` in [`VideomtConfig`], then it contains the logits from
        the inner layers of the VideomtMaskedAttentionDecoder.

Returns:
    losses (`dict[str, Tensor]`): A dict of `torch.Tensor` containing three keys:
    - **loss_cross_entropy** -- The loss computed using cross entropy on the predicted and ground truth labels.
    - **loss_mask** -- The loss computed using sigmoid cross_entropy loss on the predicted and ground truth
      masks.
    - **loss_dice** -- The loss computed using dice loss on the predicted on the predicted and ground truth
      masks.
    if `use_auxiliary_loss` was set to `true` in [`VideomtConfig`], the dictionary contains additional
    losses for each auxiliary predictions.
r€  rE  rD  r0  )	r¸  Úget_num_masksru   rø  rå  r½  rI   ÚitemsÚupdate)r.   rE  rD  r|  r}  r  r�  r�  rä  rÞ  Úaux_outputsÚ	loss_dictrÃ   rÄ   s   &&&&&&        r1   rI   ÚVideomtLoss.forward^  sñ   € ðH —,‘,Ð3È;Óeˆà×&Ñ& |È½O×<RÑ<RÐ&ÓSˆ	ð%
Ø�o‰oÐ2ÀÓTð%
à×ÑÐ3À7ÓKð%
ˆð
 !Ò,Ü$-Ð.CÖ$DÑ �Ø'2Ð3IÕ'JÐ$Ø'2Ð3IÕ'JÐ$Ø ŸL™LÐ)=ÐU`Óo�	ØENÇ_Á_ÔEVÔWÑEV±z°s ˜u A c U˜^¨UÒ2ÑEV�	ÑWØ—‘˜iÖ(ñ %Eð ˆùó Xs   Â'Cc                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# )r5   r}  ru   r7   )r9   r   ru   )r:   r;   s   "€r1   r<   r«  •  s1   ø€ ÷ ñ ©%¯,©,ð ÁÇÁð ÑQV×Q]ÑQ]ñ r3   c                ó@  € \        R V 4       4      p\        P                  ! V\        P                  VR7      p^p\	        4       '       d5   \
        P                  / 8w  d    \        V4      p\        4       P                  p\        P                  ! W4,          ^R7      pV# )z[
Computes the average number of target masks across the batch, for normalization purposes.
c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir…   )rÈ  )Ú.0Úclassess   & r1   Ú	<genexpr>Ú,VideomtLoss.get_num_masks.<locals>.<genexpr>™  s   é € ÐA±L¨œ˜GŸ˜³Lùs   ‚r	  )Úmin)
r^  r9   r‹  rÈ   r   r   Ú_shared_stater   Únum_processesÚclamp)r.   r}  ru   r�  Ú
world_sizes   &&&  r1   r  ÚVideomtLoss.get_num_masks•  sv   € ô ÑA±LÓAÓAˆ	Ü—O’O I´U·[±[ÈÔPˆ	Øˆ
Ü"×$Ò$Ü×)Ñ)¨RÔ/Ü" 9Ó-�	Ü)›^×9Ñ9�
ä—K’K 	Õ 6¸AÔ>ˆ	ØÐr3   )r±  r°  r´  r¸  r®  rw  r³  r©  r…   )rL   rM   rN   rO   r"   rÃ  rÑ  rå  rø  rÚ  rð  rê  rñ  rI   r  rQ   rR   rS   rT   s   @@r1   r§  r§  m  ss   ù‡ € ÷!
ó !
÷Fð ÷-ð -÷" ð  ÷D<ð <ò|2ò-÷"ð "÷"5!ð 5!÷n5ò 5÷n÷ ð r3   r§  c                   óœ   a a€ ] tR tRt oRtRtRtRtRtR.t	Rt
R]R	]/t]P                  ! 4       V3R
 lV 3R ll4       tV3R ltRtVtV ;t# )ÚVideomtPreTrainedModeli¥  zz
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
ÚvideomtÚpixel_values_videosFr  Trç   rG  c                ó8   <€ V ^8„  d   QhRS[ P                  RR/# )r5   rÁ   r7   N)r   rÇ   )r:   r;   s   "€r1   r<   Ú#VideomtPreTrainedModel.__annotate__¹  s   ø€ ÷ .ñ .¡B§I¡Ið .°$ñ .r3   c                ó”  <€ \         SV `  V4       V P                  P                  p\	        V\
        P                  \
        P                  \
        P                  34      '       dÅ   \        P                  ! VP                  \        P                  ! ^4      R7       VP                  e   \        P
                  P                  P!                  VP                  4      w  r4V^ 8”  d   ^\        P                  ! V4      ,          M^ p\        P"                  ! VP                  V) V4       EM]\	        V\
        P$                  4      '       d‚   \        P&                  ! VP                  R^R7       VP(                  eO   \+        VP                  RR4      '       g2   \        P,                  ! VP                  VP(                  ,          4       EM¼\	        V\.        4      '       dJ   \1        VR4      '       d6   \        P2                  ! VP4                  V P                  P6                  4       EM]\	        V\8        4      '       d¤   \        P:                  ! VP<                  RVR7       \        P,                  ! VP>                  4       \        P@                  ! VPB                  \        PD                  ! VPB                  PF                  R,          4      PI                  R	4      4       M¤\	        V\J        4      '       dY   \        PL                  ! VPN                  ^,           4      pVPP                  VR&   \        P@                  ! VPR                  V4       M6\	        V\T        4      '       d!   \        PV                  ! VPX                  4       \	        V\8        4      '       d,   \
        P                  P-                  VPZ                  4       R# R# )
rt   )ÚaNrë   )r£  ÚstdÚ_is_hf_initializedFr9  r]   r\   ).r!   Ú_init_weightsr/   Úinitializer_ranger'   r   r‘   r,   ÚConvTranspose2dÚinitÚkaiming_uniform_rE   ÚmathÚsqrtrŽ   r9   Ú_calculate_fan_in_and_fan_outÚuniform_ri   Únormal_Úpadding_idxÚgetattrÚzeros_r"  ÚhasattrÚ	constant_r9  r7  rV   Útrunc_normal_r`   rc   rÊ  rn   rl   rB   rm   r§  r8  r®  r°  r±  ÚVideomtForUniversalSegmentationÚones_Úattn_mask_probsro   )r.   rÁ   r6  Úfan_inr0  Úboundr±  r0   s   &&     €r1   r8  Ú$VideomtPreTrainedModel._init_weights¸  sT  ø€ ä‰Ñ˜fÔ%Ø�k‰k×+Ñ+ˆÜ�fœrŸy™y¬"¯)©)´R×5GÑ5GÐH×IÒIÜ×!Ò! &§-¡-´4·9²9¸Q³<Õ@Ø�{‰{Ò&Ü!ŸH™HŸM™M×GÑGÈÏÉÓV‘	�Ø17¸!´˜œDŸIšI fÓ-Ö-À�Ü—’˜fŸk™k¨E¨6°5Ô9ùÜ˜¤§¡×-Ò-Ü�LŠL˜Ÿ™¨S°aÕ8à×!Ñ!Ò-´g¸f¿m¹mÐMaÐch×6iÒ6iÜ—’˜FŸM™M¨&×*<Ñ*<Õ=Ô>ùÜ˜Ô 1×2Ò2Ü�v˜y×)Ò)Ü—’˜vŸ~™~¨t¯{©{×/KÑ/KÔLùÜ˜Ô 1×2Ò2Ü×Ò˜v×/Ñ/°c¸sÕCÜ�KŠK˜×.Ñ.Ô/Ü�JŠJ�v×*Ñ*¬E¯LªL¸×9LÑ9L×9RÑ9RÐSUÕ9VÓ,W×,^Ñ,^Ð_fÓ,gÕhÜ˜¤×,Ò,Ü Ÿ:š: f×&7Ñ&7¸!Õ&;Ó<ˆLØ%Ÿ™ˆL˜ÑÜ�JŠJ�v×*Ñ*¨LÕ9Ü˜Ô ?×@Ò@Ü�JŠJ�v×-Ñ-Ô.Ü�fÔ/×0Ò0Ü�G‰G�N‰N˜6×,Ñ,Ö-ñ 1r3   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # ©r5   r/   r   )r:   r;   s   "€r1   r<   r3  ¥  s   ø‡ ‚ ñ Ñò r3   rŠ   )Úvideo)rL   rM   rN   rO   rP   Úbase_model_prefixÚmain_input_nameÚinput_modalitiesÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_supports_sdpar  rÖ   Ú_can_record_outputsr9   rš  r8  rJ  rQ   rR   rS   rT   s   @@r1   r/  r/  ¥  sj   ù‡ € ñð "ÐØ+€OØ!ÐØ&+Ð#Ø'Ð(ÐØ€Nà˜ØÐ&ðÐð
 ‡]‚]ƒ_÷.ò .ó ð.÷) … r3   r/  c                   óH   a a€ ] tR tRt oRV 3R lltV3R lR ltRtVtV ;t# )ÚVideomtLayerNorm2diØ  c                ó*   <€ \         SV `  WVR 7       R# ))r  Úelementwise_affineN)r!   r"   )r.   r%   r  Úaffiner0   s   &&&&€r1   r"   ÚVideomtLayerNorm2d.__init__Ù  s   ø€ Ü‰Ñ˜À6ÐÖJr3   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r�   r8   )r:   r;   s   "€r1   r<   ÚVideomtLayerNorm2d.__annotate__Ü  rŸ   r3   c                óØ   € VP                  ^ ^^^4      p\        P                  ! WP                  V P                  V P
                  V P                  4      pVP                  ^ ^^^4      pV# )r   )ÚpermuteÚFÚ
layer_normÚnormalized_shaperE   rŽ   r  r¡   s   &&r1   rI   ÚVideomtLayerNorm2d.forwardÜ  s`   € Ø#×+Ñ+¨A¨q°!°QÓ7ˆÜ—|’| L×2GÑ2GÈÏÉÐVZ×V_ÑV_Ðae×aiÑaiÓjˆØ#×+Ñ+¨A¨q°!°QÓ7ˆØÐr3   rŠ   )g�íµ ÷Æ°>Tr£   rT   s   @@r1   rY  rY  Ø  s   ù‡ € ÷K÷÷ ð r3   rY  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# )ÚVideomtScaleLayeriã  c                ó    <€ V ^8„  d   QhRS[ /# rO  r   )r:   r;   s   "€r1   r<   ÚVideomtScaleLayer.__annotate__ä  s   ø€ ÷ ;ñ ;™}ñ ;r3   c           	     ó  <€ \         SV `  4        VP                  p\        P                  ! W"^^R7      V n        \        VP                  ,          V n        \        P                  ! VV^^VRR7      V n
        \        V4      V n        R# )r5   r   F)r   ÚpaddingÚgroupsrŽ   N)r!   r"   r&   r   r:  Úconv1r   r“   r•   r,   Úconv2rY  Úlayernorm2d©r.   r/   r&   r0   s   && €r1   r"   ÚVideomtScaleLayer.__init__ä  ss   ø€ Ü‰ÑÔØ×(Ñ(ˆÜ×'Ò'¨ÈaÐXYÔZˆŒ
Ü  ×!2Ñ!2Õ3ˆŒÜ—Y’YØØØØØØô
ˆŒ
ô .¨kÓ:ˆÖr3   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r  r8   )r:   r;   s   "€r1   r<   ri  ô  s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r3   c                óŽ   € V P                  V4      pV P                  V4      pV P                  V4      pV P                  V4      pV# r…   )rm  r•   rn  ro  ©r.   rç   s   &&r1   rI   ÚVideomtScaleLayer.forwardô  sB   € ØŸ
™
 =Ó1ˆØŸ™¨Ó6ˆØŸ
™
 =Ó1ˆØ×(Ñ(¨Ó7ˆØÐr3   )r•   rm  rn  ro  r£   rT   s   @@r1   rg  rg  ã  s   ù‡ € ÷;ó ;÷ ÷ ð r3   rg  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# )ÚVideomtScaleBlockiü  c                ó    <€ V ^8„  d   QhRS[ /# rO  r   )r:   r;   s   "€r1   r<   ÚVideomtScaleBlock.__annotate__ý  s   ø€ ÷ `ñ `™}ñ `r3   c                óÞ   <€ \         SV `  4        VP                  V n        \        P
                  ! \        V P                  4       Uu. uF  p\        V4      NK  	  up4      V n        R # u upi r…   )	r!   r"   Únum_upscale_blocksÚ
num_blocksr   Ú
ModuleListrƒ  rg  Úblock©r.   r/   r0  r0   s   && €r1   r"   ÚVideomtScaleBlock.__init__ý  sN   ø€ Ü‰ÑÔØ ×3Ñ3ˆŒÜ—]’]ÄuÈTÏ_É_ÔG]Ó#^ÑG]À!Ô$5°fÖ$=ÑG]Ñ#^Ó_ˆŽ
ùÒ#^s   ÁA*c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r  r8   )r:   r;   s   "€r1   r<   ry    s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r3   c                ó<   € V P                    F  pV! V4      pK  	  V# r…   )r~  )r.   rç   r~  s   && r1   rI   ÚVideomtScaleBlock.forward  s    € Ø—Z”ZˆEÙ! -Ó0ŠMñ  àÐr3   )r~  r|  r£   rT   s   @@r1   rw  rw  ü  s    ù‡ € ÷`ó `÷
÷ ð r3   rw  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# )ÚVideomtMaskHeadi  c                ó    <€ V ^8„  d   QhRS[ /# rO  r   )r:   r;   s   "€r1   r<   ÚVideomtMaskHead.__annotate__	  s   ø€ ÷ 4ñ 4™}ñ 4r3   c                ó  <€ \         SV `  4        VP                  p\        P                  ! W"4      V n        \        P                  ! W"4      V n        \        P                  ! W"4      V n        \        VP                  ,          V n
        R # r…   )r!   r"   r&   r   r‘   r’   r–   Úfc3r   r“   r•   rp  s   && €r1   r"   ÚVideomtMaskHead.__init__	  s[   ø€ Ü‰ÑÔà×(Ñ(ˆÜ—9’9˜[Ó6ˆŒÜ—9’9˜[Ó6ˆŒÜ—9’9˜[Ó6ˆŒÜ  ×!2Ñ!2Õ3ˆŽr3   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r  r8   )r:   r;   s   "€r1   r<   r‡    s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r3   c                ó¨   € V P                  V P                  V4      4      pV P                  V P                  V4      4      pV P                  V4      pV# r…   ©r•   r’   r–   r‰  rt  s   &&r1   rI   ÚVideomtMaskHead.forward  sD   € ØŸ™¨¯©°Ó(?Ó@ˆØŸ™¨¯©°Ó(?Ó@ˆØŸ™ Ó/ˆØÐr3   r�  r£   rT   s   @@r1   r…  r…    s   ù‡ € ÷4ó 4÷÷ ð r3   r…  zY
    The Videomt Model with head on top for instance/semantic/panoptic segmentation.
    c                   ó²   a a€ ] tR tRt oRtV3R lV 3R lltV3R lR ltV3R lR lt]]	]
RV3R	 lR
 ll4       4       4       tR tV3R lR ltRtVtV ;t# )rH  i  r1  c                ó    <€ V ^8„  d   QhRS[ /# rO  r   )r:   r;   s   "€r1   r<   Ú,VideomtForUniversalSegmentation.__annotate__!  s   ø€ ÷ ñ ™}ñ r3   c                óx  <€ \         SV `  V4       Wn        VP                  V n        \	        V4      V n        \        P                  ! VP                  VP                  R 7      V n
        \        P                  ! VP                  VP                  4      V n        \        P                  ! \        VP                  4       Uu. uF  p\!        V4      NK  	  up4      V n        \%        V4      V n        \)        V4      V n        \        P,                  ! VP                  VP.                  ^,           4      V n        VP2                  VP4                  ,          VP2                  VP4                  ,          3V n        RVP8                  RVP:                  RVP<                  /V n        \A        WP>                  R7      V n!        \        PD                  ! \F        PH                  ! VPJ                  4      4      V n&        \        P,                  ! VP                  VP                  4      V n'        V PQ                  4        R# u upi )r  rØ  rî  rï  )r/   r©  N))r!   r"   r/   Únum_hidden_layersrV   rH   r   r  r&   r  Ú	layernormri   rÝ  rÂ   r}  rƒ  r  Úlayersrw  Úupscale_blockr…  Ú	mask_headr‘   r®  Úclass_predictorr#   r$   Ú	grid_sizerµ  r·  r¶  r©  r§  rk  rk   r9   r8  r|  rJ  Úquery_updaterÚ	post_initr  s   && €r1   r"   Ú(VideomtForUniversalSegmentation.__init__!  s—  ø€ Ü‰Ñ˜Ô ØŒØ!'×!9Ñ!9ˆÔÜ+¨FÓ3ˆŒÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒä—\’\ &×"4Ñ"4°f×6HÑ6HÓIˆŒ
Ü—m’mÄ5È×IaÑIaÔCbÓ$cÑCb¸a¤\°&Ö%9ÑCbÑ$cÓdˆŒä.¨vÓ6ˆÔÜ(¨Ó0ˆŒä!Ÿyšy¨×);Ñ);¸V×=NÑ=NÐQRÕ=RÓSˆÔà ×+Ñ+¨v×/@Ñ/@Õ@À&×BSÑBSÐW]×WhÑWhÕBhÐiˆŒà  &×"5Ñ"5Ø˜×+Ñ+Ø˜×+Ñ+ð.
ˆÔô %¨F×@PÑ@PÔQˆŒä!Ÿyšy¬¯ª°F×4EÑ4EÓ)FÓGˆÔÜŸYšY v×'9Ñ'9¸6×;MÑ;MÓNˆÔà�‰Öùò' %ds   Ã H7c                ój   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[S[S[ 3,          RS[S[S[ 3,          /# )r5   rE  rD  r|  r}  r  r7   )r   rª  r”   )r:   r;   s   "€r1   r<   r‘  >  sY   ø€ ÷ ñ á$ðñ %ðñ ð	ñ
 ðñ  $¡C© KÕ0ðñ 
‰c‘6ˆkÕ	ñr3   c                óÊ   € V P                  VVVVVR 7      pV P                  P                  4        F.  w  rxVP                  4        F  w  ršWy9   g   K  W¨,          p
K  	  K0  	  V# ))rE  rD  r|  r}  r  )rk  r©  r  )r.   rE  rD  r|  r}  r  r  rÃ   rE   Úloss_keyrC  s   &&&&&&     r1   Úget_loss_dictÚ-VideomtForUniversalSegmentation.get_loss_dict>  sj   € ð (,§~¡~Ø!5Ø!5Ø#Ø%Ø"7ð (6ó (
ˆ	ð  ×+Ñ+×1Ñ1Ö3‰KˆCØ"+§/¡/Ö"3‘�Ø–?Ø•N’Dó #4ñ 4ð
 Ðr3   c                ó<   <€ V ^8„  d   QhRS[ S[S[3,          RS[/# )r5   r  r7   )rª  r”   r   )r:   r;   s   "€r1   r<   r‘  V  s$   ø€ ÷ 'ñ '¡$¡s©F {Õ"3ð '¹ñ 'r3   c                ó4   € \        VP                  4       4      # r…   )r^  ró   )r.   r  s   &&r1   Úget_lossÚ(VideomtForUniversalSegmentation.get_lossV  s   € Ü�9×#Ñ#Ó%Ó&Ð&r3   c                ó  <€ V ^8„  d   QhRS[ P                  R,          RS[S[ P                  ,          R,          RS[S[ P                  ,          R,          RS[S[ P                  ,          R,          RS[S[,          RS[/# )r5   r1  Nr|  r}  Úpatch_offsetsrÑ   r7   )r9   r   r~  r   r   rA  )r:   r;   s   "€r1   r<   r‘  \  sˆ   ø€ ÷ O
ñ O
á"Ÿ\™\¨DÕ0ðO
ñ ™%Ÿ,™,Õ'¨$Õ.ðO
ñ ™5Ÿ<™<Õ(¨4Õ/ð	O
ñ
 ™EŸL™LÕ)¨DÕ0ðO
ñ Ñ+Õ,ðO
ñ 
/ñO
r3   c           
     óÀ  € RV9   d   \        R4      hVf   \        R4      hVP                  ^8w  d   \        R4      hVf   Ve   \        R4      hVP                  w  rgr‰p
VP                  Wg,          W‰V
4      pV P	                  V4      pV P
                  V P                  P                  ,
          pV P                  RV  F  pV! V4      pK  	  VP                  WgVP                  ^,          VP                  ^,          4      p. p. p. pRp\        V4       EFr  pVRV3,          pVfI   V P                  P                  R
,          P                  VRR4      P                  VP                  4      pMeV P!                  V4      P                  VP                  4      V P                  P                  R
,          P                  VP                  4      ,           p\"        P$                  ! VV3^R7      pV P                  VR  F  pV! V4      pK  	  V P'                  V4      pV P)                  V4      w  ppVP+                  V4       VP+                  V4       VP+                  V4       VRRV P                  P,                  1R3,          pEKu  	  \/        R\"        P$                  ! V^ R7      \"        P$                  ! V^ R7      \"        P$                  ! V^ R7      R	7      # )a°  
pixel_values_videos (`torch.Tensor`, *optional*):
    Video inputs of shape `(batch_size, num_frames, num_channels, height, width)`.
mask_labels (`list[torch.Tensor]`, *optional*):
    Not supported for 5D video inputs.
class_labels (`list[torch.LongTensor]`, *optional*):
    Not supported for 5D video inputs.
patch_offsets (`list[torch.Tensor]`, *optional*):
    Unused for video inputs and only kept for modular compatibility.
r6   zAUse `pixel_values_videos` with `VideomtForUniversalSegmentation`.Nz'You have to specify pixel_values_videoszyVideomtForUniversalSegmentation only supports 5D video inputs of shape (batch_size, num_frames, channels, height, width).z“Training with 5D video inputs is not supported in `VideomtForUniversalSegmentation`. Flatten frames and use `EomtForUniversalSegmentation` instead.r[  rv   )rC  rE  rD  rF  )Nr[  r[  r]   )rC   rx   rB   ry   rH   r“  r/   r|  r•  rì   rƒ  rÂ   rE   rm   rD   ru   rš  r9   r}   r”  ÚpredictrŠ  rÝ  rA  )r.   r1  r|  r}  r§  rÑ   r~   r   r%   r€   r�   Úflat_pixel_valuesrç   Úquery_start_idxÚlayer_moduleÚall_masks_queries_logitsÚall_class_queries_logitsÚall_last_hidden_statesÚpropagated_queryÚ	frame_idxÚframe_hidden_statesÚquery_tokensÚsequence_outputrE  rD  s   &&&&&,                   r1   rI   Ú'VideomtForUniversalSegmentation.forwardY  sÆ  € ð* ˜VÔ#ÜÐ`ÓaÐaàÒ&ÜÐFÓGÐGà×#Ñ# qÔ(ÜðEóð ð
 Ò" lÒ&>ÜðQóð ð
 ?R×>WÑ>WÑ;ˆ
 °eØ/×7Ñ7¸
Õ8OÐQ]ÐglÓmÐàŸ™Ð(9Ó:ˆØ×0Ñ0°4·;±;×3IÑ3IÕIˆà ŸK™KÐ(8¨Ó9ˆLÙ(¨Ó7ŠMñ :ð &×*Ñ*¨:À=×CVÑCVÐWXÕCYÐ[h×[nÑ[nÐopÕ[qÓrˆà#%Ð Ø#%Ð Ø!#ÐØÐä˜z×*ˆIØ"/°°9°Õ"=ÐàÒ'Ø#Ÿz™z×0Ñ0°Õ<×CÑCÀJÐPRÐTVÓW×ZÑZÐ[n×[uÑ[uÓv‘à#×1Ñ1Ð2BÓC×FÑFÐGZ×GaÑGaÓbÐei×eoÑeo×evÑevØõfç‘"Ð(×/Ñ/Ó0õ 1�ô #(§)¢)¨\Ð;NÐ,OÐUVÔ"WÐà $§¡¨OÐ,<Ó =�Ù&2Ð3FÓ&GÒ#ñ !>ð #Ÿn™nÐ-@ÓAˆOØ9=¿¹ÀoÓ9VÑ6Ð Ð"6à$×+Ñ+Ð,@ÔAØ$×+Ñ+Ð,@ÔAØ"×)Ñ)¨/Ô:Ø2°1Ð6O¸¿¹×8OÑ8OÐ6OÐQRÐ3RÕSÓñ) +ô, 5ØÜ!&§¢Ð+CÈÔ!KÜ!&§¢Ð+CÈÔ!KÜ#ŸišiÐ(>ÀAÔFô	
ð 	
r3   c                ó.   € V P                   P                  # r…   )rH   rd   r  s   &r1   Úget_input_embeddingsÚ4VideomtForUniversalSegmentation.get_input_embeddings­  s   € Ø�‰×/Ñ/Ð/r3   c                ó4   <€ V ^8„  d   QhRS[ P                  /# )r5   rë  r8   )r:   r;   s   "€r1   r<   r‘  °  s   ø€ ÷ )ñ )™eŸl™lñ )r3   c                óÞ  € VR RV P                   P                  1R 3,          pV P                  V4      pVR V P                   P                  V P                  P                  ,           R1R 3,          pVP                  ^^4      pVP                  ! VP                  ^ ,          R.V P                  O5!  pV P                  V4      pV P                  V4      p\        P                  ! RW$4      pWS3# )r[  Nzbqc, bchw -> bqhwr]   )r/   rÝ  r˜  rH   rh   rG   ry   rB   r™  r—  r–  r9   Úeinsum)r.   rë  r³  Úclass_logitsÚprefix_tokensÚmask_logitss   &&    r1   r©  Ú'VideomtForUniversalSegmentation.predict°  sÑ   € Ø˜aÐ!: 4§;¡;×#:Ñ#:Ð!:¸AÐ=Õ>ˆØ×+Ñ+¨LÓ9ˆà˜q $§+¡+×"9Ñ"9¸D¿O¹O×<]Ñ<]Õ"]Ñ"_ÐabÐbÕcˆØ%×/Ñ/°°1Ó5ˆà%×-Ò-¨m×.AÑ.AÀ!Õ.DÀbÐZÈ4Ï>É>ÓZˆà—~‘~ lÓ3ˆØ×*Ñ*¨=Ó9ˆä—l’lÐ#6¸ÓTˆàÐ(Ð(r3   )rJ  r˜  r/   rk  rH   r™  r”  r•  r—  r“  rÂ   rš  r–  r©  )NNNN)rL   rM   rN   rO   rR  r"   r   r¤  r   r   r   rI   r·  r©  rQ   rR   rS   rT   s   @@r1   rH  rH    sk   ù‡ € ð ,€O÷ó ÷:ð ÷0'ð 'ð  ØØ÷O
ñ O
ó ó ó  ðO
òb0÷)÷ )ð )r3   rH  r  )F)IÚcollections.abcr(   r=  r   Údataclassesr   ÚnumpyrÔ  r9   Útorch.nn.functionalr   r¶   rb  r   Ú r   r;  Úactivationsr   Ú
file_utilsr	   r
   r   Úmodeling_layersr   Úmodeling_utilsr   r   Úprocessing_utilsr   Úutilsr   r   r   Úutils.genericr   Úutils.output_capturingr   Úconfiguration_videomtr   Úscipy.optimizer   Ú
accelerater   Úaccelerate.utilsr   rÇ   r   rV   r‡   r¥   rÔ   rÖ   r÷   r   r  r"  rA  rT  ra  rp  rr  r   r¥  r§  r/  r  rY  rg  rw  r…  rH  Ú__all__rŠ   r3   r1   Ú<module>rÒ     sû  ðó* Û Ý $Ý !ã Û ß Ð ß å &Ý !ß LÑ LÝ 9ß FÝ &ß PÑ PÝ 7Ý 5Ý 0ñ ×ÒÝ4á×ÒÝ'Ý'ô ˜RŸY™Yô  ôF,˜Ÿ	™	ô ,ô^�—‘ô ô&(�b—i‘iô (÷"%ô.8)�r—y‘yô 8)ôv(�r—y‘yô (ô"%�b—i‘iô %ô0'Ð-ô 'ôT+˜Ÿ	™	ô +ñ ðô	ð ô7¨Kó 7ó ó	ð7÷:õ@õ,ô8g˜bŸi™iô gõTõ<ô(u�"—)‘)ô uðp	 ô/.˜_ó /.ó ð/.ôd˜Ÿ™ô ô˜Ÿ	™	ô ô2	˜Ÿ	™	ô 	ô�b—i‘iô ñ" ðôô
`)Ð&<ó `)óð
`)ðF $Ð%FÐ
G‚r3   