+
    œ°³jäŽ  ã                   óÆ  € R t ^ RIt^ RIt^ RIHt ^ RIt^ RIHt ^RIH	t
 ^RIHt ^RIHtHt ^RIHt ^RIHt ^R	IHt ^R
IHtHtHt ^RIHt ^RIHt ]P<                  ! ]4      t ]! RR7      ] ! R R]4      4       4       t!]! RR7      ] ! R R]4      4       4       t"]! RR7      ] ! R R]4      4       4       t#]! RR7      ] ! R R]4      4       4       t$ ! R R]PJ                  4      t& ! R R]PJ                  4      t' ! R R]PJ                  4      t( ! R  R!]PJ                  4      t) ! R" R#]PJ                  4      t* ! R$ R%]PJ                  4      t+ ! R& R']4      t, ! R( R)]PJ                  4      t-] ! R* R+]4      4       t.] ! R, R-].4      4       t/]! R.R7       ! R/ R0].4      4       t0]! R1R7       ! R2 R3].4      4       t1]! R4R7       ! R5 R6]].4      4       t2. R7Ot3R# )8zPyTorch FocalNet model.N)Ú	dataclass)Únn)Úinitialization)ÚACT2FN)ÚBackboneMixinÚfilter_output_hidden_states)ÚGradientCheckpointingLayer)ÚBackboneOutput)ÚPreTrainedModel)ÚModelOutputÚauto_docstringÚlogging)Úcan_return_tuple©ÚFocalNetConfigzC
    FocalNet encoder's outputs, with potential hidden states.
    )Úcustom_introc                   ó<   a € ] tR t^%t o RtRtRtRtV 3R ltRt	V t
R# )ÚFocalNetEncoderOutputaÕ  
reshaped_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, hidden_size, height, width)`.

    Hidden-states of the model at the output of each layer plus the initial embedding outputs reshaped to
    include the spatial dimensions.
Nc                óÄ   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   # )é   NÚlast_hidden_stateÚhidden_statesÚreshaped_hidden_states©ÚtorchÚFloatTensorÚtuple)ÚformatÚ__classdict__s   "€Úo/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/focalnet/modeling_focalnet.pyÚ__annotate__Ú"FocalNetEncoderOutput.__annotate__%   sW   ø‡ ‚ ñ  ×(Ñ(¨4Õ/Ñ6ñ! ñ" ™×*Ñ*Õ+¨dÕ2Ñ9ñ# ñ$ "¡%×"3Ñ"3Õ4°tÕ;ÑBò% ó    © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r   s   @r   r   r   %   s$   ø‡ € ñð 37ÐØ59€MØ>BÐ÷% ƒ r"   r   zZ
    FocalNet model's outputs that also contains a pooling of the last hidden states.
    c                   ó@   a € ] tR t^:t o RtRtRtRtRtV 3R lt	Rt
V tR# )ÚFocalNetModelOutputa‘  
pooler_output (`torch.FloatTensor` of shape `(batch_size, hidden_size)`, *optional*, returned when `add_pooling_layer=True` is passed):
    Average pooling of the last layer hidden-state.
reshaped_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, hidden_size, height, width)`.

    Hidden-states of the model at the output of each layer plus the initial embedding outputs reshaped to
    include the spatial dimensions.
Nc                óò   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   # )r   Nr   Úpooler_outputr   r   r   )r   r   s   "€r   r    Ú FocalNetModelOutput.__annotate__:   so   ø‡ ‚ ñ$ ×(Ñ(¨4Õ/Ñ6ñ% ñ& ×$Ñ$ tÕ+Ñ2ñ' ñ( ™×*Ñ*Õ+¨dÕ2Ñ9ñ) ñ* "¡%×"3Ñ"3Õ4°tÕ;ÑBò+ r"   r#   )r$   r%   r&   r'   r(   r   r0   r   r   r)   r*   r+   r,   s   @r   r.   r.   :   s)   ø‡ € ñ	ð 37ÐØ.2€MØ59€MØ>BÐ÷+ ƒ r"   r.   z.
    FocalNet masked image model outputs.
    c                   ó@   a € ] tR t^Rt o RtRtRtRtRtV 3R lt	Rt
V tR# )Ú!FocalNetMaskedImageModelingOutputaÛ  
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `bool_masked_pos` is provided):
    Masked image modeling (MLM) loss.
reconstruction (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
    Reconstructed pixel values.
reshaped_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, hidden_size, height, width)`.

    Hidden-states of the model at the output of each layer plus the initial embedding outputs reshaped to
    include the spatial dimensions.
Nc                óò   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   # )r   NÚlossÚreconstructionr   r   r   )r   r   s   "€r   r    Ú.FocalNetMaskedImageModelingOutput.__annotate__R   so   ø‡ ‚ ñ( ×
Ñ
˜dÕ
"Ñ)ñ) ñ* ×%Ñ%¨Õ,Ñ3ñ+ ñ, ™×*Ñ*Õ+¨dÕ2Ñ9ñ- ñ. "¡%×"3Ñ"3Õ4°tÕ;ÑBò/ r"   r#   )r$   r%   r&   r'   r(   r5   r6   r   r   r)   r*   r+   r,   s   @r   r3   r3   R   s(   ø‡ € ñð &*€DØ/3€NØ59€MØ>BÐ÷/ ƒ r"   r3   z4
    FocalNet outputs for image classification.
    c                   ó@   a € ] tR t^lt o RtRtRtRtRtV 3R lt	Rt
V tR# )ÚFocalNetImageClassifierOutputa  
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
    Classification (or regression if config.num_labels==1) loss.
logits (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`):
    Classification (or regression if config.num_labels==1) scores (before SoftMax).
reshaped_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, hidden_size, height, width)`.

    Hidden-states of the model at the output of each layer plus the initial embedding outputs reshaped to
    include the spatial dimensions.
Nc                óò   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   # )r   Nr5   Úlogitsr   r   r   )r   r   s   "€r   r    Ú*FocalNetImageClassifierOutput.__annotate__l   so   ø‡ ‚ ñ( ×
Ñ
˜dÕ
"Ñ)ñ) ñ* ×Ñ Õ$Ñ+ñ+ ñ, ™×*Ñ*Õ+¨dÕ2Ñ9ñ- ñ. "¡%×"3Ñ"3Õ4°tÕ;ÑBò/ r"   r#   )r$   r%   r&   r'   r(   r5   r;   r   r   r)   r*   r+   r,   s   @r   r9   r9   l   s(   ø‡ € ñð &*€DØ'+€FØ59€MØ>BÐ÷/ ƒ r"   r9   c                   óP   a a€ ] tR t^†t oRtRV 3R lltRV3R lR lltRtVtV ;t	# )ÚFocalNetEmbeddingszP
Construct the patch embeddings and layernorm. Optionally, also the mask token.
c           
     ó"  <€ \         SV `  4        \        VVP                  VP                  VP
                  VP                  VP                  R R7      V n        V P                  P                  V n
        V'       d7   \        P                  ! \        P                  ! ^^VP                  4      4      MRV n        \        P                   ! VP                  VP"                  R7      V n        \        P&                  ! VP(                  4      V n        R# )T)ÚconfigÚ
image_sizeÚ
patch_sizeÚnum_channelsÚ	embed_dimÚuse_conv_embedÚis_stemN©Úeps)ÚsuperÚ__init__ÚFocalNetPatchEmbeddingsrA   rB   rC   rD   rE   Úpatch_embeddingsÚ	grid_sizeÚ
patch_gridr   Ú	Parameterr   ÚzerosÚ
mask_tokenÚ	LayerNormÚlayer_norm_epsÚnormÚDropoutÚhidden_dropout_probÚdropout)Úselfr@   Úuse_mask_tokenÚ	__class__s   &&&€r   rJ   ÚFocalNetEmbeddings.__init__‹   s¿   ø€ Ü‰ÑÔä 7ØØ×(Ñ(Ø×(Ñ(Ø×,Ñ,Ø×&Ñ&Ø!×0Ñ0Øô!
ˆÔð ×/Ñ/×9Ñ9ˆŒßO]œ"Ÿ,š,¤u§{¢{°1°a¸×9IÑ9IÓ'JÔKÐcgˆŒä—L’L ×!1Ñ!1°v×7LÑ7LÔMˆŒ	Ü—z’z &×"<Ñ"<Ó=ˆŽr"   c                ó”   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[S[ P                  ,          /# )r   Úpixel_valuesNÚbool_masked_posÚreturn)r   r   Ú
BoolTensorr   ÚTensor)r   r   s   "€r   r    ÚFocalNetEmbeddings.__annotate__�   sE   ø€ ÷ -ñ -Ù!×-Ñ-°Õ4ð-ÙGL×GWÑGWÐZ^ÕG^ð-á	‰u�|‰|Õ	ñ-r"   c                óR  € V P                  V4      w  r4V P                  V4      pVP                  4       w  rVpVeZ   V P                  P	                  WVR4      pVP                  R4      P                  V4      p	VRV	,
          ,          W‰,          ,           pV P                  V4      pW43# )Nç      ð?éÿÿÿÿ)rL   rT   ÚsizerQ   ÚexpandÚ	unsqueezeÚtype_asrW   )
rX   r]   r^   Ú
embeddingsÚoutput_dimensionsÚ
batch_sizeÚseq_lenÚ_Úmask_tokensÚmasks
   &&&       r   ÚforwardÚFocalNetEmbeddings.forward�   sš   € ð )-×(=Ñ(=¸lÓ(KÑ%ˆ
Ø—Y‘Y˜zÓ*ˆ
Ø!+§¡Ó!2Ñˆ
˜QàÒ&ØŸ/™/×0Ñ0°ÀbÓIˆKà"×,Ñ,¨RÓ0×8Ñ8¸ÓEˆDØ# s¨T¥zÕ2°[Õ5GÕGˆJà—\‘\ *Ó-ˆ
ØÐ,Ð,r"   )rW   rQ   rT   rL   rN   )F©N©
r$   r%   r&   r'   r(   rJ   rq   r*   r+   Ú__classcell__©rZ   r   s   @@r   r>   r>   †   s   ù‡ € ñ÷>÷$-÷ -ò -r"   r>   c                   óN   a a€ ] tR t^®t oRV 3R lltR tV3R lR ltRtVtV ;t	# )rK   c	                óü  <€ \         SV `  4        \        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	        V^ ,          V^ ,          ,          V^,          V^,          ,          3V n
        V'       d5   V'       d   ^p
^p^pM^p
^p^p\        P                  ! WEW¬VR7      V n        M\        P                  ! WEW3R7      V n        V'       d)   \        P                  ! WQP                  R7      V n        R# RV n        R# )é   )Úkernel_sizeÚstrideÚpadding)rz   r{   rG   N)rI   rJ   Ú
isinstanceÚcollectionsÚabcÚIterablerA   rB   rC   Únum_patchesrM   r   ÚConv2dÚ
projectionrR   rS   rT   )rX   r@   rA   rB   rC   rD   Úadd_normrE   rF   r�   rz   r|   r{   rZ   s   &&&&&&&&&    €r   rJ   Ú FocalNetPatchEmbeddings.__init__¯   s$  ø€ ô 	‰ÑÔÜ#-¨j¼+¿/¹/×:RÑ:R×#SÒ#S‘ZÐZdÐYqˆ
Ü#-¨j¼+¿/¹/×:RÑ:R×#SÒ#S‘ZÐZdÐYqˆ
Ø! !•}¨
°1­Õ5¸*ÀQ½-È:ÐVWÍ=Õ:XÕYˆØ$ŒØ$ŒØ(ÔØ&ÔØ$ Q�-¨:°a­=Õ8¸*ÀQ½-È:ÐVWÍ=Õ:XÐYˆŒççØ�Ø�Ø‘à�Ø�Ø�Ü ŸišiØ°[ÐY`ôˆD�Oô !Ÿiši¨ÈZÔkˆDŒOçÜŸš Y×4IÑ4IÔJˆDŽIàˆDŽIr"   c                óÊ  € W0P                   ^,          ,          ^ 8w  dS   ^ V P                   ^,          W0P                   ^,          ,          ,
          3p\        P                  P                  W4      pW P                   ^ ,          ,          ^ 8w  dU   ^ ^ ^ V P                   ^ ,          W P                   ^ ,          ,          ,
          3p\        P                  P                  W4      pV# ©ry   )rB   r   Ú
functionalÚpad)rX   r]   ÚheightÚwidthÚ
pad_valuess   &&&& r   Ú	maybe_padÚ!FocalNetPatchEmbeddings.maybe_padÙ   s¥   € Ø—?‘? 1Õ%Õ%¨Ô*Ø˜TŸ_™_¨QÕ/°%¿/¹/È!Õ:LÕ2LÕLÐMˆJÜŸ=™=×,Ñ,¨\ÓFˆLØ—O‘O AÕ&Õ&¨!Ô+Ø˜Q  4§?¡?°1Õ#5¸ÇÁÐQRÕASÕ8SÕ#SÐTˆJÜŸ=™=×,Ñ,¨\ÓFˆLØÐr"   c                ó‚   <€ V ^8„  d   QhRS[ P                  R,          RS[S[ P                  S[S[,          3,          /# )r   r]   Nr_   )r   r   r   ra   Úint)r   r   s   "€r   r    Ú$FocalNetPatchEmbeddings.__annotate__â   s;   ø€ ÷ -ñ -¡E×$5Ñ$5¸Õ$<ð -ÁÁuÇ|Á|ÑUZÑ[^ÕU_ÐG_ÕA`ñ -r"   c                óH  € VP                   w  r#rEW0P                  8w  d   \        R 4      hV P                  WV4      pV P	                  V4      pVP                   w   r$pWE3pVP                  ^4      P                  ^^4      pV P                  e   V P                  V4      pWg3# )zeMake sure that the channel dimension of the pixel values match with the one set in the configuration.)ÚshaperC   Ú
ValueErrorr�   rƒ   ÚflattenÚ	transposerT   )rX   r]   rn   rC   rŠ   r‹   rj   rk   s   &&      r   rq   ÚFocalNetPatchEmbeddings.forwardâ   s¦   € Ø)5×);Ñ);Ñ&ˆ˜Ø×,Ñ,Ô,ÜØwóð ð —~‘~ l¸EÓBˆØ—_‘_ \Ó2ˆ
Ø(×.Ñ.Ñˆˆ1�eØ#˜OÐØ×'Ñ'¨Ó*×4Ñ4°Q¸Ó:ˆ
à�9‰9Ò ØŸ™ :Ó.ˆJàÐ,Ð,r"   )rM   rA   rT   rC   r�   rB   rƒ   )FFF)
r$   r%   r&   r'   rJ   r�   rq   r*   r+   ru   rv   s   @@r   rK   rK   ®   s   ù‡ € ÷(òT÷-÷ -ð -r"   rK   c                   ó<   a a€ ] tR t^õt oRV 3R lltR tRtVtV ;t# )ÚFocalNetModulationc                ój  <€ \         S	V `  4        W0n        VP                  V,          V n        VP
                  V,          V n        W@n        VP                  V n        VP                  V n	        \        P                  ! V^V,          V P                  ^,           ,           VR7      V n        \        P                  ! W3^^VR7      V n        \        P                  ! 4       V n        \        P                  ! W34      V n        \        P$                  ! V4      V n        \        P(                  ! 4       V n        . V n        \/        V P                  4       F¥  pV P                  V,          V P                  ,           pV P*                  P1                  \        P2                  ! \        P                  ! W3V^W8^,          RR7      \        P                  ! 4       4      4       V P,                  P1                  V4       K§  	  V P                  '       d)   \        P4                  ! W1P6                  R7      V n        R# R# )r   )Úbias)rz   r{   r›   F)rz   r{   Úgroupsr|   r›   rG   N)rI   rJ   ÚdimÚfocal_windowsÚfocal_windowÚfocal_levelsÚfocal_levelÚfocal_factorÚ use_post_layernorm_in_modulationÚnormalize_modulatorr   ÚLinearÚprojection_inr‚   Úprojection_contextÚGELUÚ
activationÚprojection_outrU   Úprojection_dropoutÚ
ModuleListÚfocal_layersÚkernel_sizesÚrangeÚappendÚ
SequentialrR   rS   Ú	layernorm)
rX   r@   Úindexr�   r¢   r›   r«   Úkrz   rZ   s
   &&&&&&&  €r   rJ   ÚFocalNetModulation.__init__ö   s›  ø€ Ü‰ÑÔàŒØ"×0Ñ0°Õ7ˆÔØ!×.Ñ.¨uÕ5ˆÔØ(ÔØ06×0WÑ0WˆÔ-Ø#)×#=Ñ#=ˆÔ äŸYšY s¨A°­G°t×7GÑ7GÈ!Õ7KÕ,LÐSWÔXˆÔÜ"$§)¢)¨CÀ!ÈAÐTXÔ"YˆÔäŸ'š'›)ˆŒÜ Ÿiši¨Ó1ˆÔÜ"$§*¢*Ð-?Ó"@ˆÔÜŸMšM›OˆÔàˆÔÜ�t×'Ñ'Ö(ˆAØ×+Ñ+¨aÕ/°$×2CÑ2CÕCˆKØ×Ñ×$Ñ$Ü—’Ü—I’IØ¨kÀ!ÈCÐhiÕYiÐpuôô —G’G“Ió	ôð ×Ñ×$Ñ$ [Ö1ñ )ð ×0×0Ð0ÜŸ\š\¨#×3HÑ3HÔIˆDŽNñ 1r"   c                óš  € VP                   R,          pV P                  V4      P                  ^ ^^^4      P                  4       p\        P
                  ! W2W P                  ^,           3^4      w  rEp^ p\        V P                  4       F<  pV P                  V,          ! V4      pWuVRWˆ^,           13,          ,          ,           pK>  	  V P                  VP                  ^RR7      P                  ^RR7      4      p	WyVRV P                  R13,          ,          ,           pV P                  '       d   WpP                  ^,           ,          pV P                  V4      p
WJ,          pVP                  ^ ^^^4      P                  4       pV P                  '       d   V P                  V4      pV P                  V4      pV P!                  V4      pV# )zh
Args:
    hidden_state:
        Input features with shape of (batch_size, height, width, num_channels)
:NNNT)ÚkeepdimNre   )r“   r¦   ÚpermuteÚ
contiguousr   Úsplitr¡   r¯   r­   r©   Úmeanr¤   r§   r£   r²   rª   r«   )rX   Úhidden_staterC   ÚxÚqÚctxÚgatesÚctx_allÚlevelÚ
ctx_globalÚ	modulatorÚx_outs   &&          r   rq   ÚFocalNetModulation.forward  sš  € ð $×)Ñ)¨"Õ-ˆð ×Ñ˜|Ó,×4Ñ4°Q¸¸1¸aÓ@×KÑKÓMˆÜŸš A°l×DTÑDTÐWXÕDXÐ'YÐ[\Ó]‰ˆ�ð ˆÜ˜4×+Ñ+Ö,ˆEØ×#Ñ# EÖ*¨3Ó/ˆCØ e¨A¨u¸qµyÐ/@Ð,@Õ&AÕ AÕAŠGñ -ð —_‘_ S§X¡X¨a¸ XÓ%>×%CÑ%CÀAÈtÐ%CÓ%TÓUˆ
Ø¨¨q°$×2BÑ2BÑ2DÐ/DÕ)EÕEÕEˆð ×#×#Ð#Ø×!1Ñ!1°AÕ!5Õ6ˆGð ×+Ñ+¨GÓ4ˆ	Ø•ˆØ—‘˜a  A qÓ)×4Ñ4Ó6ˆØ×0×0Ð0Ø—N‘N 5Ó)ˆEð ×#Ñ# EÓ*ˆØ×'Ñ'¨Ó.ˆØˆr"   )r©   r�   r¢   r­   r¡   rŸ   r®   r²   r¤   r§   r«   r¦   rª   r£   )r   Tç        ©	r$   r%   r&   r'   rJ   rq   r*   r+   ru   rv   s   @@r   r™   r™   õ   s   ù‡ € ÷J÷B"ò "r"   r™   c                   ó<   a a€ ] tR tRt oRV 3R lltR tRtVtV ;t# )ÚFocalNetMlpi<  c                ó.  <€ \         SV `  4        T;'       g    TpT;'       g    Tp\        P                  ! W#4      V n        \
        VP                  ,          V n        \        P                  ! W44      V n        \        P                  ! V4      V n
        R # rs   )rI   rJ   r   r¥   Úfc1r   Ú
hidden_actr©   Úfc2rU   Údrop)rX   r@   Úin_featuresÚhidden_featuresÚout_featuresrÏ   rZ   s   &&&&&&€r   rJ   ÚFocalNetMlp.__init__=  sj   ø€ Ü‰ÑÔØ#×2Ð2 {ˆØ)×8Ð8¨[ˆÜ—9’9˜[Ó:ˆŒÜ  ×!2Ñ!2Õ3ˆŒÜ—9’9˜_Ó;ˆŒÜ—J’J˜tÓ$ˆŽ	r"   c                ó°   € V P                  V4      pV P                  V4      pV P                  V4      pV P                  V4      pV P                  V4      pV# rs   )rÌ   r©   rÏ   rÎ   )rX   r¼   s   &&r   rq   ÚFocalNetMlp.forwardF  sN   € Ø—x‘x Ó-ˆØ—‘ |Ó4ˆØ—y‘y Ó.ˆØ—x‘x Ó-ˆØ—y‘y Ó.ˆØÐr"   )r©   rÏ   rÌ   rÎ   )NNrÇ   rÈ   rv   s   @@r   rÊ   rÊ   <  s   ù‡ € ÷%÷ò r"   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
# )ÚFocalNetDropPathiP  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/# )r   Ú	drop_probr_   N)Úfloat)r   r   s   "€r   r    ÚFocalNetDropPath.__annotate__W  s   ø€ ÷ #ñ #¡%ð #°$ñ #r"   c                ó0   <€ \         SV `  4        Wn        R # rs   )rI   rJ   rÙ   )rX   rÙ   rZ   s   &&€r   rJ   ÚFocalNetDropPath.__init__W  s   ø€ Ü‰ÑÔØ"Žr"   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   r   r_   )r   ra   )r   r   s   "€r   r    rÛ   [  s#   ø€ ÷ <ñ <¡U§\¡\ð <±e·l±lñ <r"   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Ç   )ÚdtypeÚdevicer‡   )
rÙ   Útrainingr“   Úndimr   Úrandrà   rá   ÚfloorÚdiv)rX   r   Ú	keep_probr“   Úrandom_tensors   &&   r   rq   ÚFocalNetDropPath.forward[  s•   € Ø�>‰>˜SÔ ¨¯¯¨Ø Ð Ø˜Ÿ™Õ&ˆ	Ø×$Ñ$ QÕ'Ð)¨D°M×4FÑ4FÈÕ4JÕ,KÕKˆÜŸ
š
 5×0CÑ0CÈM×L`ÑL`ÔaˆÜŸš MÕ$=Ó>ˆØ× Ñ  Ó+¨mÕ;Ð;r"   c                ó    <€ V ^8„  d   QhRS[ /# )r   r_   )Ústr)r   r   s   "€r   r    rÛ   d  s   ø€ ÷ %ñ %™Cñ %r"   c                ó    € R V P                    2# )zp=©rÙ   ©rX   s   &r   Ú
extra_reprÚFocalNetDropPath.extra_reprd  s   € Ø�D—N‘NÐ#Ð$Ð$r"   rí   ©rÇ   )r$   r%   r&   r'   r(   rJ   rq   rï   r*   r+   ru   rv   s   @@r   r×   r×   P  s-   ù‡ € ñ÷#õ #÷<ð <÷%÷ %ð %r"   r×   c                   ó@   a a€ ] tR tRt oRtRV 3R lltR tRtVtV ;t	# )ÚFocalNetLayerih  aS  Focal Modulation Network layer (block).

Args:
    config (`FocalNetConfig`):
        Model config.
    index (`int`):
        Layer index.
    dim (`int`):
        Number of input channels.
    input_resolution (`tuple[int]`):
        Input resolution.
    drop_path (`float`, *optional*, defaults to 0.0):
        Stochastic depth rate.
c                ór  <€ \         SV `  4        Wn        W0n        W@n        VP
                  V n        VP                  V n        \        P                  ! W1P                  R 7      V n        \        VVVV P                  R7      V n        VR8”  d   \        V4      M\        P                  ! 4       V n        \        P                  ! W1P                  R 7      V n        \%        W1P&                  ,          4      p\)        WW`P                  R7      V n        RV n        RV n        VP0                  '       d‡   \        P2                  ! VP4                  \6        P8                  ! V4      ,          RR7      V n        \        P2                  ! VP4                  \6        P8                  ! V4      ,          RR7      V n        R# R# )rG   )r@   r³   r�   r«   rÇ   )r@   rÐ   rÑ   rÏ   rd   T)Úrequires_gradN)rI   rJ   r@   r�   Úinput_resolutionrV   rÏ   Úuse_post_layernormr   rR   rS   Únorm1r™   Ú
modulationr×   ÚIdentityÚ	drop_pathÚnorm2r�   Ú	mlp_ratiorÊ   ÚmlpÚgamma_1Úgamma_2Úuse_layerscalerO   Úlayerscale_valuer   Úones)rX   r@   r³   r�   rö   rû   Úmlp_hidden_dimrZ   s   &&&&&& €r   rJ   ÚFocalNetLayer.__init__x  s5  ø€ Ü‰ÑÔàŒð ŒØ 0Ôð ×.Ñ.ˆŒ	Ø"(×";Ñ";ˆÔä—\’\ #×+@Ñ+@ÔAˆŒ
Ü,ØØØØ#Ÿy™yô	
ˆŒð 9BÀC¼Ô)¨)Ô4ÌRÏ[Ê[Ë]ˆŒÜ—\’\ #×+@Ñ+@ÔAˆŒ
Ü˜S×#3Ñ#3Õ3Ó4ˆÜ fÈ~×dmÑdmÔnˆŒàˆŒØˆŒØ× × Ð ÜŸ<š<¨×(?Ñ(?Ä%Ç*Â*ÈSÃ/Õ(QÐaeÔfˆDŒLÜŸ<š<¨×(?Ñ(?Ä%Ç*Â*ÈSÃ/Õ(QÐaeÔfˆDŽLñ !r"   c           	     óx  € Vw  r4VP                   w  rVpTpV P                  '       d   TMV P                  V4      pVP                  WSWG4      pV P	                  V4      P                  WSV,          V4      pV P                  '       g   TMV P                  V4      pW€P                  V P                  V,          4      ,           pYP                  V P                  V P                  '       d!   V P                  V P                  V4      4      MV P                  V P                  V4      4      ,          4      ,           pV# rs   )
r“   r÷   rø   Úviewrù   rû   rÿ   r   rü   rþ   )	rX   r¼   Úinput_dimensionsrŠ   r‹   rl   rn   rC   Úshortcuts	   &&&      r   rq   ÚFocalNetLayer.forward˜  s  € Ø(‰ˆØ&2×&8Ñ&8Ñ#ˆ
�|Øˆð (,×'>×'>Ð'>‘|ÀDÇJÁJÈ|ÓD\ˆØ#×(Ñ(¨¸UÓQˆØ—‘ |Ó4×9Ñ9¸*ÈuÅnÐVbÓcˆØ+/×+B×+BÐ+B‘|ÈÏ
É
ÐS_ÓH`ˆð  §.¡.°·±ÀÕ1LÓ"MÕMˆØ#§n¡nØ�L‰LØ59×5L×5LÐ5Lˆt�z‰z˜$Ÿ(™( <Ó0Ô1ÐRV×RZÑRZÐ[_×[eÑ[eÐfrÓ[sÓRtõvó'
õ 
ˆð
 Ðr"   )r@   r�   rÏ   rû   rÿ   r   rö   rþ   rù   rø   rü   r÷   rñ   rt   rv   s   @@r   ró   ró   h  s   ù‡ € ñ÷g÷@ò r"   ró   c                   óD   a a€ ] tR tRt oV 3R ltV3R lR ltRtVtV ;t# )ÚFocalNetStagei­  c                óò  <€ \         SV `  4        Wn        \        VP                  4      V n        \        V P
                  4       Uu. uF  qAP                  ^V,          ,          NK  	  ppWR,          pW P
                  ^,
          8  d   WR^,           ,          MRpW P
                  ^,
          8  d   \        MRp\        P                  ! ^ VP                  \        VP                  4      RR7       U	u. uF  q™P                  4       NK  	  p
p	V
\        VP                  RV 4      \        VP                  RV^,            4       p\        P                  ! \        VP                  V,          4       Uu. uF1  p\!        TTTT\#        V\$        4      '       d	   W´,          MTR7      NK3  	  up4      V n        Ve!   V! VV^VVRVP(                  RR7      V n        MRV n        RV n        R# u upi u up	i u upi )r   NÚcpu)rá   )r@   r³   r�   rö   rû   TF)r@   rA   rB   rC   rD   r„   rE   rF   )rI   rJ   r@   ÚlenÚdepthsÚ
num_stagesr¯   rD   rK   r   ÚlinspaceÚdrop_path_rateÚsumÚitemr   r¬   ró   r}   ÚlistÚlayersrE   Ú
downsampleÚpointing)rX   r@   r³   rö   ÚirD   r�   Úout_dimr  r½   Údprrû   rZ   s   &&&&        €r   rJ   ÚFocalNetStage.__init__®  s°  ø€ Ü‰ÑÔàŒÜ˜fŸm™mÓ,ˆŒä8=¸d¿o¹oÔ8NÓOÑ8N°1×%Ñ%¨¨A­×.Ð.Ñ8Nˆ	ÐOØÕˆØ+0·?±?ÀQÕ3FÔ+F�) A�IÖ&ÈTˆØ16¿¹È1Õ9LÔ1LÕ,ÐSWˆ
ô "'§¢°°6×3HÑ3HÌ#ÈfÏmÉmÓJ\ÐejÕ!kÓlÑ!k˜A�v‰vŽxÑ!kˆÐlØœ˜FŸM™M¨&¨5Ð1Ó2´S¸¿¹À{ÈÐQRÍÐ9SÓ5TÐUˆ	ä—m’mô ˜vŸ}™}¨UÕ3Ô4ó	ñ 5�Aô Ø!ØØØ%5Ü.8¸ÄD×.IÒ.I˜ižlÈy÷ñ 5ñ	ó
ˆŒð Ò!Ù(ØØ+ØØ Ø!ØØ%×4Ñ4Øô	ˆD�Oð #ˆDŒOàˆŽùòI Pùò mùò	s   Á"G*Ã3G/Å37G4c                óz   <€ V ^8„  d   QhRS[ P                  RS[S[S[3,          RS[S[ P                  ,          /# )r   r   r  r_   )r   ra   r   r�   )r   r   s   "€r   r    ÚFocalNetStage.__annotate__Ú  s<   ø€ ÷ ñ ¡U§\¡\ð ÁUÉ3ÑPSÈ8Å_ð ÑY^Ñ_d×_kÑ_kÕYlñ r"   c                ó  € Vw  r4V P                    F  pV! W4      pK  	  TpV P                  eM   Vw  r4VP                  ^^4      P                  VP                  ^ ,          RW44      pV P                  V4      w  rMW4W43pWV3pV# )Nre   )r  r  r–   Úreshaper“   )	rX   r   r  rŠ   r‹   Úlayer_moduleÚ!hidden_states_before_downsamplingrk   Ústage_outputss	   &&&      r   rq   ÚFocalNetStage.forwardÚ  s�   € Ø(‰ˆØ ŸKœKˆLÙ(¨ÓIŠMñ (ð -:Ð)Ø�?‰?Ò&Ø,‰MˆFØ)×3Ñ3°A°qÓ9×AÑAØ1×7Ñ7¸Õ:¸BÀóˆMð 04¯©¸}Ó/MÑ,ˆMÐ,ð "(°Ð >Ðà&ÐK\Ð]ˆàÐr"   )r@   r  r  r  r  rÈ   rv   s   @@r   r  r  ­  s   ù‡ € õ*÷X÷ ð r"   r  c                   óH   a a€ ] tR tRt oV 3R ltRV3R lR lltRtVtV ;t# )ÚFocalNetEncoderiï  c                óh  <€ \         SV `  4        \        VP                  4      V n        Wn        \        P                  ! \        V P                  4       Uu. uF=  p\        VVV^ ,          ^V,          ,          V^,          ^V,          ,          3R7      NK?  	  up4      V n
        RV n        R# u upi )é    )r@   r³   rö   FN)rI   rJ   r  r  r  r@   r   r¬   r¯   r  ÚstagesÚgradient_checkpointing)rX   r@   rM   Úi_layerrZ   s   &&& €r   rJ   ÚFocalNetEncoder.__init__ð  sœ   ø€ Ü‰ÑÔÜ˜fŸm™mÓ,ˆŒØŒä—m’mô  % T§_¡_Ô5óñ  6�Gô Ø!Ø!Ø&/°¥l°q¸'µzÕ&BÀIÈaÅLÐUVÐX_ÕU_ÕD`Ð%a÷ñ
  6ñó	
ˆŒð ',ˆÖ#ùòs   ÁAB/c                ó¢   <€ V ^8„  d   QhRS[ P                  RS[S[S[3,          RS[R,          RS[R,          RS[R,          RS[S[,          /# )r   r   r  Úoutput_hidden_statesNÚ(output_hidden_states_before_downsamplingÚreturn_dictr_   )r   ra   r   r�   Úboolr   )r   r   s   "€r   r    ÚFocalNetEncoder.__annotate__  se   ø€ ÷ 5
ñ 5
á—|‘|ð5
ñ  ¡¡S �/ð5
ñ # T�kð	5
ñ
 37¸µ+ð5
ñ ˜D•[ð5
ñ 
Ñ&Õ	&ñ5
r"   c                ó¢  € V'       d   RMR pV'       d   RMR pV'       dL   VP                   w  r‰p
VP                  ! V.VOV
N5!  pVP                  ^ ^^^4      pWa3,          pW{3,          p\        V P                  4       EF  w  rÍV! W4      pV^ ,          pV^,          pV^,          pVR,          VR,          3pV'       df   V'       d^   VP                   w  r‰p
VP                  ! V.V^ ,          V^,          3OV
N5!  pVP                  ^ ^^^4      pWo3,          pW{3,          pK¨  V'       g   K²  V'       d   K¼  VP                   w  r‰p
VP                  ! V.VOV
N5!  pVP                  ^ ^^^4      pWa3,          pW{3,          pEK
  	  V'       g/   \
        ;QJ d    . R W3 4       F  NK  	  5# ! R W3 4       4      # \        VVVR7      # )Nc              3   ó0   "  € T F  qf   K  Vx € K  	  R # 5irs   r#   )Ú.0Úvs   & r   Ú	<genexpr>Ú*FocalNetEncoder.forward.<locals>.<genexpr>1  s   é € ÐXÑ$F˜qŸšÓ$Fùs   ‚Œ
)r   r   r   r#   éþÿÿÿre   )r“   r  r¸   Ú	enumerater*  r   r   )rX   r   r  r/  r0  r1  Úall_hidden_statesÚall_reshaped_hidden_statesrl   rn   Úhidden_sizeÚreshaped_hidden_stater  Ústage_moduler$  r#  rk   s   &&&&&&           r   rq   ÚFocalNetEncoder.forward  sõ  € ÷ #7™B¸DÐß+?¡RÀTÐ"çØ)6×)<Ñ)<Ñ&ˆJ˜;à$1×$6Ò$6°zÐ$bÐDTÐ$bÐVaÓ$bÐ!Ø$9×$AÑ$AÀ!ÀQÈÈ1Ó$MÐ!ØÐ!1Õ1ÐØ&Ð*BÕBÐ&ä(¨¯©×5‰OˆAÙ(¨ÓIˆMà)¨!Õ,ˆMØ0=¸aÕ0@Ð-Ø -¨aÕ 0Ðà 1°"Õ 5Ð7HÈÕ7LÐMÐç#×(PØ-N×-TÑ-TÑ*�
˜{ð )J×(NÒ(NØð)Ø"3°AÕ"6Ð8IÈ!Õ8LÐ!Mð)ØOZó)Ð%ð )>×(EÑ(EÀaÈÈAÈqÓ(QÐ%Ø!Ð%IÕIÐ!Ø*Ð.FÕFÒ*ß%Ñ%×.VÑ.VØ-:×-@Ñ-@Ñ*�
˜{à(5×(:Ò(:¸:Ð(fÐHXÐ(fÐZeÓ(fÐ%Ø(=×(EÑ(EÀaÈÈAÈqÓ(QÐ%Ø!Ð%5Õ5Ð!Ø*Ð.FÕFÓ*ñ3  6÷6 ß”5ÑX ]Ñ$FÓX—5ÐX�5ÑX ]Ñ$FÓXÓXÐXä$Ø+Ø+Ø#=ô
ð 	
r"   )r@   r+  r  r*  )FFTrÈ   rv   s   @@r   r'  r'  ï  s   ù‡ € õ,÷$5
÷ 5
ò 5
r"   r'  c                   óx   a a€ ] tR tRt oRtRtRtR.t]P                  ! 4       V 3R l4       t
V3R ltRtVtV ;t# )	ÚFocalNetPreTrainedModeli:  Úfocalnetr]   Tr  c                óö  <€ \         SV `  V4       \        V\        4      '       d3   VP                  e#   \
        P                  ! VP                  4       R# R# \        V\        4      '       d‹   V P                  P                  '       dm   \
        P                  ! VP                  V P                  P                  4       \
        P                  ! VP                  V P                  P                  4       R# R# R# )zInitialize the weightsN)rI   Ú_init_weightsr}   r>   rQ   ÚinitÚzeros_ró   r@   r  Ú	constant_rÿ   r  r   )rX   ÚmodulerZ   s   &&€r   rF  Ú%FocalNetPreTrainedModel._init_weightsB  s¢   ø€ ô 	‰Ñ˜fÔ%Ü�fÔ0×1Ò1Ø× Ñ Ò,Ü—’˜F×-Ñ-Ö.ñ -ä˜¤×.Ò.Ø�{‰{×)×)Ð)Ü—’˜vŸ~™~¨t¯{©{×/KÑ/KÔLÜ—’˜vŸ~™~¨t¯{©{×/KÑ/KÖLñ *ñ /r"   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # ©r   r@   r   )r   r   s   "€r   r    Ú$FocalNetPreTrainedModel.__annotate__:  s   ø‡ ‚ áÑò r"   r#   )r$   r%   r&   r'   Úbase_model_prefixÚmain_input_nameÚsupports_gradient_checkpointingÚ_no_split_modulesr   Úno_gradrF  r)   r*   r+   ru   rv   s   @@r   rC  rC  :  sB   ù‡ € ð #ÐØ$€OØ&*Ð#Ø(Ð)Ðà
‡]‚]ƒ_ô	Mó ð	M÷ … r"   rC  c                   ó\   a a€ ] tR tRt oRV 3R lltR t]RV3R lR ll4       tRtVt	V ;t
# )	ÚFocalNetModeliO  c                ó  <€ \         SV `  V4       Wn        \        VP                  4      V n        \        VP                  ^V P
                  ^,
          ,          ,          4      V n        \        WR7      V n
        \        WP                  P                  4      V n        \        P                  ! V P                  VP                   R7      V n        V'       d   \        P$                  ! ^4      MRV n        V P)                  4        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.
)rY   rG   N)rI   rJ   r@   r  r  r  r�   rD   Únum_featuresr>   rj   r'  rN   Úencoderr   rR   rS   r²   ÚAdaptiveAvgPool1dÚpoolerÚ	post_init)rX   r@   Úadd_pooling_layerrY   rZ   s   &&&&€r   rJ   ÚFocalNetModel.__init__Q  s¯   ø€ ô 	‰Ñ˜Ô ØŒÜ˜fŸm™mÓ,ˆŒÜ × 0Ñ 0°1¸¿¹È1Õ9LÕ3MÕ MÓNˆÔä,¨VÔSˆŒÜ& v¯©×/IÑ/IÓJˆŒäŸš d×&7Ñ&7¸V×=RÑ=RÔSˆŒß1B”b×*Ò*¨1Ô-ÈˆŒð 	�‰Ör"   c                ó.   € V P                   P                  # rs   )rj   rL   rî   s   &r   Úget_input_embeddingsÚ"FocalNetModel.get_input_embeddingsf  s   € Ø�‰×/Ñ/Ð/r"   c                ó¨   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          RS[S[,          /# ©r   r]   Nr^   r/  r1  r_   )r   r   r`   r2  r   r.   )r   r   s   "€r   r    ÚFocalNetModel.__annotate__j  sa   ø€ ÷ /
ñ /
á×'Ñ'¨$Õ.ð/
ñ ×)Ñ)¨DÕ0ð/
ñ # T�kð	/
ñ
 ˜D•[ð/
ñ 
Ñ$Õ	$ñ/
r"   c                ó"  € Ve   TMV P                   P                  pVe   TMV P                   P                  pVf   \        R4      hV P	                  WR7      w  rgV P                  VVVVR7      pV^ ,          p	V P                  V	4      p	Rp
V P                  e9   V P                  V	P                  ^^4      4      p
\        P                  ! V
^4      p
V'       g   Wš3VR,          ,           pV# \        V	V
VP                  VP                  R7      # )z§
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).
Nz You have to specify pixel_values)r^   ©r/  r1  :ry   NN)r   r0   r   r   )r@   r/  r1  r”   rj   rX  r²   rZ  r–   r   r•   r.   r   r   )rX   r]   r^   r/  r1  ÚkwargsÚembedding_outputr  Úencoder_outputsÚsequence_outputÚpooled_outputÚoutputs   &&&&&,      r   rq   ÚFocalNetModel.forwardi  s  € ð %9Ò$DÑ È$Ï+É+×JjÑJjð 	ð &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆàÒÜÐ?Ó@Ð@à-1¯_©_¸\¨_Ó-kÑ*ÐàŸ,™,ØØØ!5Ø#ð	 'ó 
ˆð *¨!Õ,ˆØŸ.™.¨Ó9ˆàˆØ�;‰;Ò"Ø ŸK™K¨×(AÑ(AÀ!ÀQÓ(GÓHˆMÜ!ŸMšM¨-¸Ó;ˆMçØ%Ð5¸ÈÕ8KÕKˆFàˆMä"Ø-Ø'Ø)×7Ñ7Ø#2×#IÑ#Iô	
ð 	
r"   )r@   rj   rX  r²   rW  r  rZ  )TF©NNNN)r$   r%   r&   r'   rJ   r_  r   rq   r*   r+   ru   rv   s   @@r   rU  rU  O  s-   ù‡ € ÷ò*0ð ÷/
ñ /
ó ÷/
ð /
r"   rU  a‰  
    FocalNet Model with a decoder on top for masked image modeling.

    This follows the same implementation as in [SimMIM](https://huggingface.co/papers/2111.09886).

    <Tip>

    Note that we provide a script to pre-train this model on custom data in our [examples
    directory](https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-pretraining).

    </Tip>
    c                   óR   a a€ ] tR tRt oV 3R lt]RV3R lR ll4       tRtVtV ;t	# )ÚFocalNetForMaskedImageModelingiœ  c                óì  <€ \         SV `  V4       \        VR RR7      V n        \	        VP
                  4      V n        \        VP                  ^V P                  ^,
          ,          ,          4      p\        P                  ! \        P                  ! W!P                  ^,          VP                  ,          ^R7      \        P                  ! VP                  4      4      V n        V P!                  4        R# )FT)r\  rY   )Úin_channelsÚout_channelsrz   N)rI   rJ   rU  rD  r  r  r  r�   rD   r   r±   r‚   Úencoder_striderC   ÚPixelShuffleÚdecoderr[  )rX   r@   rW  rZ   s   && €r   rJ   Ú'FocalNetForMaskedImageModeling.__init__«  s­   ø€ Ü‰Ñ˜Ô ä% fÀÐVZÔ[ˆŒä˜fŸm™mÓ,ˆŒÜ˜6×+Ñ+¨a°D·O±OÀaÕ4GÕ.HÕHÓIˆÜ—}’}Ü�IŠIØ(×7LÑ7LÈaÕ7OÐRX×ReÑReÕ7eÐstôô �OŠO˜F×1Ñ1Ó2ó	
ˆŒð 	�‰Ör"   c                ó¨   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          RS[S[,          /# rb  )r   r   r`   r2  r   r3   )r   r   s   "€r   r    Ú+FocalNetForMaskedImageModeling.__annotate__½  sh   ø€ ÷ O
ñ O
á×'Ñ'¨$Õ.ðO
ñ ×)Ñ)¨DÕ0ðO
ñ # T�kð	O
ñ
 ˜D•[ðO
ñ 
Ñ2Õ	2ñO
r"   c                ó  € Ve   TMV P                   P                  pV P                  VVVVR7      pV^ ,          pVP                  ^^4      pVP                  w  r‰p
\
        P                  ! V
R,          4      ;r¼V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'       g"   V3VR,          ,           pVe   V3V,           # T# \'        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, FocalNetConfig, FocalNetForMaskedImageModeling
>>> import torch
>>> from PIL import Image
>>> import httpx
>>> from io import BytesIO

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))

>>> image_processor = AutoImageProcessor.from_pretrained("microsoft/focalnet-base-simmim-window6-192")
>>> config = FocalNetConfig()
>>> model = FocalNetForMaskedImageModeling(config)

>>> 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.logits
>>> list(reconstructed_pixel_values.shape)
[1, 3, 192, 192]
```N)r^   r/  r1  g      à?Únone)Ú	reductiongñhãˆµøä>ºr   NN)r5   r6   r   r   re   )r@   r1  rD  r–   r“   Úmathrå   r!  ru  rA   rB   Úrepeat_interleaverh   r¹   r   rˆ   Úl1_lossr  rC   r3   r   r   )rX   r]   r^   r/  r1  rf  Úoutputsri  rl   rC   Úsequence_lengthrŠ   r‹   Úreconstructed_pixel_valuesÚmasked_im_lossrf   rp   Úreconstruction_lossrk  s   &&&&&,             r   rq   Ú&FocalNetForMaskedImageModeling.forward¼  sÆ  € ðN &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆà—-‘-ØØ+Ø!5Ø#ð	  ó 
ˆð " !�*ˆà)×3Ñ3°A°qÓ9ˆØ4C×4IÑ4IÑ1ˆ
 /ÜŸš O°SÕ$8Ó9Ð9ˆØ)×1Ñ1°*ÈFÓZˆð &*§\¡\°/Ó%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çØ0Ð2°W¸Rµ[Õ@ˆFØ3AÒ3M�^Ð%¨Õ.ÐYÐSYÐYä0ØØ5Ø!×/Ñ/Ø#*×#AÑ#Aô	
ð 	
r"   )ru  rD  r  rm  ©
r$   r%   r&   r'   rJ   r   rq   r*   r+   ru   rv   s   @@r   ro  ro  œ  s,   ù‡ € õð" ÷O
ñ O
ó ÷O
ð O
r"   ro  z…
    FocalNet Model with an image classification head on top (a linear layer on top of the pooled output) e.g. for
    ImageNet.
    c                   óR   a a€ ] tR tRt oV 3R lt]RV3R lR ll4       tRtVtV ;t	# )ÚFocalNetForImageClassificationi  c                óH  <€ \         SV `  V4       VP                  V n        \        V4      V n        VP                  ^ 8”  d6   \
        P                  ! V P                  P                  VP                  4      M\
        P                  ! 4       V n	        V P                  4        R# )r)  N)rI   rJ   Ú
num_labelsrU  rD  r   r¥   rW  rú   Ú
classifierr[  ©rX   r@   rZ   s   &&€r   rJ   Ú'FocalNetForImageClassification.__init__  sx   ø€ Ü‰Ñ˜Ô à ×+Ñ+ˆŒÜ% fÓ-ˆŒð IO×HYÑHYÐ\]ÔH]ŒB�IŠI�d—m‘m×0Ñ0°&×2CÑ2CÔDÔce×cnÒcnÓcpð 	Œð
 	�‰Ör"   c                ó¨   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          RS[S[,          /# )r   r]   NÚlabelsr/  r1  r_   )r   r   Ú
LongTensorr2  r   r9   )r   r   s   "€r   r    Ú+FocalNetForImageClassification.__annotate__&  sa   ø€ ÷ '
ñ '
á×'Ñ'¨$Õ.ð'
ñ × Ñ  4Õ'ð'
ñ # T�kð	'
ñ
 ˜D•[ð'
ñ 
Ñ.Õ	.ñ'
r"   c                ór  € Ve   TMV P                   P                  pV P                  VVVR7      pV^,          pV P                  V4      pRp	Ve   V P	                  W(V P                   4      p	V'       g"   V3VR,          ,           p
V	e   V	3V
,           # T
# \        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).
Nre  r|  )r5   r;   r   r   )r@   r1  rD  r‹  Úloss_functionr9   r   r   )rX   r]   r�  r/  r1  rf  r€  rj  r;   r5   rk  s   &&&&&,     r   rq   Ú&FocalNetForImageClassification.forward%  s¿   € ð &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆà—-‘-ØØ!5Ø#ð  ó 
ˆð   �
ˆà—‘ Ó/ˆàˆØÒØ×%Ñ% f°d·k±kÓBˆDçØ�Y ¨¥Õ,ˆFØ)-Ò)9�T�G˜fÕ$ÐE¸vÐEä,ØØØ!×/Ñ/Ø#*×#AÑ#Aô	
ð 	
r"   )r‹  rD  rŠ  rm  r†  rv   s   @@r   rˆ  rˆ    s(   ù‡ € õð ÷'
ñ '
ó ÷'
ð '
r"   rˆ  zG
    FocalNet backbone, to be used with frameworks like X-Decoder.
    c                   óv   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4       4       4       t	Rt
VtV ;t# )	ÚFocalNetBackboneiP  Fc                ó    <€ V ^8„  d   QhRS[ /# rM  r   )r   r   s   "€r   r    ÚFocalNetBackbone.__annotate__X  s   ø€ ÷ ñ ™~ñ r"   c                ó¬   <€ \         SV `  V4       VP                  .VP                  ,           V n        \        V4      V n        V P                  4        R # rs   )rI   rJ   rD   Úhidden_sizesrW  rU  rD  r[  rŒ  s   &&€r   rJ   ÚFocalNetBackbone.__init__X  sD   ø€ Ü‰Ñ˜Ô à#×-Ñ-Ð.°×1DÑ1DÕDˆÔÜ% fÓ-ˆŒð 	�‰Ör"   c                ób   <€ V ^8„  d   QhRS[ P                  RS[R,          RS[R,          RS[/# )r   r]   r/  Nr1  r_   )r   ra   r2  r	   )r   r   s   "€r   r    r˜  d  s?   ø€ ÷ 3
ñ 3
á—l‘lð3
ñ # T�kð3
ñ ˜D•[ð	3
ñ 
ñ3
r"   c                óÖ  € Ve   TMV P                   P                  pVe   TMV P                   P                  pV P                  VRRR7      pVP                  pRp\        V P                  4       F'  w  r‰W�P                  9   g   K  WvV,          3,          pK)  	  V'       g!   V3p
V'       d   W¥P                  3,          p
V
# \        TV'       d   VP                  RR7      # RRR7      # )aC  
Examples:

```python
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> import torch
>>> from PIL import Image
>>> import httpx
>>> from io import BytesIO

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))

>>> processor = AutoImageProcessor.from_pretrained("microsoft/focalnet-tiny-lrf")
>>> model = AutoBackbone.from_pretrained("microsoft/focalnet-tiny-lrf")

>>> inputs = processor(image, return_tensors="pt")
>>> outputs = model(**inputs)
```NTre  )Úfeature_mapsr   Ú
attentionsr#   )
r@   r1  r/  rD  r   r;  Ústage_namesrÒ   r   r	   )rX   r]   r/  r1  rf  r€  r   rž  ÚidxÚstagerk  s   &&&&,      r   rq   ÚFocalNetBackbone.forwarda  sá   € ð< &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆà$8Ò$DÑ È$Ï+É+×JjÑJjð 	ð —-‘- À4ÐUY�-ÓZˆà×6Ñ6ˆàˆÜ# D×$4Ñ$4Ö5‰JˆCØ×)Ñ)Ö)Ø¨sÕ!3Ð 5Õ5’ñ 6÷ Ø"�_ˆFß#Ø×0Ñ0Ð2Õ2�ØˆMäØ%ß3G˜'×/Ñ/Øô
ð 	
àMQØô
ð 	
r"   )rD  rW  )NN)r$   r%   r&   r'   Úhas_attentionsrJ   r   r   r   rq   r*   r+   ru   rv   s   @@r   r–  r–  P  sD   ù‡ € ð €N÷ó ð Ø Ø÷3
ñ 3
ó ó !ó ÷3
ð 3
r"   r–  )rˆ  ro  r–  rU  rC  )4r(   Úcollections.abcr~   r}  Údataclassesr   r   r   Ú r   rG  Úactivationsr   Úbackbone_utilsr   r   Úmodeling_layersr   Úmodeling_outputsr	   Úmodeling_utilsr
   Úutilsr   r   r   Úutils.genericr   Úconfiguration_focalnetr   Ú
get_loggerr$   Úloggerr   r.   r3   r9   ÚModuler>   rK   r™   rÊ   r×   ró   r  r'  rC  rU  ro  rˆ  r–  Ú__all__r#   r"   r   Ú<module>r´     s^  ðñ ã Û Ý !ã Ý å &Ý !ß HÝ 9Ý .Ý -ß 9Ñ 9Ý -Ý 2ð 
×	Ò	˜HÓ	%€ñ ðôð
 ôC˜Kó Có óðCñ ðôð
 ôC˜+ó Có óðCñ$ ðôð
 ôC¨ó Có óðCñ( ðôð
 ôC Kó Có óðCô(%-˜Ÿ™ô %-ôPD-˜bŸi™iô D-ôND˜Ÿ™ô DôN�"—)‘)ô ô(%�r—y‘yô %ô0B�B—I‘Iô BôJ?Ð.ô ?ôDH
�b—i‘iô H
ðV ôM˜oó Mó ðMð( ôI
Ð+ó I
ó ðI
ñX ðôôb
Ð%<ó b
óðb
ñJ ðôô8
Ð%<ó 8
óð8
ñv ðôô
B
�}Ð&=ó B
óð
B
òJ‚r"   