ó
    ‡Ž¡j�`  ã                   ó  • S SK r S SKJr  S SKJrJrJr  S SKrS SK	r	SSK
Jr  SSKJrJr  SSKJrJrJrJr  SSKJrJrJr  SS	KJr  SS
KJr  \(       a  SSKJr   " S S\SS9r\" SS9\ " S S\5      5       5       rS/rg)é    N)Ú
accumulate)ÚTYPE_CHECKINGÚOptionalÚUnioné   )ÚBatchFeature)Ú
ImageInputÚis_valid_image)ÚMultiModalDataÚProcessingKwargsÚProcessorMixinÚUnpack)Ú
AddedTokenÚBatchEncodingÚ	TextInput)Úauto_docstring)Úrequires)ÚPreTokenizedInputc                   ó0   • \ rS rSrSS0SSSS.SS0S	.rS
rg)ÚColModernVBertProcessorKwargsé(   ÚpaddingÚlongestTÚchannels_first)Úreturn_row_col_infoÚdata_formatÚdo_convert_rgbÚreturn_tensorsÚpt)Útext_kwargsÚimages_kwargsÚcommon_kwargs© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú	_defaultsÚ__static_attributes__r#   ó    ÚÊC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\transformers/models/colmodernvbert/processing_colmodernvbert.pyr   r   (   s/   † ð �yð
ð $(Ø+Ø"ñ
ð
 +¨DÐ1ñ
ƒIr*   r   F)Útotal)Útorch)Úbackendsc                   óN  ^ • \ rS rSr\r     S"S\S\S-  S\S-  4U 4S jjjr\	   S#S\
\\
   -  \\\
      -  S\\S	\\   \S	   4   S\S-  S
\\   S\4
S jj5       r  S$S\
S-  S\\S	\\   \S	   4   S
\\   4S jjr  S$S\
S-  S\\S	\\   \S	   4   S
\\   4U 4S jjjrS\S\S\4S jrS\S\\   S\\\      4S jrS%S jr S%S\
S-  S
\\   S\4S jjrS\\\   -  S
\\   S\4S jr   S&S\S\S   4   S\S\S   4   S\S\S   S\S\4   SS4S  jjrS!rU =r$ )'ÚColModernVBertProcessoré6   NÚimage_seq_lenÚvisual_prompt_prefixÚquery_prefixc                 ó´  >• Sn[        SSSS9R                  U l        [        SSSS9R                  U l        [        SSSS9R                  U l        SU l        X@l        UR                  U R                  5      U l        UR                  U R                  5      U l	        UR                  U R
                  5      U l
        [        S	5       VV	s/ s H3  n[        S	5        H   o’R                  S
US-    SU	S-    S35      PM"     M5     sn	nU l        [        R                  " S5      U l        SU R                  U R                  U R                  /0n
UR!                  U
5        UR                  U R                  5      U l        ["        TU ]H  " X4SU0UD6  U=(       d    SU R                   S3U l        U=(       d    SU l        U R                  U l        gs  sn	nf )aJ  
image_seq_len (`int`, *optional*, defaults to 64):
    The length of the image sequence i.e. the number of <image> tokens per image in the input.
visual_prompt_prefix (`str`, *optional*):
    A string that gets tokenized and prepended to the image tokens.
query_prefix (`str`, *optional*):
    A prefix to be used for the query.
Nz<fake_token_around_image>FT)Ú
normalizedÚspecialz<image>z<end_of_utterance>z<global-img>é   ú<row_é   Ú_col_Ú>z*(\n?<global-img>\n?|<row_\d+_col_\d+>\n?)+Úadditional_special_tokensÚchat_templatez<|begin_of_text|>User:z0Describe the image.<end_of_utterance>
Assistant:Ú )r   ÚcontentÚfake_image_tokenÚimage_tokenÚend_of_utterance_tokenÚglobal_image_tagr2   Úconvert_tokens_to_idsÚimage_token_idÚfake_image_token_idÚglobal_image_token_idÚrangeÚrow_col_idsÚreÚcompileÚ%_regex_to_remove_extra_special_tokensÚadd_special_tokensÚsuperÚ__init__r3   r4   Úquery_augmentation_token)ÚselfÚimage_processorÚ	tokenizerr>   r2   r3   r4   ÚkwargsÚiÚjÚtokens_to_addÚ	__class__s              €r+   rP   Ú ColModernVBertProcessor.__init__;   sÊ  ø€ ð$ ˆÜ *Ð+FÐSXÐbfÑ g× oÑ oˆÔÜ% i¸EÈ4ÑP×XÑXˆÔÜ&0Ð1EÐRWÐaeÑ&f×&nÑ&nˆÔ#Ø .ˆÔØ*ÔØ'×=Ñ=¸d×>NÑ>NÓOˆÔØ#,×#BÑ#BÀ4×CXÑCXÓ#YˆÔ Ø%.×%DÑ%DÀT×EZÑEZÓ%[ˆÔ"äSXÐYZÔS[ô
ÚS[ÈaÔejÐkl×emÐ`a×+Ñ+¨e°A¸±E°7¸%ÀÀAÁ¸wÀaÐ,HÖIÑemÑIÑS[ò
ˆÔô 68·Z²ZÐ@mÓ5nˆÔ2ð (Ø×%Ñ%Ø× Ñ Ø×+Ñ+ð*ð
ˆð 	×$Ñ$ ]Ô3Ø'×=Ñ=¸d×>NÑ>NÓOˆÔä‰Ò˜Ñ[À=Ð[ÐTZÒ[à$8÷ %
Ø$ T×%5Ñ%5Ð$6Ð6gÐhð 	Ô!ð )×.¨BˆÔØ(,×(CÑ(CˆÕ%ùó1
s   Ã:GÚimagesÚtextr   rU   Úreturnc                 óâ  • U R                   " SXS.UD6u  pU R                  " SXS.UD6  U R                  " [        4SU R                  R
                  0UD6nUb  UOU R                  nUS   R                  SS5      nUS   R                  SS5      nUS   R                  SS5      n0 =pšUGb  U R                  " U40 US	   D6u  p›U	R                  S
S5        U	R                  SS5        UbÚ  U R                  X+S9u  p,U R                  " U40 US   D6n
U(       a  XÊS'   / n[        U5       Hg  u  pï/ nU HI  nUS   u  nnU
R                  UU5      nU
R                  UUS-
  5      nUR                  UU-
  S-   5        MK     UR                  U5        Mi     U(       a  U R                  U
S   U5      U
S'   U R                  X*S/S9  OUb  U R                  " SSU0US   D6n
[        0 U
EU	EUS9$ )zì
image_seq_len (`int`, *optional*):
    The length of the image sequence. If not provided, the default value of self.image_seq_len is used.
    image_seq_len should be equal to int(((image_size // patch_size) ** 2) / (scale_factor**2))
)r[   r\   Útokenizer_init_kwargsNr    Úreturn_text_replacement_offsetsFÚreturn_mm_token_type_idsr   r!   ÚrowsÚcols)Úimages_replacementsÚtext_replacement_offsetsÚnew_spanr:   Ú	input_idsÚmm_token_type_idsÚimage)Ú
modalitiesr\   )ÚdataÚtensor_typer#   )Úprepare_inputs_layoutÚvalidate_inputsÚ_merge_kwargsr   rT   Úinit_kwargsr2   ÚpopÚ_process_imagesÚget_text_with_replacementsÚ	enumerateÚchar_to_tokenÚappendÚcreate_mm_token_type_idsÚ_check_special_mm_tokensr   )rR   r[   r\   r2   rU   Úoutput_kwargsr`   ra   r   Úimage_inputsÚtext_inputsrd   re   Úbatch_image_seq_lengthsÚbatch_idÚtext_replacement_offsetÚimage_seq_lensrk   ÚstartÚendÚstart_id_posÚ
end_id_poss                         r+   Ú__call__Ú ColModernVBertProcessor.__call__p   sW  € ð ×1Ò1ÐU¸ÑUÈfÑU‰ˆØ×ÒÐ@ FÑ@¸Ò@à×*Ò*Ü)ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð *7Ñ)B™È×HZÑHZˆØ*7¸Ñ*F×*JÑ*JÐKlÐnsÓ*tÐ'Ø#0°Ñ#?×#CÑ#CÐD^Ð`eÓ#fÐ Ø& }Ñ5×9Ñ9Ð:JÈDÓQˆà%'Ð'ˆØÒØ04×0DÒ0DÀVÑ0nÈ}Ð]lÑOmÑ0nÑ-ˆLð ×Ñ˜V TÔ*Ø×Ñ˜V TÔ*àÑØ15×1PÑ1PØð 2Qð 2Ñ.�ð #Ÿnšn¨TÑR°]À=Ñ5QÑR�Þ2Ø>VÐ :Ñ;à*,Ð'Ü9BÐC[Ö9\Ñ5�HØ%'�NÛ 7˜Ø%)¨*Ñ%5™
˜˜sØ'2×'@Ñ'@ÀÈ5Ó'Q˜Ø%0×%>Ñ%>¸xÈÈqÉÓ%Q˜
à&×-Ñ-¨j¸<Ñ.GÈ!Ñ.KÖLñ !8ð ,×2Ñ2°>ÖBñ :]ö ,Ø7;×7TÑ7TØ# KÑ0Ð2Ió8�KÐ 3Ñ4ð ×-Ñ-¨dÈWÈIÐ-ÑVøàÑØŸ.š.ÑS¨dÐS°mÀMÑ6RÑSˆKäÐ!@ KÐ!@°<Ð!@ÈnÑ]Ð]r*   c                 ó‚  • Ub1  [        U[        5      (       a  U/n[        U5      R                  5       nUbü  U R                  R                  U5      n[        U5      (       a  U//nX4$ [        U[        [        45      (       a¯  [        US   5      (       aœ  Ub–  U Vs/ s H  oDR                  U R                  5      PM     nnS/[        [        U5      5      -   n[        [        U5      5       Vs/ s H  nXU   XgS-       PM     nn[        U5      US   :”  a  X�US   S  /-   nX4$ Un X4$ U/nX4$ s  snf s  snf )Nr   r:   éÿÿÿÿ)Ú
isinstanceÚstrÚlistÚcopyrS   Úfetch_imagesr
   ÚtupleÚcountrB   r   rI   Úlen)	rR   r[   r\   rU   ÚsampleÚn_images_in_textÚcumsum_images_in_textrV   Úsplit_imagess	            r+   rm   Ú-ColModernVBertProcessor.prepare_inputs_layout±   sp  € ð ÑÜ˜$¤×$Ñ$Ø�v�Ü˜“:—?‘?Ó$ˆDàÑØ×)Ñ)×6Ñ6°vÓ>ˆFÜ˜f×%Ñ%Ø!˜(˜�ð$ ˆ|Ðô# ˜F¤T¬5 M×2Ñ2´~ÀfÈQÁi×7PÑ7PØÑ#áUYÓ'ZÒUYÈ6¯©°T×5EÑ5EÖ(FÑUYÐ$Ð'ZØ-.¨C´$´zÐBRÓ7SÓ2TÑ,TÐ)ô "'¤sÐ+;Ó'<Ô!=ó$â!=˜Að °QÑ7Ð:OÐTUÑPUÑ:VÓWÙ!=ð !ð $ô
 ˜6“{Ð%:¸2Ñ%>Ó>Ø!-Ð8MÈbÑ8QÐ8SÐ1TÐ0UÑ!U˜ð ˆ|Ðð	 ".™ð ˆ|Ðð %˜X�Fàˆ|Ðùò ([ùò$s   Â$D7Ã3D<c                 óÌ  >• [         TU ]  " X40 UD6  Uc  Uc  [        S5      eUb´  U Vs/ s H  oDR                  U R                  5      PM     nnUbM  U Vs/ s H  n[        U5      PM     nnXW:w  a,  [        SU R                   SU SU R                   SU S3	5      eg Uc6  [        U5      (       a%  [        S[        U5       SU R                   S35      eg g g s  snf s  snf )	Nz+You must provide either `text` or `images`.zThe total number of zP tokens in the prompts should be the same as the number of images passed. Found Ú z tokens and z images per sample.zFound z. tokens in the text but no images were passed.)rO   rn   Ú
ValueErrorrŽ   rB   r�   ÚanyÚsum)	rR   r[   r\   rU   r�   r‘   ÚsublistÚn_images_in_imagesrY   s	           €r+   rn   Ú'ColModernVBertProcessor.validate_inputsÓ   s  ø€ ô 	‰Ò Ñ7°Ò7à‰<˜F™NÜÐJÓKÐKàÑÙMQÓRÊTÀ6§¡¨T×-=Ñ-=Ö >ÉTÐÐRØÑ!ÙBHÓ%IÂ&°w¤c¨'¦lÁ&Ð"Ð%IØ#Ó9Ü$Ø.¨t×/?Ñ/?Ð.@ð A"Ø"2Ð!3°1°T×5EÑ5EÐ4FÀlÐSeÐRfÐfyð{óð ð :ð
 ‘¤CÐ(8×$9Ñ$9Ü ØœSÐ!1Ó2Ð3°1°T×5EÑ5EÐ4FÐFtÐuóð ð %:�ð ùÚRùâ%Is   «$CÁC!rz   Ú	image_idxc           	      ó¨  • US    VVs/ s H  oD  H  oUPM     M     snnU   nUS    VVs/ s H  ow  H  oˆPM     M     snnU   n	US:X  aJ  U	S:X  aD  U R                    U R                   -   U R                   U R                  -  -   U R                    -   $ Sn
[	        U5       HU  n[	        U	5       H>  nU
U R                    SUS-    SUS-    S3-   U R                   U R                  -  -   -  n
M@     U
S	-  n
MW     U
S	U R                    3U R                   -   U R                   U R                  -  -   U R                    -   -  n
U
$ s  snnf s  snnf )
Nrb   rc   r   r?   r9   r:   r;   r<   Ú
)rA   rD   rB   r2   rI   )rR   rz   r�   rU   Úrow_listÚrowÚ
image_rowsÚcol_listÚcolÚ
image_colsÚtext_split_imagesÚn_hÚn_ws                r+   Úreplace_image_tokenÚ+ColModernVBertProcessor.replace_image_tokenì   s§  € Ø*6°vÒ*>ÔSÒ*>˜hË(À3’cÉ(‘cÑ*>ÒSÐT]Ñ^ˆ
Ø*6°vÒ*>ÔSÒ*>˜hË(À3’cÉ(‘cÑ*>ÒSÐT]Ñ^ˆ
Ø˜‹?˜z¨Q›à×(Ñ(Ð)Ø×*Ñ*Ð+ñ-à×%Ñ%Ð&¨$×*<Ñ*<Ñ<ñ=ð ×*Ñ*Ð+ñ-ðð !#ÐÜ˜ZÖ(�Ü  Ö,�CØ%Ø×0Ñ0Ð1Ø! #¨¡' ¨%°°a±¨y¸Ð:ñ;à!×-Ñ-Ð.°$×2DÑ2DÑDñEñÒ%ñ -ð " TÑ)Ò!ñ )ð Ø�T×*Ñ*Ð+Ð,Ø×*Ñ*Ð+ñ-à×%Ñ%Ð&¨$×*<Ñ*<Ñ<ñ=ð ×*Ñ*Ð+ñ-ñÐð %Ð$ùó5 TùÛSs
   ‰E¬Erg   r|   c                 ó’  • / n[        U5       Hµ  u  pE[        R                  " X   5      n[        R                  " U5      n[        R                  " X`R
                  :H  5      S   nSn	U H6  n
U	[        U5      :¼  a    O&X‰   nXº-   nSX{U& [        R                  " XŒ5      n	M8     UR                  UR                  5       5        M·     U$ )Nr   r:   )
rt   ÚnpÚarrayÚ
zeros_likeÚwhererG   r�   Úsearchsortedrv   Útolist)rR   rg   r|   rh   rV   Úseq_lengthsÚ	array_idsÚmm_token_typesÚimage_start_positionsrW   Úseq_lenr€   r�   s                r+   rw   Ú0ColModernVBertProcessor.create_mm_token_type_ids	  sÂ   € ð ÐÜ'Ð(?Ö@‰NˆAÜŸš ¡Ó.ˆIÜŸ]š]¨9Ó5ˆNÜ$&§H¢H¨Y×:RÑ:RÑ-RÓ$SÐTUÑ$VÐ!ØˆAÛ&�ØœÐ1Ó2Ó2ÙØ-Ñ0�Ø‘o�Ø,-� SÐ)Ü—O’OÐ$9Ó?’ñ 'ð ×$Ñ$ ^×%:Ñ%:Ó%<Ö=ñ Að !Ð r*   c                 ó   • 0 nUbú  [         R                  R                  S0 5      nUR                  U5        U Vs/ s H!  nU R                  R
                  " / UQUP76 PM#     nnU R                  S-   nU R                  S-   n[        U R                  SSS9S   5      S-
  n	/ n
/ nU HA  u  pÍnXŽ-  S-   nUS	:”  a  U	OS	nU
R                  UU-   Xý-  -   5        UR                  U5        MC     UR                  X«S
.5        [        S0 UD6$ s  snf )a{  
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.

Args:
    image_sizes (`list[list[int]]`, *optional*):
        The input sizes formatted as (height, width) per each image.

Returns:
    `MultiModalData`: A `MultiModalData` object holding number of tokens per each of the provided
    input modalities, along with other useful data.
r!   r   é   z

F)rN   rg   r:   r   )Únum_image_tokensÚnum_image_patchesr#   )r   r(   ÚgetÚupdaterS   Úget_number_of_image_patchesr2   r�   rT   rv   r   )rR   Úimage_sizesrU   Úvision_datar!   Ú
image_sizeÚnum_image_row_colsÚbase_image_lengthÚ
col_lengthÚextra_split_newlinerº   r»   Únum_patchesÚnum_rowsÚnum_colsÚ
row_lengthÚsplit_extras                    r+   Ú_get_num_multimodal_tokensÚ2ColModernVBertProcessor._get_num_multimodal_tokens  sC  € ð ˆØÑ"Ü9×CÑC×GÑGÈÐY[Ó\ˆMØ× Ñ  Ô(ñ #.ó"â"-�Jð ×$Ñ$×@Ò@Ð\À*Ð\ÈmÕ\Ù"-ð ð "ð
 !%× 2Ñ 2°QÑ 6ÐØ×+Ñ+¨aÑ/ˆJô
 #& d§n¡n°VÐPU nÐ&VÐWbÑ&cÓ"dÐghÑ"hÐØ!ÐØ "Ðã3EÑ/� xØ'Ñ2°QÑ6�
Ø5=À³\Ñ1Àq�Ø ×'Ñ'Ð(9¸KÑ(GÈ:ÑK`Ñ(aÔbØ!×(Ñ(¨Ö5ñ	 4Fð ×ÑÐ4DÑmÔnäÑ, Ñ,Ð,ùò/"s   »(Dc                 óº  • U R                   " [        4SU R                  R                  0UD6nUS   R	                  SS5      nUSLn[        U5      (       a  U/nOw[        U[        5      (       a  [        US   5      (       a  ON[        U[        5      (       a.  [        US   [        5      (       a  [        US   S   5      (       d  [        S5      eU Vs/ s H  ofR                  S5      PM     nnU R                  U R                  /[        U5      -  UUS   US   S	9nU(       a.  US
   R                  US   S:H  S5      nUR                  SU05        U$ s  snf )au  
Prepare for the model one or several image(s). Handles input validation, RGB conversion,
and prepends the `visual_prompt_prefix` to each image. Optionally computes labels from
`token_type_ids` when a `suffix` is provided in `text_kwargs`.

Args:
    images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `list[PIL.Image.Image]`, `list[np.ndarray]`, `list[torch.Tensor]`):
        The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
        tensor. In case of a NumPy array/PyTorch tensor, each image should be of shape (C, H, W), where C is a
        number of channels, H and W are image height and width.
    return_tensors (`str` or [`~utils.TensorType`], *optional*):
        If set, will return tensors of a particular framework. Acceptable values are:

        - `'pt'`: Return PyTorch `torch.Tensor` objects.
        - `'np'`: Return NumPy `np.ndarray` objects.

Returns:
    [`BatchFeature`]: A [`BatchFeature`] with the following fields:

    - **input_ids** -- List of token ids to be fed to a model.
    - **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
      `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
      `None`).
    - **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
r_   r    ÚsuffixNr   zAimages must be an image, list of images or list of list of imagesÚRGBr!   )r\   r[   r!   r    rg   Útoken_type_idsiœÿÿÿÚlabels)ro   r   rT   rp   rq   r
   rˆ   rŠ   r—   Úconvertr„   r3   r�   Úmasked_fillr½   )	rR   r[   rU   ry   rÎ   Úreturn_token_type_idsri   Ú	batch_docrÑ   s	            r+   Úprocess_imagesÚ&ColModernVBertProcessor.process_imagesI  sj  € ð< ×*Ò*Ü)ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð ˜}Ñ-×1Ñ1°(¸DÓAˆà &¨dÐ 2Ðô ˜&×!Ñ!Ø�X‰FÜ˜¤×%Ñ%¬.¸À¹×*CÑ*CØÜ˜V¤T×*Ñ*¬z¸&À¹)ÄT×/JÑ/JÌ~Ð^dÐefÑ^gÐhiÑ^j×OkÑOkÜÐ`ÓaÐañ 5;Ó;²F¨5—-‘- Ö&±FˆÐ;ð —M‘MØ×+Ñ+Ð,¬s°6«{Ñ:ØØ'¨Ñ8Ø% mÑ4ð	 "ð 
ˆ	ö !Ø˜{Ñ+×7Ñ7¸	ÐBRÑ8SÐWXÑ8XÐZ^Ó_ˆFØ×Ñ˜h¨Ð/Ô0àÐùò <s   ÃEc                 óÄ  • U R                   " [        4SU R                  R                  0UD6nUS   R	                  SS5      n[        U[        5      (       a  U/nO8[        U[        5      (       a  [        US   [        5      (       d  [        S5      eUc  U R                  S-  nU Vs/ s H  oPR                  U-   U-   PM     nnU R                  USUS   S	9nU$ s  snf )
aÌ  
Prepare for the model one or several text queries. Handles input validation, prepends the
`query_prefix`, and appends query augmentation tokens (used to pad query embeddings for
better late-interaction retrieval performance).

Args:
    text (`str`, `list[str]`, `list[list[str]]`):
        The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
        (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
        `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
    return_tensors (`str` or [`~utils.TensorType`], *optional*):
        If set, will return tensors of a particular framework. Acceptable values are:

        - `'pt'`: Return PyTorch `torch.Tensor` objects.
        - `'np'`: Return NumPy `np.ndarray` objects.

Returns:
    [`BatchFeature`]: A [`BatchFeature`] with the following fields:

    - **input_ids** -- List of token ids to be fed to a model.
    - **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
      `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
      `None`).
r_   r    rÎ   Nr   z*Text must be a string or a list of stringsé
   F)r\   rÔ   r    )ro   r   rT   rp   rq   rˆ   r‰   rŠ   r—   rQ   r4   r„   )rR   r\   rU   ry   rÎ   ÚqueryÚtexts_queryÚbatch_querys           r+   Úprocess_queriesÚ'ColModernVBertProcessor.process_queries‹  s÷   € ð: ×*Ò*Ü)ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð ˜}Ñ-×1Ñ1°(¸DÓAˆä�dœC× Ñ Ø�6‰DÜ˜T¤4×(Ñ(¬Z¸¸Q¹Ä×-EÑ-EÜÐIÓJÐJð ‰>Ø×2Ñ2°RÑ7ˆFñ SWÓ!WÒRVÈ×"3Ñ"3°eÑ";¸fÔ"DÑRVˆÐ!Wà—m‘mØØ"'Ø% mÑ4ð $ð 
ˆð Ðùò "Xs   Â*CÚquery_embeddingsztorch.TensorÚpassage_embeddingsÚ
batch_sizeÚoutput_dtypeztorch.dtypeÚoutput_deviceztorch.devicec           	      óÊ  • [        U5      S:X  a  [        S5      e[        U5      S:X  a  [        S5      eUS   R                  US   R                  :w  a  [        S5      eUS   R                  US   R                  :w  a  [        S5      eUc  US   R                  n/ n[	        S[        U5      U5       GH  n/ n[
        R                  R                  R                  R                  XXs-    SSS9n	[	        S[        U5      U5       H}  n
[
        R                  R                  R                  R                  X*X£-    SSS9nUR                  [
        R                  " SX›5      R                  S	S
9S   R                  SS
95        M     UR                  [
        R                  " USS
9R                  U5      R                  U5      5        GM     [
        R                  " USS
9$ )aÃ  
Compute the late-interaction/MaxSim score (ColBERT-like) for the given multi-vector
query embeddings (`qs`) and passage embeddings (`ps`). For ColQwen2, a passage is the
image of a document page.

Because the embedding tensors are multi-vector and can thus have different shapes, they
should be fed as:
(1) a list of tensors, where the i-th tensor is of shape (sequence_length_i, embedding_dim)
(2) a single tensor of shape (n_passages, max_sequence_length, embedding_dim) -> usually
    obtained by padding the list of tensors.

Args:
    query_embeddings (`Union[torch.Tensor, list[torch.Tensor]`): Query embeddings.
    passage_embeddings (`Union[torch.Tensor, list[torch.Tensor]`): Passage embeddings.
    batch_size (`int`, *optional*, defaults to 128): Batch size for computing scores.
    output_dtype (`torch.dtype`, *optional*, defaults to `torch.float32`): The dtype of the output tensor.
        If `None`, the dtype of the input embeddings is used.
    output_device (`torch.device` or `str`, *optional*, defaults to "cpu"): The device of the output tensor.

Returns:
    `torch.Tensor`: A tensor of shape `(n_queries, n_passages)` containing the scores. The score
    tensor is saved on the "cpu" device.
r   zNo queries providedzNo passages providedz/Queries and passages must be on the same devicez-Queries and passages must have the same dtypeT)Úbatch_firstÚpadding_valuezbnd,csd->bcnsr   )Údimr¹   r:   )r�   r—   ÚdeviceÚdtyperI   r-   ÚnnÚutilsÚrnnÚpad_sequencerv   ÚeinsumÚmaxr™   ÚcatÚto)rR   rß   rà   rá   râ   rã   ÚscoresrV   Úbatch_scoresÚbatch_queriesrW   Úbatch_passagess               r+   Úscore_retrievalÚ'ColModernVBertProcessor.score_retrievalÄ  sÍ  € ô@ ÐÓ  AÓ%ÜÐ2Ó3Ð3ÜÐ!Ó" aÓ'ÜÐ3Ó4Ð4à˜AÑ×%Ñ%Ð);¸AÑ)>×)EÑ)EÓEÜÐNÓOÐOà˜AÑ×$Ñ$Ð(:¸1Ñ(=×(CÑ(CÓCÜÐLÓMÐMàÑØ+¨AÑ.×4Ñ4ˆLà%'ˆä�qœ#Ð.Ó/°×<ˆAØ/1ˆLÜ!ŸH™HŸN™N×.Ñ.×;Ñ;Ø  Q¡^Ð4À$ÐVWð <ð ˆMô ˜1œcÐ"4Ó5°zÖB�Ü!&§¡§¡×!3Ñ!3×!@Ñ!@Ø&¨1©>Ð:ÈÐ\]ð "Að "�ð ×#Ñ#Ü—L’L °-ÓP×TÑTÐYZÐTÐ[Ð\]Ñ^×bÑbÐghÐbÐiöñ	 Cð �M‰Mœ%Ÿ)š) L°aÑ8×;Ñ;¸LÓI×LÑLÈ]Ó[×\ñ =ô �yŠy˜ QÑ'Ð'r*   )rM   rC   rA   rG   rD   rH   r2   rB   rF   rQ   r4   rJ   r3   )NNé@   NN)NNN)NN)N)é€   NÚcpu)r$   r%   r&   r'   r   Úvalid_processor_kwargsÚintr‰   rP   r   r	   rŠ   r   r   r   r   r„   rm   rn   Údictr©   rw   rË   r   rÖ   rÝ   r   rö   r)   Ú__classcell__)rY   s   @r+   r0   r0   6   s¹  ø† ð ;Ðð
 ØØØ+/Ø#'ñ3Dð
 ð3Dð " D™jð3Dð ˜D‘j÷3Dð 3Dðj ð JNØbfØ$(ñ	>^à˜T *Ñ-Ñ-°°T¸*Ñ5EÑ0FÑFð>^ð �IÐ2°D¸±OÀTÐJ]ÑE^Ð^Ñ_ð>^ð ˜T‘zð	>^ð
 Ð6Ñ7ð>^ð 
ô>^ó ð>^ðD %)Øbfñ à˜TÑ!ð ð �IÐ2°D¸±OÀTÐJ]ÑE^Ð^Ñ_ð ð Ð6Ñ7õ	 ðH %)Øbfñà˜TÑ!ðð �IÐ2°D¸±OÀTÐJ]ÑE^Ð^Ñ_ðð Ð6Ñ7÷	ð ð2%°ð %Àð %ÐSVô %ð:!°$ð !ÐQUÐVYÑQZð !Ð_cÐdhÐilÑdmÑ_nô !ô*)-ðZ %)ñ@à˜TÑ!ð@ð Ð6Ñ7ð@ð 
õ	@ðD7à˜$˜y™/Ñ)ð7ð Ð6Ñ7ð7ð 
ô	7ðz Ø04Ø49ñ>(à °°^Ñ0DÐ DÑEð>(ð " .°$°~Ñ2FÐ"FÑGð>(ð ð	>(ð
 ˜}Ñ-ð>(ð ˜^¨SÐ0Ñ1ð>(ð 
÷>(ó >(r*   r0   ) rK   Ú	itertoolsr   Útypingr   r   r   Únumpyr¬   r-   Úfeature_extraction_utilsr   Úimage_utilsr	   r
   Úprocessing_utilsr   r   r   r   Útokenization_utils_baser   r   r   rë   r   Úutils.import_utilsr   r   r   r0   Ú__all__r#   r*   r+   Ú<module>r     s~   ðó* 
Ý  ß 1Ñ 1ã Û å 4ß 5ß XÓ Xß KÑ KÝ #Ý *ö Ý<ôÐ$4¸Eò ñ 
�:ÑØôJ(˜nó J(ó ó ðJ(ðZ %Ð
%�r*   