Ë
    T^(hpõ  ã                   óØ  — d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	 d dl
Zd dlZd dlmZ d dlmc mZ d dlmZmZmZ d dlmZ ddlmZ ddlmZ dd	lmZmZmZ dd
lm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,  e'jZ                  e.«      Z/dZ0e G d„ de#«      «       Z1e G d„ de#«      «       Z2e G d„ de#«      «       Z3 G d„ dejh                  «      Z5	 dLdejh                  dejl                  dejl                  dejl                  deejl                     de7de7fd„Z8 G d„ d ejh                  «      Z9 G d!„ d"ejh                  «      Z: G d#„ d$ejh                  «      Z; G d%„ d&ejh                  «      Z<d'Z= G d(„ d)ejh                  «      Z> G d*„ d+ejh                  «      Z?d,„ Z@	 dMd-ejl                  d.e7d/e7d0e7d1e7d2ejl                  fd3„ZAdNd4„ZBd5„ ZCd6„ ZDd7ZE G d8„ d9ejh                  «      ZFd:ZGd;ZH G d<„ d=e!«      ZI e$d>eG«       G d?„ d@eI«      «       ZJ G dA„ dBejh                  «      ZK e$dCeG«       G dD„ dEeI«      «       ZL e$eG«       G dF„ dGeI«      «       ZM e$dHeG«       G dI„ dJeI«      «       ZNg dK¢ZOy)Oé    N)Ú	dataclass)ÚAnyÚCallableÚOptionalÚTupleÚUnion)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELoss)Ú_calculate_fan_in_and_fan_outé   )ÚACT2FN)Ú_prepare_4d_attention_mask)ÚBaseModelOutputÚBaseModelOutputWithPoolingÚImageClassifierOutput)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚModelOutputÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚcan_return_tupleÚloggingÚreplace_return_docstringsé   )ÚSiglip2ConfigÚSiglip2TextConfigÚSiglip2VisionConfigr   c                   óÆ   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                  df      ed<   dZeeej                  df      ed<   y)ÚSiglip2VisionOutputaÝ  
    Base class for vision model's outputs that also contains image embeddings of the pooling of the last hidden states.

    Args:
        image_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim)` *optional* returned when model is initialized with `with_projection=True`):
            The image embeddings obtained by applying the projection layer to the pooler_output.
        last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the model.
        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, if the model has an embedding layer, +
            one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    NÚimage_embedsÚlast_hidden_state.Úhidden_statesÚ
attentions)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r   ÚtorchÚFloatTensorÚ__annotations__r"   r#   r   r$   © ó    új/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/siglip2/modeling_siglip2.pyr    r    6   sr   … ñð* 15€L�(˜5×,Ñ,Ñ-Ó4Ø59Ð�x × 1Ñ 1Ñ2Ó9Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>r-   r    c                   óÆ   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                  df      ed<   dZeeej                  df      ed<   y)ÚSiglip2TextOutputaÃ  
    Base class for text model's outputs that also contains a pooling of the last hidden states.

    Args:
        text_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim)` *optional* returned when model is initialized with `with_projection=True`):
            The text embeddings obtained by applying the projection layer to the pooler_output.
        last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the model.
        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, if the model has an embedding layer, +
            one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    NÚtext_embedsr"   .r#   r$   )r%   r&   r'   r(   r1   r   r)   r*   r+   r"   r#   r   r$   r,   r-   r.   r0   r0   S   sr   … ñð* 04€K�˜%×+Ñ+Ñ,Ó3Ø59Ð�x × 1Ñ 1Ñ2Ó9Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>r-   r0   c                   ó  — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eej                     ed<   dZeej                     ed<   dZeej                     ed<   dZeed<   dZeed	<   d
ee   fd„Zy)ÚSiglip2Outputaÿ  
    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `return_loss` is `True`):
            Contrastive loss for image-text similarity.
        logits_per_image (`torch.FloatTensor` of shape `(image_batch_size, text_batch_size)`):
            The scaled dot product scores between `image_embeds` and `text_embeds`. This represents the image-text
            similarity scores.
        logits_per_text (`torch.FloatTensor` of shape `(text_batch_size, image_batch_size)`):
            The scaled dot product scores between `text_embeds` and `image_embeds`. This represents the text-image
            similarity scores.
        text_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim`):
            The text embeddings obtained by applying the projection layer to the pooled output of [`Siglip2TextModel`].
        image_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim`):
            The image embeddings obtained by applying the projection layer to the pooled output of [`Siglip2VisionModel`].
        text_model_output (`BaseModelOutputWithPooling`):
            The output of the [`Siglip2TextModel`].
        vision_model_output (`BaseModelOutputWithPooling`):
            The output of the [`Siglip2VisionModel`].
    NÚlossÚlogits_per_imageÚlogits_per_textr1   r!   Útext_model_outputÚvision_model_outputÚreturnc                 óH   ‡ — t        ˆ fd„‰ j                  «       D «       «      S )Nc              3   ód   •K  — | ]'  }|d vr‰|   nt        ‰|«      j                  «       –— Œ) y­w))r7   r8   N)ÚgetattrÚto_tuple)Ú.0ÚkÚselfs     €r.   ú	<genexpr>z)Siglip2Output.to_tuple.<locals>.<genexpr>�   s=   øè ø€ ò 
àð Ð LÑLˆD�ŠGÔRYÐZ^Ð`aÓRb×RkÑRkÓRmÓmñ
ùs   ƒ-0)ÚtupleÚkeys©r@   s   `r.   r=   zSiglip2Output.to_tupleŽ   s#   ø€ Üó 
à—Y‘Y“[ô
ó 
ð 	
r-   )r%   r&   r'   r(   r4   r   r)   r*   r+   r5   r6   r1   r!   r7   r   r8   r   r   r=   r,   r-   r.   r3   r3   p   s›   … ñð( )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø48Ð�h˜u×0Ñ0Ñ1Ó8Ø37€O�X˜e×/Ñ/Ñ0Ó7Ø/3€K�˜%×+Ñ+Ñ,Ó3Ø04€L�(˜5×,Ñ,Ñ-Ó4Ø48ÐÐ1Ó8Ø6:ÐÐ3Ó:ð
˜% ™*ô 
r-   r3   c            	       óÒ   ‡ — e Zd Zdefˆ fd„Zedej                  dej                  de	dej                  fd„«       Z
dej                  dej                  dej                  fd	„Zˆ xZS )
ÚSiglip2VisionEmbeddingsÚconfigc                 óÂ  •— t         ‰| �  «        || _        |j                  | _        |j
                  | _        t        j                  |j                  | j
                  z  | j
                  z  | j                  ¬«      | _	        |j                  | _
        t        | j                  dz  «      | _        t        j                  | j                  | j                  «      | _        y )N)Úin_featuresÚout_featuresg      à?)ÚsuperÚ__init__rG   Úhidden_sizeÚ	embed_dimÚ
patch_sizeÚnnÚLinearÚnum_channelsÚpatch_embeddingÚnum_patchesÚintÚposition_embedding_sizeÚ	EmbeddingÚposition_embedding©r@   rG   Ú	__class__s     €r.   rL   z Siglip2VisionEmbeddings.__init__–   s§   ø€ Ü‰ÑÔØˆŒØ×+Ñ+ˆŒØ ×+Ñ+ˆŒä!Ÿy™yØ×+Ñ+¨d¯o©oÑ=ÀÇÁÑOØŸ™ô 
ˆÔð
 "×-Ñ-ˆÔÜ'*¨4×+;Ñ+;¸SÑ+@Ó'AˆÔ$Ü"$§,¡,¨t×/?Ñ/?ÀÇÁÓ"PˆÕr-   Úpositional_embeddingsÚspatial_shapesÚ
max_lengthr9   c                 ób  — |j                   d   }| j                   d   }| j                  }t        j                  |||f| j                  |¬«      }| j                  ddd«      j                  d«      } | j                  j                  dk(  r| j                  t        j                  «      } t        |«      D ]w  }||   \  }}	t        j                  | ||	fddd	¬
«      }
|
j                  |||	z  «      j                  dd«      }
|
j                  |«      }
|
||d||	z  …f<   |
d   ||||	z  d…f<   Œy |S )ac  
        Resize positional embeddings to image-specific size and pad to a fixed size.

        Args:
            positional_embeddings (`torch.Tensor`):
                Position embeddings of shape (height, width, embed_dim)
            spatial_shapes (`torch.LongTensor`):
                Spatial shapes of shape (batch_size, 2) to resize the positional embeddings to
            max_length (`int`):
                Maximum length of the positional embeddings to pad resized positional embeddings to

        Returns:
            `torch.Tensor`: Embeddings of shape (batch_size, max_length, embed_dim)
        r   éÿÿÿÿ)ÚdeviceÚdtypeé   r   ÚcpuÚbilinearFT)ÚsizeÚmodeÚalign_cornersÚ	antialiasN)Úshapera   r)   Úemptyr`   ÚpermuteÚ	unsqueezeÚtypeÚtoÚfloat32ÚrangeÚFÚinterpolateÚreshapeÚ	transpose)r[   r\   r]   Ú
batch_sizerN   Úsource_dtypeÚresulted_positional_embeddingsÚiÚheightÚwidthÚresized_embeddingss              r.   Úresize_positional_embeddingsz4Siglip2VisionEmbeddings.resize_positional_embeddings¥   sc  € ð( $×)Ñ)¨!Ñ,ˆ
Ø)×/Ñ/°Ñ3ˆ	Ø,×2Ñ2ˆä).¯©Ø˜ YÐ/Ø(×/Ñ/Øô*
Ð&ð !6× =Ñ =¸aÀÀAÓ F× PÑ PÐQRÓ SÐð !×'Ñ'×,Ñ,°Ò5Ø$9×$<Ñ$<¼U¿]¹]Ó$KÐ!ä�zÓ"ò 	XˆAà*¨1Ñ-‰MˆF�EÜ!"§¡Ø%Ø˜e�_ØØ#Øô"Ðð "4×!;Ñ!;¸IÀvÐPUÁ~Ó!V×!`Ñ!`ÐabÐdeÓ!fÐð "4×!6Ñ!6°|Ó!DÐàBTÐ*¨1Ð.>°¸±Ð.>Ð+>Ñ?ØBTÐUVÑBWÐ*¨1¨f°u©nÑ.>Ð+>Ò?ð%	Xð( .Ð-r-   Úpixel_valuesc                 óJ  — | j                   j                  j                  }| j                  |j                  |¬«      «      }| j                  j                  j                  | j                  | j                  d«      }| j                  |||j                  d   ¬«      }||z   }|S )aH  
        Args:
            pixel_values (`torch.FloatTensor`):
                Pixel values of shape (batch_size, max_num_patches, num_channels * patch_size * patch_size)
            spatial_shapes (`List[Tuple[int, int]]`):
                Spatial shapes of shape (batch_size, 2) to resize the positional embeddings to
        )ra   r_   r   )r]   )	rS   Úweightra   rn   rX   rs   rV   r|   ri   )r@   r}   r\   Útarget_dtypeÚpatch_embedsr[   Úresized_positional_embeddingsÚ
embeddingss           r.   ÚforwardzSiglip2VisionEmbeddings.forwardà   s§   € ð ×+Ñ+×2Ñ2×8Ñ8ˆØ×+Ñ+¨L¯O©OÀ,¨OÓ,OÓPˆð !%× 7Ñ 7× >Ñ >× FÑ FØ×(Ñ(¨$×*FÑ*FÈó!
Ðð )-×(IÑ(IØ! >¸l×>PÑ>PÐQRÑ>Sð )Jó )
Ð%ð
 "Ð$AÑAˆ
ØÐr-   )r%   r&   r'   r   rL   Ústaticmethodr)   ÚTensorÚ
LongTensorrU   r|   r*   r„   Ú__classcell__©rZ   s   @r.   rF   rF   •   s†   ø„ ðQÐ2õ Qð ð8.Ø$Ÿ|™|ð8.à×(Ñ(ð8.ð ð8.ð 
�‰ò	8.ó ð8.ðt E×$5Ñ$5ð Àu×GWÑGWð Ð\a×\hÑ\h÷ r-   rF   ÚmoduleÚqueryÚkeyÚvalueÚattention_maskÚscalingÚdropoutc                 óÀ  — t        j                  ||j                  dd«      «      |z  }|�||z   }t        j                  j                  |dt         j                  ¬«      j                  |j                  «      }t        j                  j                  ||| j                  ¬«      }t        j                  ||«      }	|	j                  dd«      j                  «       }	|	|fS )Nr_   éþÿÿÿ)Údimra   )ÚpÚtrainingr   rb   )r)   Úmatmulrt   rP   Ú
functionalÚsoftmaxro   rn   ra   r�   r•   Ú
contiguous)
rŠ   r‹   rŒ   r�   rŽ   r�   r�   ÚkwargsÚattn_weightsÚattn_outputs
             r.   Úeager_attention_forwardr�   ú   sº   € ô —<‘<  s§}¡}°R¸Ó'<Ó=ÀÑG€LØÐ!Ø# nÑ4ˆä—=‘=×(Ñ(¨¸2ÄUÇ]Á]Ð(ÓS×VÑVÐW\×WbÑWbÓc€LÜ—=‘=×(Ñ(¨¸È6Ï?É?Ð(Ó[€Lä—,‘,˜|¨UÓ3€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€Kà˜Ð$Ð$r-   c                   ó¼   ‡ — e Zd ZdZdeeef   fˆ fd„Z	 	 d	dej                  de
ej                     de
e   deej                  e
ej                     f   fd„Zˆ xZS )
ÚSiglip2Attentionz=Multi-headed attention from 'Attention Is All You Need' paperrG   c                 ó  •— t         ‰| �  «        || _        |j                  | _        |j
                  | _        | j                  | j                  z  | _        | j                  | j                  z  | j                  k7  r&t        d| j                  › d| j                  › d�«      ‚| j                  dz  | _	        |j                  | _        d| _        t        j                  | j                  | j                  «      | _        t        j                  | j                  | j                  «      | _        t        j                  | j                  | j                  «      | _        t        j                  | j                  | j                  «      | _        y )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).ç      à¿F)rK   rL   rG   rM   rN   Únum_attention_headsÚ	num_headsÚhead_dimÚ
ValueErrorÚscaleÚattention_dropoutr�   Ú	is_causalrP   rQ   Úk_projÚv_projÚq_projÚout_projrY   s     €r.   rL   zSiglip2Attention.__init__  s  ø€ Ü‰ÑÔØˆŒØ×+Ñ+ˆŒØ×3Ñ3ˆŒØŸ™¨$¯.©.Ñ8ˆŒØ�=‰=˜4Ÿ>™>Ñ)¨T¯^©^Ò;ÜØMÈdÏnÉnÐM]ð ^Ø—N‘NÐ# 2ð'óð ð —]‘] DÑ(ˆŒ
Ø×/Ñ/ˆŒØˆŒä—i‘i §¡°·±Ó?ˆŒÜ—i‘i §¡°·±Ó?ˆŒÜ—i‘i §¡°·±Ó?ˆŒÜŸ	™	 $§.¡.°$·.±.ÓAˆ�r-   r#   rŽ   Úoutput_attentionsr9   c           
      ó¤  — |j                   \  }}}| j                  |«      }| j                  |«      }| j                  |«      }	|j	                  ||| j
                  | j                  «      j                  dd«      }|j	                  ||| j
                  | j                  «      j                  dd«      }|	j	                  ||| j
                  | j                  «      j                  dd«      }	t        }
| j                  j                  dk7  rN| j                  j                  dk(  r|rt        j                  d«       nt        | j                  j                     }
 |
| |||	|| j                  | j                  | j                   sdn| j"                  ¬«      \  }}|j%                  |||«      j'                  «       }| j)                  |«      }|sd}||fS )	z#Input shape: Batch x Time x Channelr   rb   ÚeagerÚsdpazã`torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to eager attention. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.ç        )r¨   r�   r�   N)ri   r«   r©   rª   Úviewr£   r¤   rt   r�   rG   Ú_attn_implementationÚloggerÚwarning_oncer   r¨   r¦   r•   r�   rs   r™   r¬   )r@   r#   rŽ   r­   ru   Ú
seq_lengthrN   ÚqueriesrC   ÚvaluesÚattention_interfacerœ   r›   s                r.   r„   zSiglip2Attention.forward(  s”  € ð -:×,?Ñ,?Ñ)ˆ
�J 	à—+‘+˜mÓ,ˆØ�{‰{˜=Ó)ˆØ—‘˜]Ó+ˆà—,‘,˜z¨:°t·~±~ÀtÇ}Á}ÓU×_Ñ_Ð`aÐcdÓeˆØ�y‰y˜ Z°·±ÀÇÁÓO×YÑYÐZ[Ð]^Ó_ˆØ—‘˜Z¨°T·^±^ÀTÇ]Á]ÓS×]Ñ]Ð^_ÐabÓcˆä(?ÐØ�;‰;×+Ñ+¨wÒ6Ø�{‰{×/Ñ/°6Ò9Ñ>OÜ×#Ñ#ðLõô
 '>¸d¿k¹k×>^Ñ>^Ñ&_Ð#á$7ØØØØØØ—n‘nØ—J‘JØ#Ÿ}š}‘C°$·,±,ô	%
Ñ!ˆ�\ð "×)Ñ)¨*°jÀ)ÓL×WÑWÓYˆØ—m‘m KÓ0ˆá ØˆLà˜LÐ(Ð(r-   ©NF)r%   r&   r'   r(   r   r   r   rL   r)   r†   r   Úboolr   r„   rˆ   r‰   s   @r.   rŸ   rŸ     s{   ø„ ÙGðB˜uÐ%8Ð:KÐ%KÑLõ Bð. 26Ø,1ñ	-)à—|‘|ð-)ð ! §¡Ñ.ð-)ð $ D™>ð	-)ð
 
ˆu�|‰|˜X e§l¡lÑ3Ð3Ñ	4÷-)r-   rŸ   c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )Ú
Siglip2MLPc                 ó  •— t         ‰| �  «        || _        t        |j                     | _        t        j                  |j                  |j                  «      | _
        t        j                  |j                  |j                  «      | _        y ©N)rK   rL   rG   r   Ú
hidden_actÚactivation_fnrP   rQ   rM   Úintermediate_sizeÚfc1Úfc2rY   s     €r.   rL   zSiglip2MLP.__init__Y  sd   ø€ Ü‰ÑÔØˆŒÜ# F×$5Ñ$5Ñ6ˆÔÜ—9‘9˜V×/Ñ/°×1IÑ1IÓJˆŒÜ—9‘9˜V×5Ñ5°v×7IÑ7IÓJˆ�r-   r#   r9   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S r¿   )rÃ   rÁ   rÄ   )r@   r#   s     r.   r„   zSiglip2MLP.forward`  s4   € ØŸ™ Ó/ˆØ×*Ñ*¨=Ó9ˆØŸ™ Ó/ˆØÐr-   )r%   r&   r'   rL   r)   r†   r„   rˆ   r‰   s   @r.   r½   r½   X  s$   ø„ ôKð U§\¡\ð °e·l±l÷ r-   r½   c            
       ó’   ‡ — e Zd Zdeeef   fˆ fd„Z	 ddej                  dej                  de	e
   deej                     fd„Zˆ xZS )	ÚSiglip2EncoderLayerrG   c                 óD  •— t         ‰| �  «        |j                  | _        t	        j
                  | j                  |j                  ¬«      | _        t        |«      | _	        t	        j
                  | j                  |j                  ¬«      | _
        t        |«      | _        y )N©Úeps)rK   rL   rM   rN   rP   Ú	LayerNormÚlayer_norm_epsÚlayer_norm1rŸ   Ú	self_attnÚlayer_norm2r½   ÚmlprY   s     €r.   rL   zSiglip2EncoderLayer.__init__h  sm   ø€ Ü‰ÑÔØ×+Ñ+ˆŒÜŸ<™<¨¯©¸F×<QÑ<QÔRˆÔÜ)¨&Ó1ˆŒÜŸ<™<¨¯©¸F×<QÑ<QÔRˆÔÜ˜fÓ%ˆ�r-   r#   rŽ   r­   r9   c                 óÌ   — |}| j                  |«      }| j                  |||¬«      \  }}||z   }|}| j                  |«      }| j                  |«      }||z   }|f}|r||fz  }|S )a=  
        Args:
            hidden_states (`torch.FloatTensor`):
                Input to the layer of shape `(batch, seq_len, embed_dim)`.
            attention_mask (`torch.FloatTensor`):
                Attention mask of shape `(batch, 1, q_len, k_v_seq_len)` where padding elements are indicated by very large negative values.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        )r#   rŽ   r­   )rÍ   rÎ   rÏ   rÐ   )r@   r#   rŽ   r­   Úresidualr›   Úoutputss          r.   r„   zSiglip2EncoderLayer.forwardp  s�   € ð  !ˆà×(Ñ(¨Ó7ˆØ&*§n¡nØ'Ø)Ø/ð '5ó '
Ñ#ˆ�|ð
 ! =Ñ0ˆà ˆØ×(Ñ(¨Ó7ˆØŸ™ Ó/ˆØ  =Ñ0ˆà Ð"ˆáØ˜�Ñ&ˆGàˆr-   )F)r%   r&   r'   r   r   r   rL   r)   r†   r   r»   r   r*   r„   rˆ   r‰   s   @r.   rÇ   rÇ   g  sb   ø„ ð&˜uÐ%8Ð:KÐ%KÑLõ &ð -2ñ	$à—|‘|ð$ð Ÿ™ð$ð $ D™>ð	$ð
 
ˆu× Ñ Ñ	!÷$r-   rÇ   c            
       óx   ‡ — e Zd ZdZdefˆ fd„Ze	 	 	 d	deej                     dee
   dee
   defd„«       Zˆ xZS )
ÚSiglip2Encoderz³
    Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
    [`Siglip2EncoderLayer`].

    Args:
        config: Siglip2Config
    rG   c                 óÐ   •— t         ‰| �  «        || _        t        j                  t        |j                  «      D �cg c]  }t        |«      ‘Œ c}«      | _        d| _	        y c c}w rº   )
rK   rL   rG   rP   Ú
ModuleListrp   Únum_hidden_layersrÇ   ÚlayersÚgradient_checkpointing)r@   rG   Ú_rZ   s      €r.   rL   zSiglip2Encoder.__init__   sP   ø€ Ü‰ÑÔØˆŒÜ—m‘mÌ%ÐPV×PhÑPhÓJiÖ$jÀQÔ%8¸Õ%@Ò$jÓkˆŒØ&+ˆÕ#ùò %ks   ½A#rŽ   r­   Úoutput_hidden_statesr9   c                 óŠ  — |�|n| j                   j                  }|�|n| j                   j                  }|rdnd}|rdnd}|}| j                  D ]]  }|r||fz   }| j                  r+| j
                  r| j                  |j                  |||«      }	n ||||¬«      }	|	d   }|sŒU||	d   fz   }Œ_ |r||fz   }t        |||¬«      S )ad  
        Args:
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
                Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
                This is useful if you want more control over how to convert `input_ids` indices into associated vectors
                than the model's internal embedding lookup matrix.
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

                - 1 for tokens that are **not masked**,
                - 0 for tokens that are **masked**.

                [What are attention masks?](../glossary#attention-mask)
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more detail.
            return_dict (`bool`, *optional*):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        Nr,   )r­   r   r   )r"   r#   r$   )	rG   r­   rÜ   rÙ   rÚ   r•   Ú_gradient_checkpointing_funcÚ__call__r   )
r@   Úinputs_embedsrŽ   r­   rÜ   Úencoder_statesÚall_attentionsr#   Úencoder_layerÚlayer_outputss
             r.   r„   zSiglip2Encoder.forward§  s  € ð< 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ñ  4™¸ˆÙ0™°dˆà%ˆØ!Ÿ[™[ò 	FˆMÙ#Ø!/°=Ð2BÑ!B�Ø×*Ò*¨t¯}ª}Ø $× AÑ AØ!×*Ñ*Ø!Ø"Ø%ó	!‘ñ !.Ø!Ø"Ø&7ô!�ð *¨!Ñ,ˆMâ Ø!/°=ÀÑ3CÐ2EÑ!E‘ð)	Fñ,  Ø+¨}Ð.>Ñ>ˆNäØ+Ø(Ø%ô
ð 	
r-   ©NNN)r%   r&   r'   r(   r   rL   r   r   r)   r†   r»   r   r„   rˆ   r‰   s   @r.   rÕ   rÕ   —  sr   ø„ ñð,˜}õ ,ð ð 26Ø,0Ø/3ñC
ð ! §¡Ñ.ðC
ð $ D™>ð	C
ð
 ' t™nðC
ð 
òC
ó ôC
r-   rÕ   aØ  
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using
            [`AutoImageProcessor`]. See [`CLIPImageProcessor.__call__`] for details.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        interpolate_pos_encoding (`bool`, *optional*, defaults to `False`):
            Whether to interpolate the pre-trained position encodings.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
c                   óÌ   ‡ — e Zd Zdefˆ fd„Ze ee«       ee	e¬«      	 	 dde
j                  de
j                  de
j                  dee   dee   d	e	fd
„«       «       «       Zˆ xZS )ÚSiglip2VisionTransformerrG   c                 ór  •— t         ‰| �  «        || _        |j                  }t	        |«      | _        t        |«      | _        t        j                  ||j                  ¬«      | _        t        |d«      sdn|j                  | _        | j                  rt        |«      | _        |j"                  dk(  | _        y )NrÉ   Úvision_use_headTÚflash_attention_2)rK   rL   rG   rM   rF   rƒ   rÕ   ÚencoderrP   rË   rÌ   Úpost_layernormÚhasattrré   Úuse_headÚ$Siglip2MultiheadAttentionPoolingHeadÚheadr³   Ú_use_flash_attention_2©r@   rG   rN   rZ   s      €r.   rL   z!Siglip2VisionTransformer.__init__  s‘   ø€ Ü‰ÑÔØˆŒØ×&Ñ&ˆ	ä1°&Ó9ˆŒÜ% fÓ-ˆŒÜ Ÿl™l¨9¸&×:OÑ:OÔPˆÔÜ$+¨FÐ4EÔ$F™ÈF×LbÑLbˆŒØ�=Š=Ü<¸VÓDˆDŒIØ&,×&AÑ&AÐEXÑ&XˆÕ#r-   ©Úoutput_typeÚconfig_classr}   rŽ   r\   r­   rÜ   r9   c                 óÆ  — |�|n| j                   j                  }|�|n| j                   j                  }| j                  ||«      }|�#| j                  st        ||j                  «      }n|}| j                  ||||¬«      }|j                  }	| j                  |	«      }	| j                  r| j                  |	|«      nd}
t        |	|
|j                  |j                  ¬«      S )ú
        Returns:

        N©rà   rŽ   r­   rÜ   ©r"   Úpooler_outputr#   r$   )rG   r­   rÜ   rƒ   rñ   r   ra   rë   r"   rì   rî   rð   r   r#   r$   )r@   r}   rŽ   r\   r­   rÜ   r#   Úencoder_attention_maskÚencoder_outputsr"   rú   s              r.   r„   z Siglip2VisionTransformer.forward  sò   € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð Ÿ™¨°nÓEˆàÐ%¨d×.IÒ.Iä%?ÀÐP]×PcÑPcÓ%dÑ"à%3Ð"à+/¯<©<Ø'Ø1Ø/Ø!5ð	 ,8ó ,
ˆð ,×=Ñ=ÐØ ×/Ñ/Ð0AÓBÐàHLÏÊ˜Ÿ	™	Ð"3°^ÔDÐ[_ˆä)Ø/Ø'Ø)×7Ñ7Ø&×1Ñ1ô	
ð 	
r-   ©NN)r%   r&   r'   r   rL   r   r   ÚSIGLIP2_VISION_INPUTS_DOCSTRINGr   r   r)   r*   r†   r‡   r   r»   r„   rˆ   r‰   s   @r.   rç   rç      s¡   ø„ ðYÐ2õ Yð Ù*Ð+JÓKÙÐ+EÐTgÔhð -1Ø/3ñ*
à×'Ñ'ð*
ð Ÿ™ð*
ð ×(Ñ(ð	*
ð
 $ D™>ð*
ð ' t™nð*
ð 
$ò*
ó ió Ló ô*
r-   rç   c            	       ó¦   ‡ — e Zd Zdefˆ fd„Z	 	 	 ddeej                     deej                     deej                     dej                  fd„Z
ˆ xZS )	ÚSiglip2TextEmbeddingsrG   c                 óN  •— t         ‰| �  «        |j                  }t        j                  |j
                  |«      | _        t        j                  |j                  |«      | _        | j                  dt        j                  |j                  «      j                  d«      d¬«       y )NÚposition_ids)r   r_   F)Ú
persistent)rK   rL   rM   rP   rW   Ú
vocab_sizeÚtoken_embeddingÚmax_position_embeddingsrX   Úregister_bufferr)   ÚarangeÚexpandrò   s      €r.   rL   zSiglip2TextEmbeddings.__init__?  sƒ   ø€ Ü‰ÑÔØ×&Ñ&ˆ	ä!Ÿ|™|¨F×,=Ñ,=¸yÓIˆÔÜ"$§,¡,¨v×/MÑ/MÈyÓ"YˆÔð 	×ÑØœEŸL™L¨×)GÑ)GÓH×OÑOÐPWÓXÐejð 	õ 	
r-   Ú	input_idsr  rà   r9   c                 ó8  — |�|j                   d   n|j                   d   }| j                  j                  j                   d   }||kD  rt        d|› d|› �«      ‚|€| j                  d d …d |…f   }|€| j                  |«      }| j                  |«      }||z   }|S )Nr_   r’   r   zRSequence length must be less than max_position_embeddings (got `sequence length`: z and max_position_embeddings: )ri   rX   r   r¥   r  r  )r@   r
  r  rà   r¶   Úmax_position_embeddingÚposition_embeddingsrƒ   s           r.   r„   zSiglip2TextEmbeddings.forwardK  sÇ   € ð -6Ð,A�Y—_‘_ RÒ(À}×GZÑGZÐ[]ÑG^ˆ
Ø!%×!8Ñ!8×!?Ñ!?×!EÑ!EÀaÑ!HÐàÐ.Ò.ÜØdØ�,Ð<Ð=SÐ<TðVóð ð
 ÐØ×,Ñ,ªQ°°°¨^Ñ<ˆLàÐ Ø ×0Ñ0°Ó;ˆMà"×5Ñ5°lÓCÐØ"Ð%8Ñ8ˆ
àÐr-   rå   )r%   r&   r'   r   rL   r   r)   r‡   r*   r†   r„   rˆ   r‰   s   @r.   r   r   >  sk   ø„ ð

Ð0õ 

ð 15Ø37Ø59ñ	à˜E×,Ñ,Ñ-ðð ˜u×/Ñ/Ñ0ðð   × 1Ñ 1Ñ2ð	ð
 
�‰÷r-   r   c                 óŽ  — d„ }||d|z  z
  k  s||d|z  z   kD  rt        j                  dd¬«        |||z
  |z  «      } |||z
  |z  «      }| j                  d|z  dz
  d|z  dz
  «       | j                  «        | j	                  |t        j                  d«      z  «       | j                  |«       | j                  ||¬«       y )Nc                 ód   — dt        j                  | t        j                  d«      z  «      z   dz  S )Nç      ð?ç       @)ÚmathÚerfÚsqrt)Úxs    r.   Únorm_cdfz _trunc_normal_.<locals>.norm_cdfi  s(   € à”d—h‘h˜q¤4§9¡9¨S£>Ñ1Ó2Ñ2°cÑ9Ð9r-   rb   zjmean is more than 2 std from [a, b] in nn.init.trunc_normal_. The distribution of values may be incorrect.)Ú
stacklevelr   r  )ÚminÚmax)	ÚwarningsÚwarnÚuniform_Úerfinv_Úmul_r  r  Úadd_Úclamp_)ÚtensorÚmeanÚstdÚaÚbr  ÚlÚus           r.   Ú_trunc_normal_r(  f  sÉ   € ò:ð 	ˆq�1�s‘7‰{Ò  q¨1¨s©7¡{Ò 2Ü�‰ð;àõ	
ñ 	�!�d‘(˜cÑ!Ó"€AÙ�!�d‘(˜cÑ!Ó"€Að ‡O�O�A˜‘E˜A‘I˜q 1™u q™yÔ)ð ‡N�NÔð ‡K�K�”d—i‘i “nÑ$Ô%Ø
‡K�K�Ôð ‡M�M�a˜Q€MÕr-   r!  r"  r#  r$  r%  r9   c                 ó´   — t        j                  «       5  t        | dd||«       | j                  |«      j	                  |«       ddd«       y# 1 sw Y   yxY w)an  Fills the input Tensor with values drawn from a truncated
    normal distribution. The values are effectively drawn from the
    normal distribution :math:`\mathcal{N}(	ext{mean}, 	ext{std}^2)`
    with values outside :math:`[a, b]` redrawn until they are within
    the bounds. The method used for generating the random values works
    best when :math:`a \leq 	ext{mean} \leq b`.

    NOTE: this 'tf' variant behaves closer to Tensorflow / JAX impl where the
    bounds [a, b] are applied when sampling the normal distribution with mean=0, std=1.0
    and the result is subsequently scaled and shifted by the mean and std args.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        mean: the mean of the normal distribution
        std: the standard deviation of the normal distribution
        a: the minimum cutoff value
        b: the maximum cutoff value
    r   r  N)r)   Úno_gradr(  r  r  )r!  r"  r#  r$  r%  s        r.   Útrunc_normal_tf_r+  Š  sI   € ô* 
�‰‹ñ $Ü�v˜q # q¨!Ô,Ø�‰�CÓ×Ñ˜dÔ#÷$÷ $ñ $ús   •0AÁAc                 ó,  — t        | «      \  }}|dk(  r|}n|dk(  r|}n|dk(  r||z   dz  }|z  }|dk(  r$t        | t        j                  |«      dz  ¬«       y |dk(  rCt	        j
                  «       5  | j                  t        j                  |«      ¬«       d d d «       y |d	k(  rIt        j                  d
|z  «      }t	        j
                  «       5  | j                  | |«       d d d «       y t        d|› �«      ‚# 1 sw Y   y xY w# 1 sw Y   y xY w)NÚfan_inÚfan_outÚfan_avgrb   Útruncated_normalg�©Û¶ä%ì?©r#  ÚnormalÚuniformr   zinvalid distribution )	r   r+  r  r  r)   r*  Únormal_r  r¥   )	r!  r¦   rf   Údistributionr-  r.  ÚdenomÚvarianceÚbounds	            r.   Úvariance_scaling_r9  ¤  s  € Ü3°FÓ;�O€FˆGØˆxÒØ‰Ø	�Ò	Ø‰Ø	�Ò	Ø˜'Ñ! QÑ&ˆà�u‰}€HàÐ)Ò)ä˜¤T§Y¡Y¨xÓ%8Ð;NÑ%NÖOØ	˜Ò	!Ü�]‰]‹_ñ 	4Ø�N‰NœtŸy™y¨Ó2ˆNÔ3÷	4ð 	4à	˜Ò	"Ü—	‘	˜!˜h™,Ó'ˆÜ�]‰]‹_ñ 	+Ø�O‰O˜U˜F EÔ*÷	+ð 	+ô Ð0°°Ð?Ó@Ð@÷	4ð 	4ú÷	+ð 	+ús   Á3&C>ÃD
Ã>DÄ
Dc                 ó    — t        | dd¬«       y )Nr-  r0  ©rf   r5  ©r9  ©r!  s    r.   Úlecun_normal_r>  ½  s   € Ü�f 8Ð:LÖMr-   c                 ó    — t        | dd¬«       y )Nr-  r2  r;  r<  r=  s    r.   Údefault_flax_embed_initr@  Á  s   € Ü�f 8¸(ÖCr-   aƒ  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
            it.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.

            [What are attention masks?](../glossary#attention-mask)
        position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.max_position_embeddings - 1]`.

            [What are position IDs?](../glossary#position-ids)
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
c                   óä   ‡ — e Zd Zdefˆ fd„Ze ee«       ee	e¬«      	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
e   de
e   d	e	fd
„«       «       «       Zˆ xZS )ÚSiglip2TextTransformerrG   c                 óF  •— t         ‰| �  «        || _        |j                  }t	        |«      | _        t        |«      | _        t        j                  ||j                  ¬«      | _        t        j                  ||j                  «      | _        |j                  dk(  | _        y )NrÉ   rê   )rK   rL   rG   rM   r   rƒ   rÕ   rë   rP   rË   rÌ   Úfinal_layer_normrQ   Úprojection_sizerð   r³   rñ   rò   s      €r.   rL   zSiglip2TextTransformer.__init__ç  s}   ø€ Ü‰ÑÔØˆŒØ×&Ñ&ˆ	Ü/°Ó7ˆŒÜ% fÓ-ˆŒÜ "§¡¨Y¸F×<QÑ<QÔ RˆÔä—I‘I˜i¨×)?Ñ)?Ó@ˆŒ	Ø&,×&AÑ&AÐEXÑ&XˆÕ#r-   ró   r
  rŽ   r  r­   rÜ   r9   c                 ó   — |�|n| j                   j                  }|�|n| j                   j                  }|€t        d«      ‚|j	                  «       }|j                  d|d   «      }| j                  ||¬«      }|�"| j                  st        ||j                  «      }| j                  ||||¬«      }|j                  }	| j                  |	«      }	|	dd…ddd…f   }
| j                  |
«      }
t        |	|
|j                  |j                   ¬«      S )r÷   NzYou have to specify input_idsr_   )r
  r  rø   rù   )rG   r­   rÜ   r¥   re   r²   rƒ   rñ   r   ra   rë   r"   rD  rð   r   r#   r$   )r@   r
  rŽ   r  r­   rÜ   Úinput_shaper#   rü   r"   Úpooled_outputs              r.   r„   zSiglip2TextTransformer.forwardò  s&  € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð ÐÜÐ<Ó=Ð=à—n‘nÓ&ˆØ—N‘N 2 {°2¡Ó7ˆ	àŸ™°)È,˜ÓWˆð Ð%¨d×.IÒ.Iä7¸È×H[ÑH[Ó\ˆNà+/¯<©<Ø'Ø)Ø/Ø!5ð	 ,8ó ,
ˆð ,×=Ñ=ÐØ ×1Ñ1Ð2CÓDÐð *ª!¨R²¨(Ñ3ˆØŸ	™	 -Ó0ˆä)Ø/Ø'Ø)×7Ñ7Ø&×1Ñ1ô	
ð 	
r-   ©NNNNN)r%   r&   r'   r   rL   r   r   ÚSIGLIP2_TEXT_INPUTS_DOCSTRINGr   r   r   r)   r†   r»   r„   rˆ   r‰   s   @r.   rB  rB  æ  sµ   ø„ ð	YÐ0õ 	Yð Ù*Ð+HÓIÙÐ+EÐTeÔfð -1Ø15Ø/3Ø,0Ø/3ñ2
à˜EŸL™LÑ)ð2
ð ! §¡Ñ.ð2
ð ˜uŸ|™|Ñ,ð	2
ð
 $ D™>ð2
ð ' t™nð2
ð 
$ò2
ó gó Jó ô2
r-   rB  a@  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`Siglip2Config`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
a¨  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
            it.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.

            [What are attention masks?](../glossary#attention-mask)
        position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.max_position_embeddings - 1]`.

            [What are position IDs?](../glossary#position-ids)
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using
            [`AutoImageProcessor`]. See [`CLIPImageProcessor.__call__`] for details.
        return_loss (`bool`, *optional*):
            Whether or not to return the contrastive loss.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        interpolate_pos_encoding (`bool`, *optional*, defaults to `False`):
            Whether to interpolate the pre-trained position encodings.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
c                   ó2   — e Zd ZdZeZdZdZg d¢ZdZ	dZ
d„ Zy)ÚSiglip2PreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    Úsiglip2T)r   rÇ   rF   rÇ   rï   c                 ó  — t        |t        «      rœt        | j                  t        «      r | j                  j                  j
                  n| j                  j
                  }t        j                  j                  |j                  j                  dt        j                  |«      z  ¬«       yt        |t        j                  «      rt        |j                  «       yt        |t        «      �r™t        j                  j!                  |j"                  j                  «       t        j                  j!                  |j$                  j                  «       t        j                  j!                  |j&                  j                  «       t        j                  j!                  |j(                  j                  «       t        j                  j+                  |j"                  j,                  «       t        j                  j+                  |j$                  j,                  «       t        j                  j+                  |j&                  j,                  «       t        j                  j+                  |j(                  j,                  «       yt        |t.        «      rÑt        j                  j!                  |j0                  j                  «       t        j                  j!                  |j2                  j                  «       t        j                  j                  |j0                  j,                  d¬«       t        j                  j                  |j2                  j,                  d¬«       yt        |t4        «      r®t        j                  j!                  |j6                  j8                  «       t        j                  j!                  |j:                  j<                  j8                  «       t        j                  j+                  |j:                  j>                  j8                  «       yt        |t@        «      rrtC        jD                  tC        jF                  d«      «      }|jH                  j8                  jK                  |«       |jL                  j8                  jO                  «        yt        |tP        «      rnt        j                  j                  |jR                  j                  | j                  j                  j
                  dz  | j                  jT                  z  ¬«       yt        |t        jV                  t        jX                  f«      rLt[        |j                  «       |j,                  �*t        j                  j+                  |j,                  «       yyt        |t        j\                  «      rJ|j,                  j8                  jO                  «        |j                  j8                  jK                  d«       yy)zInitialize the weightsr   r1  g�íµ ÷Æ°>r  r¡   N)/Ú
isinstancerF   rG   r   Úvision_configrM   rP   Úinitr4  rX   r   Únpr  rW   r@  rŸ   Úxavier_uniform_r«   r©   rª   r¬   Úzeros_Úbiasr½   rÃ   rÄ   rï   ÚprobeÚdataÚ	attentionÚin_proj_weightÚin_proj_biasÚSiglip2Modelr)   Úlogr!  Úlogit_scaleÚfill_Ú
logit_biasÚzero_ÚSiglip2ForImageClassificationÚ
classifierÚinitializer_factorrQ   ÚConv2dr>  rË   )r@   rŠ   rz   Úlogit_scale_inits       r.   Ú_init_weightsz$Siglip2PreTrainedModel._init_weightsu  s‹  € ä�fÔ5Ô6ô ˜dŸk™k¬=Ô9ð —‘×)Ñ)×5Ò5à—[‘[×,Ñ,ð ô
 �G‰G�O‰O˜F×5Ñ5×<Ñ<À!ÄbÇgÁgÈeÃnÑBTˆOÕUÜ˜¤§¡Ô-Ü# F§M¡MÕ2Ü˜Ô 0Õ1Ü�G‰G×#Ñ# F§M¡M×$8Ñ$8Ô9Ü�G‰G×#Ñ# F§M¡M×$8Ñ$8Ô9Ü�G‰G×#Ñ# F§M¡M×$8Ñ$8Ô9Ü�G‰G×#Ñ# F§O¡O×$:Ñ$:Ô;Ü�G‰G�N‰N˜6Ÿ=™=×-Ñ-Ô.Ü�G‰G�N‰N˜6Ÿ=™=×-Ñ-Ô.Ü�G‰G�N‰N˜6Ÿ=™=×-Ñ-Ô.Ü�G‰G�N‰N˜6Ÿ?™?×/Ñ/Õ0Ü˜¤
Ô+Ü�G‰G×#Ñ# F§J¡J×$5Ñ$5Ô6Ü�G‰G×#Ñ# F§J¡J×$5Ñ$5Ô6Ü�G‰G�O‰O˜FŸJ™JŸO™O°ˆOÔ6Ü�G‰G�O‰O˜FŸJ™JŸO™O°ˆOÕ6Ü˜Ô DÔEÜ�G‰G×#Ñ# F§L¡L×$5Ñ$5Ô6Ü�G‰G×#Ñ# F×$4Ñ$4×$CÑ$C×$HÑ$HÔIÜ�G‰G�N‰N˜6×+Ñ+×8Ñ8×=Ñ=Õ>Ü˜¤Ô-Ü$Ÿy™y¬¯©°cÓ):Ó;ÐØ×Ñ×#Ñ#×)Ñ)Ð*:Ô;Ø×Ñ×"Ñ"×(Ñ(Õ*Ü˜Ô =Ô>Ü�G‰G�O‰OØ×!Ñ!×(Ñ(Ø—K‘K×-Ñ-×9Ñ9¸4Ñ?À$Ç+Á+×B`ÑB`Ñ`ð õ ô ˜¤§¡¬B¯I©IÐ 6Ô7Ü˜&Ÿ-™-Ô(Ø�{‰{Ð&Ü—‘—‘˜vŸ{™{Õ+ð 'ä˜¤§¡Ô-Ø�K‰K×Ñ×"Ñ"Ô$Ø�M‰M×Ñ×$Ñ$ SÕ)ð .r-   N)r%   r&   r'   r(   r   rõ   Úbase_model_prefixÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_supports_flash_attn_2Ú_supports_sdparf  r,   r-   r.   rL  rL  a  s4   „ ñð
 !€LØ!ÐØ&*Ð#òÐð "ÐØ€Nó,*r-   rL  zBThe text model from Siglip2 without any head or projection on top.c                   ó  ‡ — e Zd ZeZdefˆ fd„Zdej                  fd„Zd„ Z	e
 ee«       eee¬«      	 	 	 	 	 ddeej"                     deej"                     d	eej"                     d
ee   dee   defd„«       «       «       Zˆ xZS )ÚSiglip2TextModelrG   c                 ód   •— t         ‰| �  |«       t        |«      | _        | j	                  «        y r¿   )rK   rL   rB  Ú
text_modelÚ	post_initrY   s     €r.   rL   zSiglip2TextModel.__init__«  s&   ø€ Ü‰Ñ˜Ô Ü0°Ó8ˆŒà�‰Õr-   r9   c                 óB   — | j                   j                  j                  S r¿   ©ro  rƒ   r  rD   s    r.   Úget_input_embeddingsz%Siglip2TextModel.get_input_embeddings±  s   € Ø�‰×)Ñ)×9Ñ9Ð9r-   c                 ó:   — || j                   j                  _        y r¿   rr  )r@   r�   s     r.   Úset_input_embeddingsz%Siglip2TextModel.set_input_embeddings´  s   € Ø5:ˆ�‰×"Ñ"Õ2r-   ró   r
  rŽ   r  r­   rÜ   c                 ó.   — | j                  |||||¬«      S )aÂ  
        Returns:

        Examples:

        ```python
        >>> from transformers import AutoTokenizer, Siglip2TextModel

        >>> model = Siglip2TextModel.from_pretrained("google/siglip2-base-patch16-224")
        >>> tokenizer = AutoTokenizer.from_pretrained("google/siglip2-base-patch16-224")

        >>> # important: make sure to set padding="max_length" as that's how the model was trained
        >>> inputs = tokenizer(["a photo of a cat", "a photo of a dog"], padding="max_length", return_tensors="pt")

        >>> outputs = model(**inputs)
        >>> last_hidden_state = outputs.last_hidden_state
        >>> pooled_output = outputs.pooler_output  # pooled (EOS token) states
        ```©r
  rŽ   r  r­   rÜ   )ro  )r@   r
  rŽ   r  r­   rÜ   s         r.   r„   zSiglip2TextModel.forward·  s)   € ð< �‰ØØ)Ø%Ø/Ø!5ð ó 
ð 	
r-   rI  )r%   r&   r'   r   rõ   rL   rP   ÚModulers  ru  r   r   rJ  r   r   r   r)   r†   r»   r„   rˆ   r‰   s   @r.   rm  rm  ¤  sÏ   ø„ ð
 %€LðÐ0õ ð: b§i¡ió :ò;ð Ù*Ð+HÓIÙÐ+EÐTeÔfð -1Ø15Ø/3Ø,0Ø/3ñ!
à˜EŸL™LÑ)ð!
ð ! §¡Ñ.ð!
ð ˜uŸ|™|Ñ,ð	!
ð
 $ D™>ð!
ð ' t™nð!
ð 
$ò!
ó gó Jó ô!
r-   rm  c                   ó€   ‡ — e Zd ZdZdefˆ fd„Zddej                  deej                     dej                  fd„Z	ˆ xZ
S )	rï   zMultihead Attention Pooling.rG   c                 ó¬  •— t         ‰| �  «        t        j                  t	        j
                  dd|j                  «      «      | _        t        j                  j                  |j                  |j                  d¬«      | _
        t        j                  |j                  |j                  ¬«      | _        t        |«      | _        |j                  | _        y )Nr   T)Úbatch_firstrÉ   )rK   rL   rP   Ú	Parameterr)   ÚrandnrM   rV  ÚMultiheadAttentionr¢   rX  rË   rÌ   Ú	layernormr½   rÐ   r£   rY   s     €r.   rL   z-Siglip2MultiheadAttentionPoolingHead.__init__á  s’   ø€ Ü‰ÑÔä—\‘\¤%§+¡+¨a°°F×4FÑ4FÓ"GÓHˆŒ
ÜŸ™×4Ñ4°V×5GÑ5GÈ×IcÑIcÐquÐ4ÓvˆŒÜŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ˜fÓ%ˆŒØ×3Ñ3ˆ�r-   Úhidden_staterŽ   r9   c                 óº  — |j                   d   }| j                  j                  |dd«      }|�f|j                   d   |j                   d   }}t        ||j                  |«      }|j                  d| j
                  |d«      }|j                  d||«      }| j                  ||||¬«      d   }|}| j                  |«      }|| j                  |«      z   }|d d …df   S )Nr   r   r_   )Ú	attn_mask)
ri   rV  Úrepeatr   ra   r£   rs   rX  r  rÐ   )r@   r€  rŽ   ru   rV  Ú
target_lenÚ
source_lenrÒ   s           r.   r„   z,Siglip2MultiheadAttentionPoolingHead.forwardê  sâ   € Ø!×'Ñ'¨Ñ*ˆ
Ø—
‘
×!Ñ! *¨a°Ó3ˆàÐ%Ø%*§[¡[°¡^°\×5GÑ5GÈÑ5J˜
ˆJÜ7¸È×HZÑHZÐ\fÓgˆNØ+×2Ñ2°1°d·n±nÀjÐRSÓTˆNØ+×3Ñ3°B¸
ÀJÓOˆNà—~‘~ e¨\¸<ÐSa�~ÓbÐcdÑeˆàˆØ—~‘~ lÓ3ˆØ $§(¡(¨<Ó"8Ñ8ˆàšA˜q˜DÑ!Ð!r-   r¿   )r%   r&   r'   r(   r   rL   r)   r†   r   r„   rˆ   r‰   s   @r.   rï   rï   Þ  sA   ø„ Ù&ð4Ð2õ 4ñ" E§L¡Lð "À(È5Ï<É<ÑBXð "Ðdi×dpÑdp÷ "r-   rï   zDThe vision model from Siglip2 without any head or projection on top.c                   óô   ‡ — e Zd ZeZdZdefˆ fd„Zdej                  fd„Z	e
 ee«       eee¬«      	 	 ddej                   dej"                  dej$                  d	ee   d
ee   defd„«       «       «       Zˆ xZS )ÚSiglip2VisionModelr}   rG   c                 ód   •— t         ‰| �  |«       t        |«      | _        | j	                  «        y r¿   )rK   rL   rç   Úvision_modelrp  rY   s     €r.   rL   zSiglip2VisionModel.__init__  s)   ø€ Ü‰Ñ˜Ô ä4°VÓ<ˆÔð 	�‰Õr-   r9   c                 óB   — | j                   j                  j                  S r¿   )r‰  rƒ   rS   rD   s    r.   rs  z'Siglip2VisionModel.get_input_embeddings  s   € Ø× Ñ ×+Ñ+×;Ñ;Ð;r-   ró   Úpixel_attention_maskr\   r­   rÜ   c                 ó.   — | j                  |||||¬«      S )aô  
        Returns:

        Examples:

        ```python
        >>> from PIL import Image
        >>> import requests
        >>> from transformers import AutoProcessor, Siglip2VisionModel

        >>> model = Siglip2VisionModel.from_pretrained("google/siglip2-base-patch16-224")
        >>> processor = AutoProcessor.from_pretrained("google/siglip2-base-patch16-224")

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

        >>> inputs = processor(images=image, return_tensors="pt")

        >>> outputs = model(**inputs)
        >>> last_hidden_state = outputs.last_hidden_state
        >>> pooled_output = outputs.pooler_output  # pooled features
        ```©r}   rŽ   r\   r­   rÜ   )r‰  )r@   r}   r‹  r\   r­   rÜ   s         r.   r„   zSiglip2VisionModel.forward  s,   € ðB × Ñ Ø%Ø/Ø)Ø/Ø!5ð !ó 
ð 	
r-   rý   )r%   r&   r'   r   rõ   Úmain_input_namerL   rP   rx  rs  r   r   rþ   r   r   r)   r*   r†   r‡   r   r»   r„   rˆ   r‰   s   @r.   r‡  r‡  ý  s»   ø„ ð
 '€LØ$€OðÐ2õ ð< b§i¡ió <ð Ù*Ð+JÓKÙÐ+EÐTgÔhð -1Ø/3ñ$
à×'Ñ'ð$
ð $Ÿl™lð$
ð ×(Ñ(ð	$
ð
 $ D™>ð$
ð ' t™nð$
ð 
$ò$
ó ió Ló ô$
r-   r‡  c                   ó´  ‡ — e Zd ZeZdefˆ fd„Z ee«      	 	 	 	 	 ddee	j                     dee	j                     dee	j                     dee   dee   de	j                  fd	„«       Z ee«      	 	 	 	 	 dd
ee	j                     dee	j                     dee	j                     dee   dee   de	j                  fd„«       Ze ee«       eee¬«      	 	 	 	 	 	 	 	 	 ddee	j                     d
ee	j                     dee	j                     dee	j                     dee	j                     dee	j                     dee   dee   dee   defd„«       «       «       Zˆ xZS )r[  rG   c                 ó°  •— t         ‰| �  |«       t        |j                  t        «      s"t        dt        |j                  «      › d�«      ‚t        |j                  t        «      s"t        dt        |j                  «      › d�«      ‚|j                  }|j                  }t        j                  |«      }t        j                  |«      }|j                  | _        |j                  | _        t        j                  t!        j"                  d«      «      | _        t        j                  t!        j"                  d«      «      | _        | j)                  «        y )NzNconfig.text_config is expected to be of type Siglip2TextConfig but is of type ú.zRconfig.vision_config is expected to be of type Siglip2VisionConfig but is of type r   )rK   rL   rO  Útext_configr   Ú	TypeErrorrm   rP  r   rm  Ú_from_configr‡  ro  r‰  rP   r|  r)   r}  r]  r_  rp  )r@   rG   r’  rP  ro  r‰  rZ   s         €r.   rL   zSiglip2Model.__init__>  s  ø€ Ü‰Ñ˜Ô ä˜&×,Ñ,Ô.?Ô@ÜðÜ˜×+Ñ+Ó,Ð-¨Qð0óð ô
 ˜&×.Ñ.Ô0CÔDÜðÜ˜×-Ñ-Ó.Ð/¨qð2óð ð
 ×(Ñ(ˆØ×,Ñ,ˆô &×2Ñ2°;Ó?ˆ
Ü)×6Ñ6°}ÓEˆð %×/Ñ/ˆŒØ(×5Ñ5ˆÔäŸ<™<¬¯©°A«Ó7ˆÔÜŸ,™,¤u§{¡{°1£~Ó6ˆŒð 	�‰Õr-   r
  rŽ   r  r­   rÜ   r9   c                 ó²   — |�|n| j                   j                  }|�|n| j                   j                  }| j                  |||||¬«      }|j                  }|S )aM  
        Returns:
            text_features (`torch.FloatTensor` of shape `(batch_size, output_dim`): The text embeddings obtained by
            applying the projection layer to the pooled output of [`Siglip2TextModel`].

        Examples:

        ```python
        >>> from transformers import AutoTokenizer, AutoModel
        >>> import torch

        >>> model = AutoModel.from_pretrained("google/siglip2-base-patch16-224")
        >>> tokenizer = AutoTokenizer.from_pretrained("google/siglip2-base-patch16-224")

        >>> # important: make sure to set padding="max_length" as that's how the model was trained
        >>> inputs = tokenizer(["a photo of a cat", "a photo of a dog"], padding="max_length", return_tensors="pt")
        >>> with torch.no_grad():
        ...     text_features = model.get_text_features(**inputs)
        ```rw  )rG   r­   rÜ   ro  rú   )r@   r
  rŽ   r  r­   rÜ   Útext_outputsrH  s           r.   Úget_text_featureszSiglip2Model.get_text_features^  sr   € ð: 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð 48·?±?ØØ)Ø%Ø/Ø!5ð 4Có 4
ˆð %×2Ñ2ˆàÐr-   r}   r‹  r\   c                 ó²   — |�|n| j                   j                  }|�|n| j                   j                  }| j                  |||||¬«      }|j                  }|S )aŒ  
        Returns:
            image_features (`torch.FloatTensor` of shape `(batch_size, output_dim`): The image embeddings obtained by
            applying the projection layer to the pooled output of [`Siglip2VisionModel`].

        Examples:

        ```python
        >>> from PIL import Image
        >>> import requests
        >>> from transformers import AutoProcessor, AutoModel
        >>> import torch

        >>> model = AutoModel.from_pretrained("google/siglip2-base-patch16-224")
        >>> processor = AutoProcessor.from_pretrained("google/siglip2-base-patch16-224")

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

        >>> inputs = processor(images=image, return_tensors="pt")

        >>> with torch.no_grad():
        ...     image_features = model.get_image_features(**inputs)
        ```r�  )rG   r­   rÜ   r‰  rú   )r@   r}   r‹  r\   r­   rÜ   Úvision_outputsrH  s           r.   Úget_image_featureszSiglip2Model.get_image_featuresŒ  su   € ðD 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð 6:×5FÑ5FØ%Ø/Ø)Ø/Ø!5ð 6Gó 6
ˆð '×4Ñ4ˆàÐr-   ró   Úreturn_lossc
           	      ó  — |�|n| j                   j                  }|	�|	n| j                   j                  }	| j                  |||||	¬«      }
| j	                  |||||	¬«      }|
j
                  }|j
                  }||j                  ddd¬«      z  }||j                  ddd¬«      z  }t        j                  ||j                  «       j                  |j                  «      «      }| j                  j                  |j                  «      | j                  j                  |j                  «      }}||j                  «       z  |z   }|j                  «       }d}|r t        j                  |j!                  d«      |j                  ¬	«      }t        j"                  |«       d|z  z   }t        j$                  j&                  j)                  ||z  «      }t        j*                  |d¬
«       }|j-                  «       }t/        |||||||
¬«      S )aa  
        Returns:

        Examples:

        ```python
        >>> from PIL import Image
        >>> import requests
        >>> from transformers import AutoProcessor, AutoModel
        >>> import torch

        >>> model = AutoModel.from_pretrained("google/siglip2-base-patch16-224")
        >>> processor = AutoProcessor.from_pretrained("google/siglip2-base-patch16-224")

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

        >>> texts = ["a photo of 2 cats", "a photo of 2 dogs"]
        >>> # important: we pass `padding=max_length` since the model was trained with this
        >>> inputs = processor(text=texts, images=image, padding="max_length", return_tensors="pt")

        >>> with torch.no_grad():
        ...     outputs = model(**inputs)

        >>> logits_per_image = outputs.logits_per_image
        >>> probs = torch.sigmoid(logits_per_image) # these are the probabilities
        >>> print(f"{probs[0][0]:.1%} that image 0 is '{texts[0]}'")
        31.9% that image 0 is 'a photo of 2 cats'
        ```Nr�  rw  rb   r_   T)r”   r“   Úkeepdimr   )r`   ©r“   )r4   r5   r6   r1   r!   r7   r8   )rG   r­   rÜ   r‰  ro  rú   Únormr)   r–   Útrn   r`   r]  r_  ÚexpÚeyere   Ú	ones_likerP   r—   Ú
logsigmoidÚsumr"  r3   )r@   r
  r}   r‹  r\   rŽ   r  r›  r­   rÜ   r™  r–  r!   r1   r6   r]  r_  r5   r4   r¢  Úm1_diag1ÚloglikÚnlls                          r.   r„   zSiglip2Model.forward¿  s   € ðZ 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð 6:×5FÑ5FØ%Ø/Ø)Ø/Ø!5ð 6Gó 6
ˆð 48·?±?ØØ)Ø%Ø/Ø!5ð 4Có 4
ˆð &×3Ñ3ˆØ"×0Ñ0ˆð $ l×&7Ñ&7¸!ÀÈTÐ&7Ó&RÑRˆØ! K×$4Ñ$4°q¸bÈ$Ð$4Ó$OÑOˆô  Ÿ,™, {°L·N±NÓ4D×4GÑ4GÈ×HZÑHZÓ4[Ó\ˆà"&×"2Ñ"2×"5Ñ"5°k×6HÑ6HÓ"IÈ4Ï?É?×K]ÑK]Ð^i×^pÑ^pÓKq�ZˆØ)¨K¯O©OÓ,=Ñ=À
ÑJˆà*×,Ñ,Ó.ÐàˆÙä—)‘)˜O×0Ñ0°Ó3¸O×<RÑ<RÔSˆCÜŸ™¨Ó8Ð8¸1¸s¹7ÑBˆHÜ—X‘X×(Ñ(×3Ñ3°H¸Ñ4NÓOˆFÜ—9‘9˜V¨Ô,Ð,ˆCØ—8‘8“:ˆDäØØ-Ø+Ø#Ø%Ø*Ø .ô
ð 	
r-   rI  )	NNNNNNNNN)r%   r&   r'   r   rõ   rL   r   rJ  r   r)   r†   r»   r*   r—  rþ   r‡   rš  r   ÚSIGLIP2_INPUTS_DOCSTRINGr   r3   r„   rˆ   r‰   s   @r.   r[  r[  :  sA  ø„ à €Lð˜}õ ñ@ +Ð+HÓIð -1Ø15Ø/3Ø,0Ø/3ñ+à˜EŸL™LÑ)ð+ð ! §¡Ñ.ð+ð ˜uŸ|™|Ñ,ð	+ð
 $ D™>ð+ð ' t™nð+ð 
×	Ñ	ò+ó Jð+ñZ +Ð+JÓKð 59Ø7;Ø59Ø,0Ø/3ñ0à˜u×0Ñ0Ñ1ð0ð ' u§|¡|Ñ4ð0ð ! ×!1Ñ!1Ñ2ð	0ð
 $ D™>ð0ð ' t™nð0ð 
×	Ñ	ò0ó Lð0ðd Ù*Ð+CÓDÙ¨=À}ÔUð 15Ø48Ø7;Ø59Ø15Ø37Ø&*Ø,0Ø/3ñ_
à˜E×,Ñ,Ñ-ð_
ð ˜u×0Ñ0Ñ1ð_
ð ' u§|¡|Ñ4ð	_
ð
 ! ×!1Ñ!1Ñ2ð_
ð ! §¡Ñ.ð_
ð ˜u×/Ñ/Ñ0ð_
ð ˜d‘^ð_
ð $ D™>ð_
ð ' t™nð_
ð 
ò_
ó Vó Eó ô_
r-   r[  z®
    Siglip2 vision encoder with an image classification head on top (a linear layer on top of the pooled final hidden states of
    the patch tokens) e.g. for ImageNet.
    c                   ó  ‡ — e Zd ZdZdeddfˆ fd„Ze ee«       e	e
e¬«      	 	 	 	 	 	 ddeej                     deej                     deej                     d	eej                     d
ee   dee   de
fd„«       «       «       Zˆ xZS )ra  r}   rG   r9   Nc                 ó~  •— t         ‰| �  |«       |j                  | _        t        j	                  |j
                  «      }|j                  | _        |j                  dkD  r4t        j                  |j
                  j                  |j                  «      nt        j                  «       | _        | j                  «        y )Nr   )rK   rL   Ú
num_labelsr‡  r”  rP  r‰  rP   rQ   rM   ÚIdentityrb  rp  )r@   rG   r‰  rZ   s      €r.   rL   z&Siglip2ForImageClassification.__init__.  s”   ø€ Ü‰Ñ˜Ô à ×+Ñ+ˆŒô *×6Ñ6°v×7KÑ7KÓLˆØ(×5Ñ5ˆÔð OU×N_ÑN_ÐbcÒNcŒB�I‰I�f×*Ñ*×6Ñ6¸×8IÑ8IÔJÔik×itÑitÓivð 	Œð
 	�‰Õr-   ró   r‹  r\   Úlabelsr­   rÜ   c                 ó8  — |�|n| j                   j                  }|�|n| j                   j                  }| j                  |||||¬«      }|j                  }|�Q|d   j                  |j                  «      }	t        j                  ||	z  d¬«      t        j                  |	d¬«      z  }nt        j                  |d¬«      }| j                  |«      }
d}|��¢|j                  |
j                  «      }| j                   j                  €�| j                  dk(  rd| j                   _        nl| j                  dkD  rL|j                  t        j                  k(  s|j                  t        j                  k(  rd| j                   _        nd| j                   _        | j                   j                  dk(  rIt!        «       }| j                  dk(  r& ||
j#                  «       |j#                  «       «      }nŒ ||
|«      }n‚| j                   j                  dk(  r=t%        «       } ||
j'                  d	| j                  «      |j'                  d	«      «      }n,| j                   j                  dk(  rt)        «       } ||
|«      }t+        ||
|j,                  |j.                  ¬
«      S )a;  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
            `config.num_labels > 1` a classification loss is computed (Cross-Entropy).

        Returns:

        Examples:

        ```python
        >>> from transformers import AutoImageProcessor, Siglip2ForImageClassification
        >>> import torch
        >>> from PIL import Image
        >>> import requests

        >>> torch.manual_seed(3)  # doctest: +IGNORE_RESULT
        >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
        >>> image = Image.open(requests.get(url, stream=True).raw)

        >>> # note: we are loading a `Siglip2Model` from the hub here,
        >>> # so the head will be randomly initialized, hence the predictions will be random if seed is not set above.
        >>> image_processor = AutoImageProcessor.from_pretrained("google/siglip2-base-patch16-224")
        >>> model = Siglip2ForImageClassification.from_pretrained("google/siglip2-base-patch16-224")

        >>> inputs = image_processor(images=image, return_tensors="pt")
        >>> outputs = model(**inputs)
        >>> logits = outputs.logits
        >>> # model predicts one of the two classes
        >>> predicted_class_idx = logits.argmax(-1).item()
        >>> print("Predicted class:", model.config.id2label[predicted_class_idx])
        Predicted class: LABEL_1
        ```N)rŽ   r\   r­   rÜ   ).Nr   rž  Ú
regressionÚsingle_label_classificationÚmulti_label_classificationr_   )r4   Úlogitsr#   r$   )rG   r­   rÜ   r‰  r"   rn   r`   r)   r¥  r"  rb  Úproblem_typer¬  ra   ÚlongrU   r   Úsqueezer
   r²   r	   r   r#   r$   )r@   r}   r‹  r\   r®  r­   rÜ   rÓ   Úsequence_outputÚ	pool_maskr³  r4   Úloss_fcts                r.   r„   z%Siglip2ForImageClassification.forward@  s8  € ðZ 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð /3×.?Ñ.?ØØ/Ø)Ø/Ø!5ð /@ó /
ˆð "×3Ñ3ˆð  Ð+Ø,¨YÑ7×:Ñ:¸?×;QÑ;QÓRˆIÜ#Ÿi™i¨¸)Ñ(CÈÔKÌeÏiÉiÐXaÐghÔNiÑi‰Oä#Ÿj™j¨¸aÔ@ˆOð —‘ Ó1ˆàˆØÑà—Y‘Y˜vŸ}™}Ó-ˆFØ�{‰{×'Ñ'Ð/Ø—?‘? aÒ'Ø/;�D—K‘KÕ,Ø—_‘_ qÒ(¨f¯l©l¼e¿j¹jÒ.HÈFÏLÉLÔ\a×\eÑ\eÒLeØ/L�D—K‘KÕ,à/K�D—K‘KÔ,à�{‰{×'Ñ'¨<Ò7Ü"›9�Ø—?‘? aÒ'Ù# F§N¡NÓ$4°f·n±nÓ6FÓG‘Dá# F¨FÓ3‘DØ—‘×)Ñ)Ð-JÒJÜ+Ó-�Ù §¡¨B°·±Ó @À&Ç+Á+ÈbÃ/ÓR‘Ø—‘×)Ñ)Ð-IÒIÜ,Ó.�Ù ¨Ó/�ä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r-   )NNNNNN)r%   r&   r'   rŽ  r   rL   r   r   r©  r   r   Ú_CONFIG_FOR_DOCr   r)   r†   r‡   r»   r„   rˆ   r‰   s   @r.   ra  ra  $  sà   ø„ ð %€Oð˜}ð °õ ð$ Ù*Ð+CÓDÙÐ+@ÈÔ_ð 04Ø7;Ø59Ø)-Ø,0Ø/3ña
à˜uŸ|™|Ñ,ða
ð ' u§|¡|Ñ4ða
ð ! ×!1Ñ!1Ñ2ð	a
ð
 ˜Ÿ™Ñ&ða
ð $ D™>ða
ð ' t™nða
ð 
òa
ó `ó Eó ôa
r-   ra  )r[  rL  rm  r‡  ra  )r±   )r±   r  g       Àr  )r  r-  r2  )Pr  r  Údataclassesr   Útypingr   r   r   r   r   ÚnumpyrR  r)   Útorch.nnrP   Útorch.nn.functionalr—   rq   r	   r
   r   Útorch.nn.initr   Úactivationsr   Úmodeling_attn_mask_utilsr   Úmodeling_outputsr   r   r   Úmodeling_utilsr   r   Úutilsr   r   r   r   r   r   Úconfiguration_siglip2r   r   r   Ú
get_loggerr%   r´   rº  r    r0   r3   rx  rF   r†   Úfloatr�   rŸ   r½   rÇ   rÕ   rþ   rç   r   r(  r+  r9  r>  r@  rJ  rB  ÚSIGLIP2_START_DOCSTRINGr©  rL  rm  rï   r‡  r[  ra  Ú__all__r,   r-   r.   ú<module>rË     sú  ðó* Û Ý !ß 8Õ 8ã Û Ý ß Ð ß AÑ AÝ 7å !Ý Bß bÑ bß F÷÷ ÷ YÑ Xð 
ˆ×	Ñ	˜HÓ	%€ð "€ð ô?˜+ó ?ó ð?ð8 ô?˜ó ?ó ð?ð8 ô!
�Kó !
ó ð!
ôHb˜bŸi™iô bðX ñ%Ø�I‰Ið%à�<‰<ð%ð 
�‰ð%ð �<‰<ð	%ð
 ˜UŸ\™\Ñ*ð%ð ð%ð ó%ô.D)�r—y‘yô D)ôN�—‘ô ô-˜"Ÿ)™)ô -ô`T
�R—Y‘Yô T
ðn#Ð ô$;
˜rŸy™yô ;
ô|%˜BŸI™Iô %òP! ðJ \_ñ$Ø�L‰Lð$Ø %ð$Ø27ð$ØBGð$ØSXð$à
‡\�\ó$ó4Aò2NòDð!Ð ôBA
˜RŸY™Yô A
ðHÐ ð%Ð ôP@*˜_ô @*ñF ØLØóô3
Ð-ó 3
ó	ð3
ôl"¨2¯9©9ô "ñ> ØNØóô6
Ð/ó 6
ó	ð6
ñr Ð-Ó.ôf
Ð)ó f
ó /ðf
ñR ðð óôy
Ð$:ó y
óðy
òx�r-   