Ë
    ÜÓ^jÒo  ã                   óž  — d dl Z d dlmZ d dlmZ d dl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 ddlmZ dd	lmZmZmZ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  ddl!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)  ejT                  e+«      Z, ed¬«      e	 G d„ de«      «       «       Z-e G d„ de«      «       Z.e G d„ de«      «       Z/ G d„ dej`                  «      Z1e G d„ de)«      «       Z2 ed¬«       G d „ d!e(«      «       Z3 G d"„ d#e&«      Z4e G d$„ d%e2«      «       Z5 ed&¬«       G d'„ d(e2«      «       Z6 ed)¬«       G d*„ d+e2«      «       Z7g d,¢Z8y)-é    N)Ú	dataclass)ÚLiteral)Ústrict)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )Úinitialization)ÚPreTrainedConfig)ÚBaseModelOutputÚMaskedLMOutputÚSequenceClassifierOutputÚTokenClassifierOutput)ÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚlogging)Úcan_return_tupleé   )ÚCONFIG_MAPPINGÚ
AutoConfigÚ	AutoModel)ÚModernBertPredictionHead)ÚSmolVLMModelÚSmolVLMPreTrainedModelúModernVBERT/modernvbert)Ú
checkpointc                   óâ   ‡ — e Zd ZU dZdZeedœZdZee	z  dz  e
d<   dZee	z  dz  e
d<   dZee
d<   d	Zee
d
<   dZee
d<   dZee
d<   dZed   e
d<   dZeez  e
d<   dZee
d<   dZee
d<   ˆ fd„Zˆ xZS )ÚModernVBertConfiga?  
    pixel_shuffle_factor (`int | None`, *optional*, defaults to 4):
        Scale factor used by any pixel-shuffle / upsampling operations in the vision head.
    initializer_cutoff_factor (`float | None`, *optional*, defaults to 2.0):
        The cutoff factor for the truncated_normal_initializer for initializing all weight matrices.
    classifier_pooling (`Literal["cls", "mean"]`, *optional*, defaults to `"cls"`):
        The pooling strategy to use for classification tasks.
    classifier_bias (`bool | None`, *optional*, defaults to `False`):
        Whether to add a bias term to the classification head

    Example:
    ```python
    >>> from transformers import ModernVBertConfig

    >>> # Initializing configuration
    >>> configuration = ModernVBertConfig()

    >>> # Initializing a model from the configuration (model class is implemented in
    >>> # `modernvbert.modeling_modernvbert`)

    >>> from transformers import ModernVBertModel
    >>> model = ModernVBertModel(configuration)

    >>> # Accessing the model configuration
    >>> cfg = model.config
    ```Úmodernvbert)Útext_configÚvision_configNr"   r#   içÄ  Úimage_token_idé   Úpixel_shuffle_factorg{®Gáz”?Úinitializer_rangeç       @Úinitializer_cutoff_factorÚcls)r*   ÚmeanÚclassifier_poolingç        Úclassifier_dropoutFÚclassifier_biasÚtie_word_embeddingsc                 ó|  •— | j                   €t        d   «       | _         n7t        | j                   t        «      rt        d   di | j                   ¤Ž| _         | j                  €t        d   «       | _        n7t        | j                  t        «      rt        d   di | j                  ¤Ž| _        t        ‰| �  di |¤Ž y )NÚ
modernbertÚsiglip_vision_model© )r"   r   Ú
isinstanceÚdictr#   ÚsuperÚ__post_init__)ÚselfÚkwargsÚ	__class__s     €ú~/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/modernvbert/modular_modernvbert.pyr8   zModernVBertConfig.__post_init__X   s£   ø€ Ø×ÑÐ#Ü-¨lÑ;Ó=ˆDÕÜ˜×(Ñ(¬$Ô/Ü-¨lÑ;ÑO¸d×>NÑ>NÑOˆDÔà×ÑÐ%Ü!/Ð0EÑ!FÓ!HˆDÕÜ˜×*Ñ*¬DÔ1Ü!/Ð0EÑ!FÑ!\È×I[ÑI[Ñ!\ˆDÔä‰ÑÑ' Ó'ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typer   Úsub_configsr"   r   r6   Ú__annotations__r#   r$   Úintr&   r'   Úfloatr)   r,   r   r.   r/   Úboolr0   r8   Ú__classcell__©r;   s   @r<   r    r    ,   s¬   ø… ñð6 €JØ",¸zÑJ€Kà26€KÐ! DÑ(¨4Ñ/Ó6Ø48€MÐ# dÑ*¨TÑ1Ó8Ø€N�CÓØ !Ð˜#Ó!Ø#Ð�uÓ#Ø'*Ð˜uÓ*Ø16Ð˜ Ñ.Ó6Ø&)Ð˜ ™Ó)Ø!€O�TÓ!Ø %Ð˜Ó%÷(ð (r=   r    c                   ó¾   — e Zd ZU dZdZej                  ed<   dZe	ej                     dz  ed<   dZ
e	ej                     dz  ed<   dZe	ej                     dz  ed<   y)ÚModernVBertBaseModelOutputaY  
    Base class for ModernVBERT model's outputs.
    Args:
        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.
            If `past_key_values` is used only the last hidden-state of the sequences of shape `(batch_size, 1,
            hidden_size)` is output.
        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.
        image_hidden_states (`tuple(torch.FloatTensor)`, *optional*):
            Tuple of `torch.FloatTensor` (one for the output of the image embeddings, `(batch_size, num_images,
            sequence_length, hidden_size)`.
            image_hidden_states of the model produced by the vision encoder
    NÚlast_hidden_stateÚhidden_statesÚ
attentionsÚimage_hidden_states)r>   r?   r@   rA   rL   ÚtorchÚFloatTensorrD   rM   ÚtuplerN   rO   r4   r=   r<   rK   rK   f   si   … ñð, ,0Ð�u×(Ñ(Ó/Ø59€M�5˜×*Ñ*Ñ+¨dÑ2Ó9Ø26€J��e×'Ñ'Ñ(¨4Ñ/Ó6Ø;?Ð˜˜u×0Ñ0Ñ1°DÑ8Ô?r=   rK   c                   óè   — e Zd ZU dZdZej                  dz  ed<   dZej                  ed<   dZ	e
ej                  df   dz  ed<   dZe
ej                  df   dz  ed<   dZej                  dz  ed<   y)	ÚModernVBertMaskedLMOutputaG  
    Base class for ModernVBERT model's outputs with masked language modeling loss.
    Args:
        loss (`torch.FloatTensor`, *optional*, returned when `labels` is provided):
            Masked language modeling (MLM) loss.
        logits (`torch.FloatTensor`):
            Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
        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.
        image_hidden_states (`tuple(torch.FloatTensor)`, *optional*):
            Tuple of `torch.FloatTensor` (one for the output of the image embeddings, `(batch_size, num_images,
            sequence_length, hidden_size)`.
            image_hidden_states of the model produced by the vision encoder
    NÚlossÚlogits.rM   rN   rO   )r>   r?   r@   rA   rU   rP   rQ   rD   rV   rM   rR   rN   rO   r4   r=   r<   rT   rT   „   s‚   … ñð, &*€Dˆ%×
Ñ
˜dÑ
"Ó)Ø $€FˆE×ÑÓ$Ø:>€M�5˜×*Ñ*¨CÐ/Ñ0°4Ñ7Ó>Ø7;€J��e×'Ñ'¨Ð,Ñ-°Ñ4Ó;Ø48Ð˜×*Ñ*¨TÑ1Ô8r=   rT   c                   ó.   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zˆ xZS )ÚModernVBertConnectorzê
    Connector module for ModernVBERT. It performs a pixel shuffle operation followed by a linear projection to match the text model's hidden size.
    Based on https://pytorch.org/docs/stable/generated/torch.nn.PixelShuffle.html
    c                 óî   •— t         ‰| �  «        |j                  | _        t        j                  |j
                  j                  |j                  dz  z  |j                  j                  d¬«      | _        y )Nr   F©Úbias)	r7   Ú__init__r&   ÚnnÚLinearr#   Úhidden_sizer"   Úmodality_projection©r9   Úconfigr;   s     €r<   r\   zModernVBertConnector.__init__©   s^   ø€ Ü‰ÑÔØ$*×$?Ñ$?ˆÔ!Ü#%§9¡9Ø× Ñ ×,Ñ,°×0KÑ0KÈQÑ0NÑOØ×Ñ×*Ñ*Øô$
ˆÕ r=   c                 ó¼  — |j                  «       \  }}}t        |dz  «      x}}|j                  ||||«      }|j                  ||t        ||z  «      ||z  «      }|j                  dddd«      }|j	                  |t        ||z  «      t        ||z  «      ||dz  z  «      }|j                  dddd«      }|j	                  |t        ||dz  z  «      ||dz  z  «      S )Ng      à?r   r   é   r	   )ÚsizerE   ÚviewÚpermuteÚreshape)r9   rO   r&   Ú
batch_sizeÚ
seq_lengthÚ	embed_dimÚheightÚwidths           r<   Úpixel_shufflez"ModernVBertConnector.pixel_shuffle²   s  € Ø,?×,DÑ,DÓ,FÑ)ˆ
�J 	Ü˜Z¨™_Ó-Ð-ˆ�Ø1×6Ñ6°zÀ6È5ÐR[Ó\ÐØ1×6Ñ6Ø˜¤ EÐ,@Ñ$@Ó AÀ9ÐOcÑCcó
Ðð 2×9Ñ9¸!¸QÀÀ1ÓEÐØ1×9Ñ9ØÜ�Ð,Ñ,Ó-Ü�Ð-Ñ-Ó.ØÐ-¨qÑ0Ñ1ó	
Ðð 2×9Ñ9¸!¸QÀÀ1ÓEÐØ"×*Ñ*Øœ˜JÐ*>ÀÑ*AÑBÓCÀYÐRfÐhiÑRiÑEjó
ð 	
r=   c                 ó\   — | j                  || j                  «      }| j                  |«      S ©N)rn   r&   r`   )r9   rO   s     r<   ÚforwardzModernVBertConnector.forwardÅ   s.   € Ø"×0Ñ0Ð1DÀd×F_ÑF_Ó`ÐØ×'Ñ'Ð(;Ó<Ð<r=   )r>   r?   r@   rA   r\   rn   rq   rH   rI   s   @r<   rX   rX   £   s   ø„ ñô

ò
ö&=r=   rX   c                   óB   — e Zd ZeZg Z ej                  «       d„ «       Zy)ÚModernVBertPreTrainedModelc                 ó  ‡ — t        j                  ‰ |«       dt        j                  dt        fˆ fd„}t        |t        «      ra‰ j                  j                  t        j                  d‰ j                  j                  j                  z  «      z  } ||j                  |«       y t        |t        «      ra‰ j                  j                  t        j                  d‰ j                  j                  j                  z  «      z  } ||j                  |«       y t        |t         t"        f«      r^‰ j                  j                  t        j                  ‰ j                  j                  j$                  «      z  } ||j&                  |«       y y )NÚmoduleÚstdc                 ó8  •— t        ‰j                  dd«      }t        j                  | j                  d|| |z  ||z  ¬«       t        | t        j                  t        j                  f«      r-| j                  � t        j                  | j                  «       y y y )Nr)   r(   r-   )r+   rv   ÚaÚb)Úgetattrrb   ÚinitÚtrunc_normal_Úweightr5   r]   r^   ÚConv2dr[   Úzeros_)ru   rv   Úcutoff_factorr9   s      €r<   Úinit_weightz=ModernVBertPreTrainedModel._init_weights.<locals>.init_weightÓ   s€   ø€ Ü# D§K¡KÐ1LÈcÓRˆMÜ×ÑØ—‘ØØØ �. 3Ñ&Ø #Ñ%õô ˜&¤2§9¡9¬b¯i©iÐ"8Ô9Ø—;‘;Ð*Ü—K‘K §¡Õ,ð +ð :r=   r(   )r   Ú_init_weightsr]   ÚModulerF   r5   rX   rb   r'   ÚmathÚsqrtr"   Únum_hidden_layersr`   ÚModernVBertForMaskedLMÚlm_headÚ$ModernVBertForSequenceClassificationÚ!ModernVBertForTokenClassificationr_   Ú
classifier)r9   ru   r�   Úout_stdÚfinal_out_stds   `    r<   r‚   z(ModernVBertPreTrainedModel._init_weightsÏ   s  ø€ ä×%Ñ% d¨FÔ3ð	-¤§	¡	ð 	-´õ 	-ô �fÔ2Ô3Ø—k‘k×3Ñ3´d·i±iÀÀdÇkÁk×F]ÑF]×FoÑFoÑ@oÓ6pÑpˆGÙ˜×2Ñ2°GÕ<Ü˜Ô 6Ô7Ø—k‘k×3Ñ3´d·i±iÀÀdÇkÁk×F]ÑF]×FoÑFoÑ@oÓ6pÑpˆGÙ˜Ÿ™¨Õ0ÜØä4Ü1ðô
ð !ŸK™K×9Ñ9¼D¿I¹IÀdÇkÁk×F]ÑF]×FiÑFiÓ<jÑjˆMÙ˜×)Ñ)¨=Õ9ð
r=   N)	r>   r?   r@   r    Úconfig_classÚ_no_split_modulesrP   Úno_gradr‚   r4   r=   r<   rs   rs   Ê   s'   „ à$€LØÐà€U‡]�]ƒ_ñ:ó ñ:r=   rs   aG  
    ModernVBertModel is a model that combines a vision encoder (SigLIP) and a text encoder (ModernBert).

    ModernVBert is the base model of the visual retriever ColModernVBert, and was introduced in the following paper:
    [*ModernVBERT: Towards Smaller Visual Document Retrievers*](https://arxiv.org/abs/2510.01149).
    )Úcustom_introc                   ó@  ‡ — e Zd Zdefˆ fd„Ze edd¬«      	 	 	 	 	 	 	 ddej                  dej                  dz  d	ej                  dz  d
ej                  dz  dej                  dz  dej                  dz  dej                  dz  dee   deez  fd„«       «       Zˆ xZS )ÚModernVBertModelrb   c                 ó�  •— t         ‰| �  |«       t        |«      | _        t	        j
                  |j                  «      | _        t	        j
                  |j                  «      | _	        t        |j                  j                  |j                  j                  z  dz  |j                  dz  z  «      | _        | j                  «        y )Nr   )r7   r\   rX   Ú	connectorr   Úfrom_configr"   Ú
text_modelr#   Úvision_modelrE   Ú
image_sizeÚ
patch_sizer&   Úimage_seq_lenÚ	post_initra   s     €r<   r\   zModernVBertModel.__init__û   s¡   ø€ Ü‰Ñ˜Ô ô .¨fÓ5ˆŒÜ#×/Ñ/°×0BÑ0BÓCˆŒÜ%×1Ñ1°&×2FÑ2FÓGˆÔä Ø×"Ñ"×-Ñ-°×1EÑ1E×1PÑ1PÑPÐUVÑVØ×*Ñ*¨AÑ-ñ/ó
ˆÔð 	�‰Õr=   áØ  
        Inputs fed to the model can have an arbitrary number of images. To account for this, pixel_values fed to
        the model have image padding -> (batch_size, max_num_images, 3, max_heights, max_widths) where
        max_num_images is the maximum number of images among the batch_size samples in the batch.
        Padding images are not needed beyond padding the pixel_values at the entrance of the model.
        For efficiency, we only pass through the vision_model's forward the real images by
        discarding the padding images i.e. pixel_values of size (image_batch_size, 3, height, width) where
        image_batch_size would be 7 when num_images_per_sample=[1, 3, 1, 2] and max_num_images would be 3.
        r   ©r‘   r   NÚ	input_idsÚattention_maskÚposition_idsÚinputs_embedsÚpixel_valuesÚpixel_attention_maskrO   r:   Úreturnc                 ó¶  — |€9 | j                   j                  «       |«      j                  |j                  «      }|�| j	                  ||¬«      j
                  }|�;|j                  |j                  |j                  ¬«      }| j                  |||¬«      } | j                   d|||dœ|¤Ž}	t        |	j                  |	j                  |	j                  |¬«      S )a|  
        pixel_attention_mask (`torch.Tensor` of shape `(batch_size, image_size, image_size)`, *optional*):
            Mask to avoid performing attention on padding pixel indices.
        image_hidden_states (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
            The hidden states of the image encoder after modality projection.
        )r£   r¤   )ÚdtypeÚdevice)rŸ   r¢   rO   )r¢   r    r¡   )rL   rM   rN   rO   r4   )r—   Úget_input_embeddingsÚtor¨   Úget_image_featuresÚpooler_outputr§   Úinputs_mergerrK   rL   rM   rN   )
r9   rŸ   r    r¡   r¢   r£   r¤   rO   r:   Úoutputss
             r<   rq   zModernVBertModel.forward  sÿ   € ð> Ð ØB˜DŸO™O×@Ñ@ÓBÀ9ÓM×PÑPÐQZ×QaÑQaÓbˆMð Ð#Ø"&×"9Ñ"9Ø)Ð@Tð #:ó #ç‰mð  ð
 Ð*Ø"5×"8Ñ"8¸}×?RÑ?RÐ[h×[oÑ[oÐ"8Ó"pÐØ ×.Ñ.Ø#°=ÐVið /ó ˆMð
 "�$—/‘/ð 
Ø'Ø)Ø%ñ
ð ñ	
ˆô *Ø%×7Ñ7Ø!×/Ñ/Ø×)Ñ)Ø 3ô	
ð 	
r=   )NNNNNNN)r>   r?   r@   r    r\   r   r   rP   Ú
LongTensorÚTensorrQ   Ú
BoolTensorr   r   rR   rK   rq   rH   rI   s   @r<   r“   r“   ò   sü   ø„ ðÐ0õ ð  Ùðð -ôð '+Ø.2Ø04Ø26Ø15Ø8<Ø8<ñ/
à×#Ñ#ð/
ð Ÿ™ tÑ+ð/
ð ×&Ñ&¨Ñ-ð	/
ð
 ×(Ñ(¨4Ñ/ð/
ð ×'Ñ'¨$Ñ.ð/
ð $×.Ñ.°Ñ5ð/
ð #×.Ñ.°Ñ5ð/
ð Ð+Ñ,ð/
ð 
Ð+Ñ	+ò/
óó ô/
r=   r“   c                   ó   — e Zd Zy)ÚModernVBertPredictionHeadN)r>   r?   r@   r4   r=   r<   r³   r³   J  s   „ Ør=   r³   c                   ót  ‡ — e Zd ZddiZdefˆ fd„Zd„ Zd„ Ze e	dd¬	«      	 	 	 	 	 	 	 	 dde
j                  de
j                  d
z  de
j                  d
z  de
j                  d
z  de
j                  d
z  de
j                  d
z  de
j                  d
z  de
j                  d
z  dee   deez  fd„«       «       Zˆ xZS )r‡   zlm_head.weightz1model.text_model.embeddings.tok_embeddings.weightrb   c                 ól  •— t         ‰| �  |«       |j                  j                  | _        t	        |«      | _        t        |j                  «      | _        t        j                  |j                  j                  | j                  |j                  j                  ¬«      | _        | j                  «        y )NrZ   )r7   r\   r"   Ú
vocab_sizer“   Úmodelr³   Úprojection_headr]   r^   r_   Údecoder_biasrˆ   rœ   ra   s     €r<   r\   zModernVBertForMaskedLM.__init__R  s   ø€ Ü‰Ñ˜Ô à ×,Ñ,×7Ñ7ˆŒä% fÓ-ˆŒ
Ü8¸×9KÑ9KÓLˆÔÜ—y‘y ×!3Ñ!3×!?Ñ!?ÀÇÁÐW]×WiÑWi×WvÑWvÔwˆŒð 	�‰Õr=   c                 ó   — | j                   S rp   ©rˆ   )r9   s    r<   Úget_output_embeddingsz,ModernVBertForMaskedLM.get_output_embeddings^  s   € Ø�|‰|Ðr=   c                 ó   — || _         y rp   r»   )r9   Únew_embeddingss     r<   Úset_output_embeddingsz,ModernVBertForMaskedLM.set_output_embeddingsa  s	   € Ø%ˆ�r=   r�   r   rž   NrŸ   r    r¡   r¢   r£   r¤   rO   Úlabelsr:   r¥   c	                 ó\  —  | j                   d|||||||dœ|	¤Ž}
|
d   }| j                  | j                  |«      «      }d}|�<t        «       } ||j	                  d| j
                  «      |j	                  d«      «      }t        |||
j                  |
j                  |
j                  ¬«      S )á  
        pixel_attention_mask (`torch.Tensor` of shape `(batch_size, image_size, image_size)`, *optional*):
            Mask to avoid performing attention on padding pixel indices.
        image_hidden_states (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
            The hidden states of the image encoder after modality projection.
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
            text_config.]` or `model.image_token_id`. Tokens with indices set to `model.image_token_id` are
            ignored (masked), the loss is only computed for the tokens with labels in `[0, ..., text_config.]`.
        ©rŸ   r    r¡   r¢   r£   r¤   rO   r   Néÿÿÿÿ)rU   rV   rM   rN   rO   r4   )
r·   rˆ   r¸   r   rf   r¶   rT   rM   rN   rO   )r9   rŸ   r    r¡   r¢   r£   r¤   rO   rÀ   r:   r®   rM   rV   rU   Ú	criterions                  r<   rq   zModernVBertForMaskedLM.forwardd  sÁ   € ðH �$—*‘*ð 	
ØØ)Ø%Ø'Ø%Ø!5Ø 3ñ	
ð ñ	
ˆð   ™
ˆà—‘˜d×2Ñ2°=ÓAÓBˆàˆØÐÜ(Ó*ˆIÙ˜VŸ[™[¨¨T¯_©_Ó=¸v¿{¹{È2»ÓOˆDä(ØØØ!×/Ñ/Ø×)Ñ)Ø '× ;Ñ ;ô
ð 	
r=   ©NNNNNNNN)r>   r?   r@   Ú_tied_weights_keysr    r\   r¼   r¿   r   r   rP   r¯   r°   rQ   r±   r   r   rR   rT   rq   rH   rI   s   @r<   r‡   r‡   N  s*  ø„ à*Ð,_Ð`Ðð
Ð0õ 
òò&ð Ùðð -ôð '+Ø.2Ø04Ø26Ø15Ø8<Ø8<Ø*.ñ0
à×#Ñ#ð0
ð Ÿ™ tÑ+ð0
ð ×&Ñ&¨Ñ-ð	0
ð
 ×(Ñ(¨4Ñ/ð0
ð ×'Ñ'¨$Ñ.ð0
ð $×.Ñ.°Ñ5ð0
ð #×.Ñ.°Ñ5ð0
ð × Ñ  4Ñ'ð0
ð Ð+Ñ,ð0
ð 
Ð*Ñ	*ò0
óó ô0
r=   r‡   za
    The ModernVBert Model with a sequence classification head on top that performs pooling.
    c                   ó`  ‡ — e Zd Zdefˆ fd„Ze edd¬«      	 	 	 	 	 	 	 	 ddej                  dej                  dz  d	ej                  dz  d
ej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  dee   deez  fd„«       «       Zˆ xZS )r‰   rb   c                 ó‚  •— t         ‰| �  |«       |j                  | _        || _        t	        |«      | _        t        |j                  «      | _        t        j                  |j                  «      | _        t        j                  |j                  j                  |j                  «      | _        | j!                  «        y rp   )r7   r\   Ú
num_labelsrb   r“   r·   r³   r"   Úheadr]   ÚDropoutr.   Údropr^   r_   r‹   rœ   ra   s     €r<   r\   z-ModernVBertForSequenceClassification.__init__ª  sˆ   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒØˆŒä% fÓ-ˆŒ
Ü-¨f×.@Ñ.@ÓAˆŒ	Ü—J‘J˜v×8Ñ8Ó9ˆŒ	ÜŸ)™) F×$6Ñ$6×$BÑ$BÀF×DUÑDUÓVˆŒð 	�‰Õr=   r�   r   rž   NrŸ   r    r¡   r¢   r£   r¤   rO   rÀ   r:   r¥   c	                 óÂ  —  | j                   d|||||||dœ|	¤Ž}
|
d   }| j                  j                  dk(  r
|dd…df   }n¼| j                  j                  dk(  r£|�|j                  dd \  }}n|j                  dd \  }}|�|j                  n|j                  }|€(t        j                  ||f|t
        j                  ¬«      }||j                  d«      z  j                  d	¬
«      |j                  d	d¬«      z  }| j                  |«      }| j                  |«      }| j                  |«      }d}|��‡| 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/        |||
j0                  |
j2                  ¬«      S )rÂ   rÃ   r   r*   Nr+   r   )r¨   r§   rÄ   rd   )ÚdimT)rÏ   ÚkeepdimÚ
regressionÚsingle_label_classificationÚmulti_label_classification©rU   rV   rM   rN   r4   )r·   rb   r,   Úshaper¨   rP   ÚonesrG   Ú	unsqueezeÚsumrË   rÍ   r‹   Úproblem_typerÊ   r§   ÚlongrE   r   Úsqueezer   rf   r   r   rM   rN   )r9   rŸ   r    r¡   r¢   r£   r¤   rO   rÀ   r:   r®   rL   ri   Úseq_lenr¨   Úpooled_outputrV   rU   Úloss_fcts                      r<   rq   z,ModernVBertForSequenceClassification.forward·  s¥  € ðF �$—*‘*ð 	
ØØ)Ø%Ø'Ø%Ø!5Ø 3ñ	
ð ñ	
ˆð $ A™JÐà�;‰;×)Ñ)¨UÒ2Ø 1²!°Q°$Ñ 7ÑØ�[‰[×+Ñ+¨vÒ5ØÐ(Ø&3×&9Ñ&9¸"¸1Ð&=Ñ#�
™Gà&/§o¡o°b°qÐ&9Ñ#�
˜GØ)2Ð)>�Y×%Ò%ÀM×DXÑDXˆFàÐ%Ü!&§¡¨Z¸Ð,AÈ&ÔX]×XbÑXbÔ!c�Ø!2°^×5MÑ5MÈbÓ5QÑ!Q× VÑ VÐ[\Ð VÓ ]Ð`n×`rÑ`rØ˜tð asó añ !Ðð Ÿ	™	Ð"3Ó4ˆØŸ	™	 -Ó0ˆØ—‘ Ó/ˆàˆØÑØ�{‰{×'Ñ'Ð/Ø—?‘? 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=   rÆ   )r>   r?   r@   r    r\   r   r   rP   r¯   r°   rQ   r±   r   r   rR   r   rq   rH   rI   s   @r<   r‰   r‰   ¤  s   ø„ ðÐ0õ ð Ùðð -ôð '+Ø.2Ø04Ø26Ø15Ø8<Ø8<Ø*.ñQ
à×#Ñ#ðQ
ð Ÿ™ tÑ+ðQ
ð ×&Ñ&¨Ñ-ð	Q
ð
 ×(Ñ(¨4Ñ/ðQ
ð ×'Ñ'¨$Ñ.ðQ
ð $×.Ñ.°Ñ5ðQ
ð #×.Ñ.°Ñ5ðQ
ð × Ñ  4Ñ'ðQ
ð Ð+Ñ,ðQ
ð 
Ð)Ñ	)òQ
óó ôQ
r=   r‰   zw
    The ModernVBert Model with a token classification head on top, e.g. for Named Entity Recognition (NER) tasks.
    c                   ó`  ‡ — e Zd Zdefˆ fd„Ze edd¬«      	 	 	 	 	 	 	 	 ddej                  dej                  dz  d	ej                  dz  d
ej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  dee   deez  fd„«       «       Zˆ xZS )rŠ   rb   c                 ót  •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        |j                  «      | _        t        j                  |j                  «      | _        t        j                  |j                  j                  |j                  «      | _        | j                  «        y rp   )r7   r\   rÊ   r“   r·   r³   r"   rË   r]   rÌ   r.   rÍ   r^   r_   r‹   rœ   ra   s     €r<   r\   z*ModernVBertForTokenClassification.__init__  s�   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒä% fÓ-ˆŒ
Ü-¨f×.@Ñ.@ÓAˆŒ	Ü—J‘J˜v×8Ñ8Ó9ˆŒ	ÜŸ)™) F×$6Ñ$6×$BÑ$BÀF×DUÑDUÓVˆŒð 	�‰Õr=   r�   r   rž   NrŸ   r    r¡   r¢   r£   r¤   rO   rÀ   r:   r¥   c	                 ól  —  | j                   d|||||||dœ|	¤Ž}
|
d   }| j                  |«      }| j                  |«      }| j                  |«      }d}|�<t	        «       } ||j                  d| j                  «      |j                  d«      «      }t        |||
j                  |
j                  ¬«      S )rÂ   rÃ   r   NrÄ   rÔ   r4   )
r·   rË   rÍ   r‹   r   rf   rÊ   r   rM   rN   )r9   rŸ   r    r¡   r¢   r£   r¤   rO   rÀ   r:   r®   rL   rV   rU   rÞ   s                  r<   rq   z)ModernVBertForTokenClassification.forward*  sÏ   € ðH �$—*‘*ð 	
ØØ)Ø%Ø'Ø%Ø!5Ø 3ñ	
ð ñ	
ˆð $ A™JÐà ŸI™IÐ&7Ó8ÐØ ŸI™IÐ&7Ó8ÐØ—‘Ð!2Ó3ˆàˆØÐÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯O©OÓ<¸f¿k¹kÈ"»oÓNˆDä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r=   rÆ   )r>   r?   r@   r    r\   r   r   rP   r¯   r°   rQ   r±   r   r   rR   r   rq   rH   rI   s   @r<   rŠ   rŠ     s  ø„ ð
Ð0õ 
ð Ùðð -ôð '+Ø.2Ø04Ø26Ø15Ø8<Ø8<Ø*.ñ1
à×#Ñ#ð1
ð Ÿ™ tÑ+ð1
ð ×&Ñ&¨Ñ-ð	1
ð
 ×(Ñ(¨4Ñ/ð1
ð ×'Ñ'¨$Ñ.ð1
ð $×.Ñ.°Ñ5ð1
ð #×.Ñ.°Ñ5ð1
ð × Ñ  4Ñ'ð1
ð Ð+Ñ,ð1
ð 
Ð&Ñ	&ò1
óó ô1
r=   rŠ   )r    rs   r“   r‡   r‰   rŠ   )9r„   Údataclassesr   Útypingr   rP   Útorch.nnr]   Úhuggingface_hub.dataclassesr   r   r   r   Ú r
   r{   Úconfiguration_utilsr   Úmodeling_outputsr   r   r   r   Úmodeling_utilsr   Úprocessing_utilsr   Úutilsr   r   r   Úutils.genericr   Úautor   r   r   Úmodernbert.modeling_modernbertr   Úsmolvlm.modeling_smolvlmr   r   Ú
get_loggerr>   Úloggerr    rK   rT   rƒ   rX   rs   r“   r³   r‡   r‰   rŠ   Ú__all__r4   r=   r<   ú<module>ró      s£  ðó Ý !Ý ã Ý Ý .ß AÑ Aå &Ý 3÷ó õ .Ý &ß @Ñ @Ý -ß 8Ñ 8Ý Eß Kð 
ˆ×	Ñ	˜HÓ	%€ñ Ð4Ô5Øô5(Ð(ó 5(ó ó 6ð5(ðp ô@ ó @ó ð@ð: ô9 ó 9ó ð9ô<$=˜2Ÿ9™9ô $=ðN ô$:Ð!7ó $:ó ð$:ñN ðôôM
�|ó M
óðM
ô`	Ð 8ô 	ð ôR
Ð7ó R
ó ðR
ñj ðôô
l
Ð+Eó l
óð
l
ñ^ ðôô
K
Ð(Bó K
óð
K
ò\�r=   