+
    œ°³js  ã                   ó  € ^ RI t ^ RIHt ^ RIHt ^RI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HtHtHt  ! R	 R
]4      t] ! R R]4      4       t ! R R]]4      t]! RR7       ! R R]]4      4       t. ROtR# )é    N©ÚIJepaConfig)Úinitialization)ÚBaseModelOutputWithPoolingÚImageClassifierOutput)ÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚ	torch_int)ÚViTEmbeddingsÚViTForImageClassificationÚViTModelÚViTPreTrainedModelc                   ój   a a€ ] tR t^t oRV3R lV 3R l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	# )
ÚIJepaEmbeddingsc                ó*   <€ V ^8„  d   QhRS[ RS[RR/# )é   ÚconfigÚuse_mask_tokenÚreturnN©r   Úbool)ÚformatÚ__classdict__s   "€Úh/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/ijepa/modular_ijepa.pyÚ__annotate__ÚIJepaEmbeddings.__annotate__   s'   ø€ ÷ añ a™{ð a¹Dð aÈTñ aó    c                óÊ   <€ \         SV `  W4       V =V P                  P                  p\
        P                  ! \        P                  ! ^W1P                  4      4      V n
        R# )é   N)ÚsuperÚ__init__Ú	cls_tokenÚpatch_embeddingsÚnum_patchesÚnnÚ	ParameterÚtorchÚrandnÚhidden_sizeÚposition_embeddings)Úselfr   r   r&   Ú	__class__s   &&& €r   r#   ÚIJepaEmbeddings.__init__   sH   ø€ Ü‰Ñ˜Ô0àˆNØ×+Ñ+×7Ñ7ˆÜ#%§<¢<´·²¸A¸{×L^ÑL^Ó0_Ó#`ˆÖ r   c                óZ   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[ P                  /# )r   Ú
embeddingsÚheightÚwidthr   )r)   ÚTensorÚint)r   r   s   "€r   r   r      s5   ø€ ÷ %ñ %±5·<±<ð %Éð %ÑUXð %Ñ]b×]iÑ]iñ %r   c                óh  € VP                   ^,          pV P                  P                   ^,          p\        P                  P	                  4       '       g   WE8X  d   W#8X  d   V P                  # V P                  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V# )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éÿÿÿÿ)Úshaper,   r)   ÚjitÚ
is_tracingÚ
patch_sizer   ÚreshapeÚpermuter'   Ú
functionalÚinterpolateÚview)r-   r1   r2   r3   r&   Únum_positionsÚpatch_pos_embedÚdimÚ
new_heightÚ	new_widthÚsqrt_num_positionss   &&&&       r   Úinterpolate_pos_encodingÚ(IJepaEmbeddings.interpolate_pos_encoding   s  € ð !×&Ñ& qÕ)ˆØ×0Ñ0×6Ñ6°qÕ9ˆô �y‰y×#Ñ#×%Ò%¨+Ô*FÈ6Ì?Ø×+Ñ+Ð+à×2Ñ2ˆà×Ñ˜rÕ"ˆàŸ™Õ.ˆ
ØŸ_™_Õ,ˆ	ä& }°cÕ'9Ó:ÐØ)×1Ñ1°!Ð5GÐ]`ÓaˆØ)×1Ñ1°!°Q¸¸1Ó=ˆäŸ-™-×3Ñ3ØØÐ(ØØð	 4ó 
ˆð *×1Ñ1°!°Q¸¸1Ó=×BÑBÀ1ÀbÈ#ÓNˆàÐr   c                ó|   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[RS[ P                  /# )r   Úpixel_valuesÚbool_masked_posNrK   r   )r)   r4   Ú
BoolTensorr   )r   r   s   "€r   r   r   =   sF   ø€ ÷ ñ á—l‘lðñ ×)Ñ)¨DÕ0ðñ #'ð	ñ
 
�‰ñr   c                ó~  € VP                   w  rErgV P                  V4      pVem   VP                   ^,          p	V P                  P                  WIR4      p
VP	                  R4      P                  V
4      pVRV,
          ,          W«,          ,           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# )Ng      ð?zInput image size (Ú*z) doesn't match model (z).r;   )r<   r%   Ú
mask_tokenÚexpandÚ	unsqueezeÚtype_asrK   Ú
image_sizeÚ
ValueErrorr,   Údropout)r-   rN   rO   rK   Ú
batch_sizeÚ_r2   r3   r1   Ú
seq_lengthÚmask_tokensÚmasks   &&&&        r   ÚforwardÚIJepaEmbeddings.forward=   s#  € ð (4×'9Ñ'9Ñ$ˆ
�vØ×*Ñ*¨<Ó8ˆ
àÒ&Ø#×)Ñ)¨!Õ,ˆJØŸ/™/×0Ñ0°ÈÓLˆKà"×,Ñ,¨RÓ0×8Ñ8¸ÓEˆDØ# s¨T¥zÕ2°[Õ5GÕGˆJ÷ $Ø#×&CÑ&CÀJÐX]Ó&^Õ^‰JàŸ™¨Õ+Ô+¨u¿¹ÈÕ8JÔ/JÜ Ø(¨¨°°%°ð 9ØŸ™¨Õ+Ð,¨A¨d¯o©o¸aÕ.@Ð-AÀðEóð ð $×&>Ñ&>Õ>ˆJà—\‘\ *Ó-ˆ
àÐr   )r,   )F)NF)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r#   rK   r_   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r.   r   s   @@r   r   r      s+   ù‡ € ÷aõ a÷%ð %÷N÷ ò r   r   c                   óN   a € ] tR t^]t o ]P
                  ! 4       R 4       tRtV tR# )ÚIJepaPreTrainedModelc                ób  € \         P                  ! W4       \        V\        P                  \        P
                  34      '       dj   \        P                  ! VP                  RV P                  P                  R7       VP                  e#   \        P                  ! VP                  4       R# R# \        V\        4      '       dj   \        P                  ! VP                  RV P                  P                  R7       VP                  e#   \        P                  ! VP                  4       R# R# R# )zInitialize the weightsg        )ÚmeanÚstdN)r   Ú_init_weightsÚ
isinstancer'   ÚLinearÚConv2dÚinitÚtrunc_normal_Úweightr   Úinitializer_rangeÚbiasÚzeros_r   r,   rS   )r-   Úmodules   &&r   rn   Ú"IJepaPreTrainedModel._init_weights_   sÂ   € ô 	×%Ò% dÔ3Ü�fœrŸy™y¬"¯)©)Ð4×5Ò5Ü×Ò˜vŸ}™}°3¸D¿K¹K×<YÑ<YÕZØ�{‰{Ò&Ü—’˜FŸK™KÖ(ñ 'ä˜¤×0Ò0Ü×Ò˜v×9Ñ9ÀÈÏÉ×IfÑIfÕgØ× Ñ Ò,Ü—’˜F×-Ñ-Ö.ñ -ñ 1r   © N)	ra   rb   rc   rd   r)   Úno_gradrn   re   rf   )r   s   @r   rj   rj   ]   s   ø‡ € à
‡]‚]ƒ_ñ
/ó ö
/r   rj   c                   óB   a a€ ] tR t^mt oRV3R lV 3R llltRtVtV ;t# )Ú
IJepaModelc                ó,   <€ V ^8„  d   QhRS[ RS[RS[/# )r   r   Úadd_pooling_layerr   r   )r   r   s   "€r   r   ÚIJepaModel.__annotate__n   s(   ø€ ÷ 	Qñ 	Q™{ð 	Q¹tð 	QÑ]añ 	Qr   c                óT   <€ \         SV `  V4       Wn        \        WR7      V n        R# )zÓ
add_pooling_layer (bool, *optional*, defaults to `True`):
    Whether to add a pooling layer
use_mask_token (`bool`, *optional*, defaults to `False`):
    Whether to use a mask token for masked image modeling.
)r   N)r"   r#   r   r   r1   )r-   r   r   r   r.   s   &&&&€r   r#   ÚIJepaModel.__init__n   s#   ø€ ô 	‰Ñ˜Ô ØŒÜ)¨&ÔPˆŽr   )r   r1   )FF)ra   rb   rc   rd   r#   re   rf   rg   rh   s   @@r   r}   r}   m   s   ù‡ € ÷	Q÷ 	Qõ 	Qr   r}   aÒ  
    IJepa Model transformer with an image classification head on top (a linear layer on top of the final hidden states)
    e.g. for ImageNet.

    <Tip>

        Note that it's possible to fine-tune IJepa 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                   óT   a a€ ] tR t^zt 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# )ÚIJepaForImageClassificationc                ó    <€ V ^8„  d   QhRS[ /# )r   r   r   )r   r   s   "€r   r   Ú(IJepaForImageClassification.__annotate__‰   s   ø€ ÷ ñ ™{ñ r   c                ój   <€ \         SV `  V4       \        VR R7      V n        V P	                  4        R# )F)r   N)r"   r#   r}   ÚijepaÚ	post_init)r-   r   r.   s   &&€r   r#   Ú$IJepaForImageClassification.__init__‰   s(   ø€ Ü‰Ñ˜Ô Ü ¸%Ô@ˆŒ
Ø�‰Ör   c          
      óš   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[R,          RS[S[,          RS[/# )r   rN   NÚlabelsrK   Úkwargsr   )r)   r4   r   r	   r
   r   )r   r   s   "€r   r   r‡   Ž   sY   ø€ ÷ 
ñ 
á—l‘l TÕ)ð
ñ —‘˜tÕ#ð
ñ #'¨¥+ð	
ñ
 Ñ+Õ,ð
ñ 
ñ
r   c                ó  € V P                   ! V3RV/VB pVP                  pV P                  VP                  ^R7      4      pRpVe   V P                  ! W'V P
                  3/ VB p\        VVVP                  VP                  R7      # )ab  
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).
rK   )rG   N)ÚlossÚlogitsÚhidden_statesÚ
attentions)	r‰   Úlast_hidden_stateÚ
classifierrl   Úloss_functionr   r   r’   r“   )	r-   rN   r�   rK   rŽ   ÚoutputsÚsequence_outputr‘   r�   s	   &&&&,    r   r_   Ú#IJepaForImageClassification.forwardŽ   s›   € ð /3¯jªjØñ/
à%=ð/
ð ñ/
ˆð
 "×3Ñ3ˆØ—‘ ×!5Ñ!5¸!Ð!5Ó!<Ó=ˆàˆØÒØ×%Ò% f°d·k±kÑLÀVÑLˆDä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r   )r‰   )NNN)	ra   rb   rc   rd   r#   r_   re   rf   rg   rh   s   @@r   r…   r…   z   s   ù‡ € ÷ó ÷

÷ 
ò 
r   r…   )rj   r}   r…   )r)   Útorch.nnr'   Ú-transformers.models.ijepa.configuration_ijepar   Ú r   rr   Úmodeling_outputsr   r   Úmodeling_utilsr   Úprocessing_utilsr	   Úutilsr
   r   r   Úvit.modeling_vitr   r   r   r   r   rj   r}   r…   Ú__all__rz   r   r   Ú<module>r£      s“   ðÛ Ý å Eå &ß QÝ -Ý &ß BÑ Bß eÓ eôL�mô Lð^ ô/Ð-ó /ó ð/ô
QÐ% xô 
Qñ ðôô%
Ð"6Ð8Qó %
óð%
òP‚r   