+
    œ°³j 4  ã                   óz  € R t ^ RIHt ^ RIt^ RIHt ^RIHt ^RIH	t	H
t
 ^RIHt ^RIHtHtHtHt ^RIHt ^R	IHtHtHtHtHt ^R
IHt  ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ]! RR7      ] ! R R]4      4       4       t!]! RR7       ! R R]4      4       t". ROt#R# )z7PyTorch DeiT (Data-efficient Image Transformers) model.)Ú	dataclassN)Únn)Úinitialization)ÚBaseModelOutputWithPoolingÚMaskedImageModelingOutput)ÚUnpack)ÚModelOutputÚTransformersKwargsÚauto_docstringÚ	torch_int)Úcan_return_tuple)ÚViTEmbeddingsÚViTForImageClassificationÚViTForMaskedImageModelingÚViTModelÚViTPreTrainedModel©Ú
DeiTConfigc                   ón   a a€ ] tR t^'t oRt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
# )ÚDeiTEmbeddingsa«  
Construct the CLS token, distillation token, position and patch embeddings. Optionally, also the mask token.

Differences from ViTEmbeddings:
- Adds a distillation token (for distillation pre-training).
- Position embeddings include +2 slots (CLS + distillation) instead of +1.
- interpolate_pos_encoding handles 2 special tokens instead of 1.
- forward concatenates distillation token and handles position encoding for both.
c                ó*   <€ V ^8„  d   QhRS[ RS[RR/# )é   ÚconfigÚuse_mask_tokenÚreturnN)r   Úbool)ÚformatÚ__classdict__s   "€Úf/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/deit/modular_deit.pyÚ__annotate__ÚDeiTEmbeddings.__annotate__2   s'   ø€ ÷ Vñ V™zð V¹4ð VÈDñ Vó    c                óÄ  <€ \         SV `  WR 7       \        P                  ! \        P
                  ! ^^VP                  4      4      V n        V P                  P                  p\        P                  ! \        P
                  ! ^V^,           VP                  4      4      V n
        \        P                  ! \        P
                  ! ^^VP                  4      4      V n        R# ))r   N)ÚsuperÚ__init__r   Ú	ParameterÚtorchÚzerosÚhidden_sizeÚ	cls_tokenÚpatch_embeddingsÚnum_patchesÚposition_embeddingsÚdistillation_token)Úselfr   r   r+   Ú	__class__s   &&& €r   r$   ÚDeiTEmbeddings.__init__2   s”   ø€ Ü‰Ñ˜ÐÔ?ÜŸš¤e§k¢k°!°Q¸×8JÑ8JÓ&KÓLˆŒØ×+Ñ+×7Ñ7ˆä#%§<¢<´·²¸A¸{ÈQ½ÐPV×PbÑPbÓ0cÓ#dˆÔ Ü"$§,¢,¬u¯{ª{¸1¸aÀ×ASÑASÓ/TÓ"UˆÖ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    :   s;   ø€ ÷ &Mñ &M±5·<±<ð &MÉð &MÑUXð &MÑ]b×]iÑ]iñ &Mr!   c                óæ  € V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 and 2 class embeddings.

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
ç      à?ÚbicubicF)ÚsizeÚmodeÚalign_corners©Údim)ºNNN:Nr   N©r?   :r   NNéÿÿÿÿ)Úshaper,   r&   ÚjitÚ
is_tracingÚ
patch_sizer   ÚreshapeÚpermuter   Ú
functionalÚinterpolateÚviewÚcat)r.   r2   r3   r4   r+   Únum_positionsÚclass_and_dist_pos_embedÚpatch_pos_embedr>   Ú
new_heightÚ	new_widthÚsqrt_num_positionss   &&&&        r   Úinterpolate_pos_encodingÚ'DeiTEmbeddings.interpolate_pos_encoding:   sG  € ð !×&Ñ& qÕ)¨AÕ-ˆØ×0Ñ0×6Ñ6°qÕ9¸AÕ=ˆô �y‰y×#Ñ#×%Ò%¨+Ô*FÈ6Ì?Ø×+Ñ+Ð+à#'×#;Ñ#;¸EÕ#BÐ Ø×2Ñ2°5Õ9ˆà×Ñ˜rÕ"ˆàŸ™Õ.ˆ
ØŸ_™_Õ,ˆ	ä& }°cÕ'9Ó:ÐØ)×1Ñ1°!Ð5GÐ]`ÓaˆØ)×1Ñ1°!°Q¸¸1Ó=ˆäŸ-™-×3Ñ3ØØÐ(ØØð	 4ó 
ˆð *×1Ñ1°!°Q¸¸1Ó=×BÑBÀ1ÀbÈ#ÓNˆä�yŠyÐ2ÐDÈ!ÔLÐLr!   c                ó|   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[RS[ P                  /# )r   Úpixel_valuesÚbool_masked_posNrR   r   )r&   r5   Ú
BoolTensorr   )r   r   s   "€r   r   r    b   sF   ø€ ÷  ñ  á—l‘lð ñ ×)Ñ)¨DÕ0ð ñ #'ð	 ñ
 
�‰ñ r!   c                ó(  € VP                   w   rEpV P                  V4      pVP                  4       w  r‰pVeZ   V P                  P	                  W‰R4      p
VP                  R4      P                  V
4      pVRV,
          ,          W«,          ,           pV P                  P	                  VRR4      pV P                  P	                  VRR4      p\        P                  ! WÍV3^R7      pV'       d   WpP                  WuV4      ,           pMzWPP                  ^ ,          8w  g   W`P                  ^,          8w  d;   \        RV RV RV P                  ^ ,           RV P                  ^,           R2	4      hWpP                  ,           pV P                  V4      pV# )Ng      ð?r=   zInput image size (Ú*z) doesn't match model (z).rA   )rB   r*   r:   Ú
mask_tokenÚexpandÚ	unsqueezeÚtype_asr)   r-   r&   rK   rR   Ú
image_sizeÚ
ValueErrorr,   Údropout)r.   rU   rV   rR   Ú_r3   r4   r2   Ú
batch_sizeÚ
seq_lengthÚmask_tokensÚmaskÚ
cls_tokensÚdistillation_tokenss   &&&&          r   ÚforwardÚDeiTEmbeddings.forwardb   sm  € ð +×0Ñ0Ñˆˆ1�eØ×*Ñ*¨<Ó8ˆ
à$.§O¡OÓ$5Ñ!ˆ
 àÒ&ØŸ/™/×0Ñ0°ÈÓLˆKà"×,Ñ,¨RÓ0×8Ñ8¸ÓEˆDØ# s¨T¥zÕ2°[Õ5GÕGˆJà—^‘^×*Ñ*¨:°r¸2Ó>ˆ
Ø"×5Ñ5×<Ñ<¸ZÈÈRÓPÐÜ—Y’Y 
ÀÐLÐRSÔTˆ
ç#Ø#×&CÑ&CÀJÐX]Ó&^Õ^‰JàŸ™¨Õ+Ô+¨u¿¹ÈÕ8JÔ/JÜ Ø(¨¨°°%°ð 9ØŸ™¨Õ+Ð,¨A¨d¯o©o¸aÕ.@Ð-AÀðEóð ð $×&>Ñ&>Õ>ˆJà—\‘\ *Ó-ˆ
ØÐr!   )r)   r-   r,   )F)NF)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r$   rR   rh   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r/   r   s   @@r   r   r   '   s2   ù‡ € ñ÷Võ V÷&Mð &M÷P ÷  ò  r!   r   c                   óF   a a€ ] tR t^…t oRR.tV3R lV 3R lltRtVtV ;t# )ÚDeiTPreTrainedModelr   Ú	DeiTLayerc                ó€   <€ V ^8„  d   QhRS[ P                  S[ P                  ,          S[ P                  ,          RR/# )r   Úmoduler   N)r   ÚLinearÚConv2dÚ	LayerNorm)r   r   s   "€r   r   Ú DeiTPreTrainedModel.__annotate__ˆ   s1   ø€ ÷ /ñ /¡B§I¡I±·	±	Õ$9¹B¿L¹LÕ$Hð /ÈTñ /r!   c                óv  <€ \         SV `  V4       \        V\        4      '       d“   \        P
                  ! VP                  4       \        P
                  ! VP                  4       \        P
                  ! VP                  4       VP                  e#   \        P
                  ! VP                  4       R# R# R# )zInitialize the weightsN)
r#   Ú_init_weightsÚ
isinstancer   ÚinitÚzeros_r)   r,   r-   rZ   )r.   rw   r/   s   &&€r   r}   Ú!DeiTPreTrainedModel._init_weightsˆ   s{   ø€ ä‰Ñ˜fÔ%Ü�fœn×-Ò-Ü�KŠK˜×(Ñ(Ô)Ü�KŠK˜×2Ñ2Ô3Ü�KŠK˜×1Ñ1Ô2Ø× Ñ Ò,Ü—’˜F×-Ñ-Ö.ñ -ñ	 .r!   © )	rj   rk   rl   rm   Ú_no_split_modulesr}   ro   rp   rq   rr   s   @@r   rt   rt   …   s   ù‡ € Ø)¨;Ð7Ð÷/÷ /ó /r!   rt   c                   ó   € ] tR t^“tRtR# )Ú	DeiTModelr‚   N©rj   rk   rl   rm   ro   r‚   r!   r   r…   r…   “   ó   † Ûr!   r…   c                   óJ   a € ] tR t^—t o ]]RV 3R lR ll4       4       tRtV tR# )ÚDeiTForMaskedImageModelingNc                ó´   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[RS[ P                  R,          RS[S[,          RS[/# )r   rU   NrV   rR   Úattention_maskÚkwargsr   )r&   r5   rW   r   r   r	   r   )r   r   s   "€r   r   Ú'DeiTForMaskedImageModeling.__annotate__š   sr   ø€ ÷ J
ñ J
á—l‘l TÕ)ðJ
ñ ×)Ñ)¨DÕ0ðJ
ñ #'ð	J
ñ
 Ÿ™ tÕ+ðJ
ñ Ñ+Õ,ðJ
ñ 
#ñJ
r!   c           	     ó�  € V P                   ! V3RVRVRV/VB pVP                  pVR
,          pVP                  w  r‰p
\        V	R,          4      ;r¼VP	                  ^ ^^4      P                  WŠW¼4      pV P                  V4      pRpVEe   V P                  P                  V P                  P                  ,          pVP                  RWÿ4      pVP                  V P                  P                  ^4      P                  V P                  P                  ^4      P                  ^4      P                  4       p\        P                  P                  WRR7      pVV,          P!                  4       VP!                  4       R,           ,          V P                  P"                  ,          p\%        VVVP&                  VP(                  R	7      # )a“  
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, num_patches)`):
    Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).

Examples:
```python
>>> from transformers import AutoImageProcessor, DeiTForMaskedImageModeling
>>> import torch
>>> from PIL import Image
>>> import requests

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)

>>> image_processor = AutoImageProcessor.from_pretrained("facebook/deit-base-distilled-patch16-224")
>>> model = DeiTForMaskedImageModeling.from_pretrained("facebook/deit-base-distilled-patch16-224")

>>> num_patches = (model.config.image_size // model.config.patch_size) ** 2
>>> pixel_values = image_processor(images=image, return_tensors="pt").pixel_values
>>> # create random boolean mask of shape (batch_size, num_patches)
>>> bool_masked_pos = torch.randint(low=0, high=2, size=(1, num_patches)).bool()

>>> outputs = model(pixel_values, bool_masked_pos=bool_masked_pos)
>>> loss, reconstructed_pixel_values = outputs.loss, outputs.reconstruction
>>> list(reconstructed_pixel_values.shape)
[1, 3, 224, 224]
```rV   rR   r‹   r8   NÚnone)Ú	reductiongñhãˆµøä>)ÚlossÚreconstructionÚhidden_statesÚ
attentionsr@   rA   )ÚdeitÚlast_hidden_staterB   r6   rG   rF   Údecoderr   r^   rE   Úrepeat_interleaver\   Ú
contiguousr   rH   Úl1_lossÚsumÚnum_channelsr   r“   r”   )r.   rU   rV   rR   r‹   rŒ   ÚoutputsÚsequence_outputrb   Úsequence_lengthrœ   r3   r4   Úreconstructed_pixel_valuesÚmasked_im_lossr:   re   Úreconstruction_losss   &&&&&,            r   rh   Ú"DeiTForMaskedImageModeling.forward˜   s£  € ðL /3¯iªiØñ/
à+ð/
ð &>ð/
ð *ð	/
ð
 ñ/
ˆð "×3Ñ3ˆð *¨%Õ0ˆØ4C×4IÑ4IÑ1ˆ
 \Ü˜_¨cÕ1Ó2Ð2ˆØ)×1Ñ1°!°Q¸Ó:×BÑBÀ:Ð]cÓkˆð &*§\¡\°/Ó%BÐ"àˆØÓ&Ø—;‘;×)Ñ)¨T¯[©[×-CÑ-CÕCˆDØ-×5Ñ5°b¸$ÓEˆOà×1Ñ1°$·+±+×2HÑ2HÈ!ÓLß"Ñ" 4§;¡;×#9Ñ#9¸1Ó=ß‘˜1“ß‘“ð	 ô #%§-¡-×"7Ñ"7¸ÐlrÐ"7Ó"sÐØ1°DÕ8×=Ñ=Ó?À4Ç8Á8Ã:ÐPTÕCTÕUÐX\×XcÑXc×XpÑXpÕpˆNä(ØØ5Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
r!   r‚   )NNFN)	rj   rk   rl   rm   r   r
   rh   ro   rp   ©r   s   @r   r‰   r‰   —   s'   ø‡ € ØØ÷J
ñ J
ó ó öJ
r!   r‰   c                   ó   € ] tR t^çtRtR# )ÚDeiTForImageClassificationr‚   Nr†   r‚   r!   r   r¦   r¦   ç   r‡   r!   r¦   zC
    Output type of [`DeiTForImageClassificationWithTeacher`].
    )Úcustom_introc                   óD   a € ] tR t^ët o RtRtRtRtRtRt	V 3R lt
RtV tR# )Ú+DeiTForImageClassificationWithTeacherOutputaF  
logits (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`):
    Prediction scores as the average of the cls_logits and distillation logits.
cls_logits (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`):
    Prediction scores of the classification head (i.e. the linear layer on top of the final hidden state of the
    class token).
distillation_logits (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`):
    Prediction scores of the distillation head (i.e. the linear layer on top of the final hidden state of the
    distillation token).
Nc                ó   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   # )r   NÚlogitsÚ
cls_logitsÚdistillation_logitsr“   r”   )r&   ÚFloatTensorÚtuple)r   r   s   "€r   r   Ú8DeiTForImageClassificationWithTeacherOutput.__annotate__ë   s‡   ø‡ ‚ ñ$ ×Ñ Õ$Ñ+ñ% ñ& ×!Ñ! DÕ(Ñ/ñ' ñ( ×*Ñ*¨TÕ1Ñ8ñ) ñ* ™×*Ñ*Õ+¨dÕ2Ñ9ñ+ ñ, ‘e×'Ñ'Õ(¨4Õ/Ñ6ò- r!   r‚   )rj   rk   rl   rm   rn   r«   r¬   r­   r“   r”   Ú__annotate_func__ro   rp   r¤   s   @r   r©   r©   ë   s-   ø‡ € ñ	ð (,€FØ+/€JØ48ÐØ59€MØ26€J÷- ƒ r!   r©   aˆ  
    DeiT Model transformer with image classification heads on top (a linear layer on top of the final hidden state of
    the [CLS] token and a linear layer on top of the final hidden state of the distillation token) e.g. for ImageNet.

    .. warning::

           This model supports inference-only. Fine-tuning with distillation (i.e. with a teacher) is not yet
           supported.
    c                   ó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
# )Ú%DeiTForImageClassificationWithTeacheri  c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   r   r   Nr   )r   r   s   "€r   r   Ú2DeiTForImageClassificationWithTeacher.__annotate__  s   ø€ ÷ ñ ™zð ¨dñ r!   c                óä  <€ \         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                  ^ 8”  d,   \
        P                  ! VP                  VP                  4      M\
        P                  ! 4       V n
        V P                  4        R# )F)Úadd_pooling_layerN)r#   r$   Ú
num_labelsr…   r•   r   rx   r(   ÚIdentityÚcls_classifierÚdistillation_classifierÚ	post_init)r.   r   r/   s   &&€r   r$   Ú.DeiTForImageClassificationWithTeacher.__init__  s·   ø€ Ü‰Ñ˜Ô à ×+Ñ+ˆŒÜ˜f¸Ô>ˆŒ	ð AG×@QÑ@QÐTUÔ@UŒB�IŠI�f×(Ñ(¨&×*;Ñ*;Ô<Ô[]×[fÒ[fÓ[hð 	Ôð AG×@QÑ@QÐTUÔ@UŒB�IŠI�f×(Ñ(¨&×*;Ñ*;Ô<Ô[]×[fÒ[fÓ[hð 	Ô$ð
 	�‰Ör!   c          
      óŒ   <€ V ^8„  d   QhRS[ P                  R,          RS[RS[ P                  R,          RS[S[,          RS[/# )r   rU   NrR   r‹   rŒ   r   )r&   r5   r   r   r	   r©   )r   r   s   "€r   r   rµ   #  sU   ø€ ÷ 
ñ 
á—l‘l TÕ)ð
ñ #'ð
ñ Ÿ™ tÕ+ð	
ñ
 Ñ+Õ,ð
ñ 
5ñ
r!   c                ó  € V P                   ! V3R VRV/VB pVP                  pV P                  VR,          4      pV P                  VR,          4      pWx,           ^,          p	\	        V	VVVP
                  VP                  R7      # )rR   r‹   )r«   r¬   r­   r“   r”   )r?   é    r?   )r?   é   r?   )r•   r–   rº   r»   r©   r“   r”   )
r.   rU   rR   r‹   rŒ   r�   rž   r¬   r­   r«   s
   &&&&,     r   rh   Ú-DeiTForImageClassificationWithTeacher.forward!  s    € ð /3¯iªiØñ/
à%=ð/
ð *ð/
ð ñ	/
ˆð "×3Ñ3ˆà×(Ñ(¨¸Õ)AÓBˆ
Ø"×:Ñ:¸?È7Õ;SÓTÐð Õ2°aÕ7ˆä:ØØ!Ø 3Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r!   )rº   r•   r»   r¸   )NFN)rj   rk   rl   rm   r$   r   r
   rh   ro   rp   rq   rr   s   @@r   r³   r³     s5   ù‡ € ÷ó ð" Ø÷
ñ 
ó ó ÷
ð 
r!   r³   )r¦   r³   r‰   r…   rt   )$rn   Údataclassesr   r&   r   Ú r   r   Úmodeling_outputsr   r   Úprocessing_utilsr   Úutilsr   r	   r
   r   Úutils.genericr   Úvit.modeling_vitr   r   r   r   r   Úconfiguration_deitr   r   rt   r…   r‰   r¦   r©   r³   Ú__all__r‚   r!   r   Ú<module>rÌ      sÚ   ðñ >å !ã Ý å &÷õ 'ß OÓ OÝ -÷õ õ +ô[�]ô [ô|/Ð,ô /ô	�ô 	ôM
Ð!:ô M
ô`	Ð!:ô 	ñ ðôð
 ô7°+ó 7ó óð7ñ& ðô
ô0
Ð,?ó 0
ó
ð0
òf‚r!   