+
    œ°³jƒ"  ã                   óò   € ^ RI HtHt ^ RIHt ^RIHt ^RIHtH	t	 ^RI
HtHtHt ^RIHtHt ^RIHtHtHt ]! 4       '       d   ^ RIt]P,                  ! ]4      t ! R	 R
]RR7      t ! R R]4      tR.tR# )é    )ÚOptionalÚUnion)ÚPaliGemmaProcessor)ÚBatchFeature)Ú
ImageInputÚmake_flat_list_of_images)ÚProcessingKwargsÚProcessorMixinÚUnpack)ÚPreTokenizedInputÚ	TextInput)Úauto_docstringÚis_torch_availableÚloggingNc                   ó>   € ] tR t^ tRRRRRRR/RRR	R
R/RRR//tRtR# )ÚColPaliProcessorKwargsÚtext_kwargsÚpaddingÚlongestÚreturn_mm_token_type_idsFÚreturn_text_replacement_offsetsÚimages_kwargsÚdata_formatÚchannels_firstÚdo_convert_rgbTÚcommon_kwargsÚreturn_tensorsÚpt© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú	_defaultsÚ__static_attributes__r   ó    Úl/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/colpali/modular_colpali.pyr   r       sB   † àØ�yØ&¨Ø-¨uð
ð
 	ØÐ+Ø˜dð
ð 	Ð*¨DÐ1ð„Ir&   r   F)Útotalc                   ó"  a a€ ] tR t^/t o]tRV3R lV 3R lllt]V3R lR l4       t]	RV3R lR ll4       t
RV3R lR lltRR	 ltV3R
 lR lt]	! RR7      RV3R lR ll4       t]	! RR7      V3R lR l4       tRV3R lR lltRtVtV ;t# )ÚColPaliProcessorc                ó&   <€ V ^8„  d   QhRS[ RS[ /# )é   Úvisual_prompt_prefixÚquery_prefix©Ústr)ÚformatÚ__classdict__s   "€r'   Ú__annotate__ÚColPaliProcessor.__annotate__2   s%   ø€ ÷ lñ lñ
 "ðlñ ñlr&   c                óB   <€ W@n         WPn        \        SV `  WVR7       R# )zù
visual_prompt_prefix (`str`, *optional*, defaults to `"Describe the image."`):
    A string that gets tokenized and prepended to the image tokens.
query_prefix (`str`, *optional*, defaults to `"Question: "`):
    A prefix to be used for the query.
)Úimage_processorÚ	tokenizerÚchat_templateN)r-   r.   ÚsuperÚ__init__)Úselfr6   r7   r8   r-   r.   Ú	__class__s   &&&&&&€r'   r:   ÚColPaliProcessor.__init__2   s$   ø€ ð %9Ô!Ø(ÔÜ‰Ñ¨Ð]jÐÖkr&   c                ó    <€ V ^8„  d   QhRS[ /# )r,   Úreturnr/   )r1   r2   s   "€r'   r3   r4   E   s   ø€ ÷ (ñ (©#ñ (r&   c                ó.   € V P                   P                  # )zr
Return the query augmentation token.

Query augmentation buffers are used as reasoning buffers during inference.
)r7   Ú	pad_token)r;   s   &r'   Úquery_augmentation_tokenÚ)ColPaliProcessor.query_augmentation_tokenD   s   € ð �~‰~×'Ñ'Ð'r&   c                ó    <€ V ^8„  d   QhRS[ R,          RS[S[,          S[S[,          ,          S[S[,          ,          RS[S[,          RS[/# )r,   ÚimagesNÚtextÚkwargsr?   )r   r   r   Úlistr   r   r   )r1   r2   s   "€r'   r3   r4   N   sX   ø€ ÷ ñ á˜TÕ!ðñ Ñ+Õ+©d±9­oÕ=ÁÑEVÕ@WÕWðñ Ñ/Õ0ð	ñ
 
ñr&   c                óz  € Ve   Ve   \        R4      hRVR&   V P                  ! V P                  3RV P                  P                  /VB pVR,          P                  RV P                  ^
,          4      pVey   V Uu. uF+  q`P                  P                   V P                   V V R2NK-  	  ppVR,          P                  RR 4      e'   VR,          R;;,          V P                  ,          uu&   \        P                  ! RR	VR
V/VB pVe'   VR,          P                  VR,          ^ 8H  R4      VR&   V# u upi )Nz5Only one of text or images can be processed at a timeTÚreturn_token_type_idsÚtokenizer_init_kwargsr   ÚsuffixÚ
Ú
max_lengthrE   rF   Ú	input_idsÚtoken_type_idsÚlabelsr   iœÿÿÿ)Ú
ValueErrorÚ_merge_kwargsÚvalid_processor_kwargsr7   Úinit_kwargsÚpoprB   Ú	bos_tokenr.   ÚgetÚimage_seq_lengthr
   Ú__call__Úmasked_fill)r;   rE   rF   rG   Úoutput_kwargsrL   ÚsampleÚmodel_inputss   &&&,    r'   rZ   ÚColPaliProcessor.__call__M   sL  € ð Ò Ò 2ÜÐTÓUÐUà*.ˆÐ&Ñ'Ø×*Ò*Ø×'Ñ'ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð
 ˜}Õ-×1Ñ1°(¸D×<YÑ<YÐ\^Õ<^Ó_ˆàÒÙeiÓjÑeiÐ[a—~‘~×/Ñ/Ð0°×1BÑ1BÐ0CÀFÀ8ÈFÈ8ÐSUÓVÑeiˆDÐjØ˜]Õ+×/Ñ/°¸dÓCÒOØ˜mÕ,¨\×:¸d×>SÑ>SÕSÓ:ä%×.Ò.ÑY°fÐYÀ4ÐYÈ=ÑYˆØÒØ%1°+Õ%>×%JÑ%JÈ<ÐXhÕKiÐmnÑKnÐptÓ%uˆL˜Ñ"ØÐùò ks   Á>1D8c                ó¨   <€ V ^8„  d   QhRS[ R,          RS[S[,          S[S[,          ,          S[S[,          ,          R,          RS[S[,          /# )r,   rE   NrF   rG   )r   r   r   rH   r   r	   )r1   r2   s   "€r'   r3   r4   i   sY   ø€ ÷ Gñ Gá˜TÕ!ðGñ Ñ+Õ+©d±9­oÕ=ÁÑEVÕ@WÕWÐZ^Õ^ðGñ Ñ)Õ*ñ	Gr&   c                ó^   € \         P                  ! WR 7       Vf   Vf   \        R4      hR# R# ))rE   rF   Nz&Either text or images must be provided)r
   Úvalidate_inputsrR   )r;   rE   rF   rG   s   &&&,r'   rb   Ú ColPaliProcessor.validate_inputsi   s.   € ô 	×&Ò&¨fÕ@ØŠ<˜FšNÜÐEÓFÐFñ +‰<r&   c                ó  € \         P                  ! RR VRV/VB vrpVe^   \        V4      p\        \	        V4      4       Uu. uF4  pV P
                   V P                  P                   V P                   R2NK6  	  ppWRR3# u upi )rE   rF   NrM   r   )	r
   Úprepare_inputs_layoutr   ÚrangeÚlenÚimage_tokenr7   rW   r-   )r;   rE   rF   rG   Ú_s   &&&, r'   re   Ú&ColPaliProcessor.prepare_inputs_layouts   sž   € Ü)×?Ò?ÑcÀvÐcÐTXÐcÐ\bÑcÐˆ�qØÒÜ-¨fÓ5ˆFô œs 6›{Ô+óá+�Að ×#Ñ#Ð$ T§^¡^×%=Ñ%=Ð$>¸t×?XÑ?XÐ>YÐY[Ó\Ù+ð ð ð ˜T 4Ð'Ð'ùò	s   Á:Bc                ó,   <€ V ^8„  d   QhRS[ RS[RS[/# )r,   Úimage_inputsÚ	image_idxr?   )ÚdictÚintr0   )r1   r2   s   "€r'   r3   r4   }   s#   ø€ ÷ 8ñ 8±ð 8Áð 8ÑSVñ 8r&   c                ó<   € V P                   V P                  ,          # ©N)rh   rY   )r;   rl   rm   rG   s   &&&,r'   Úreplace_image_tokenÚ$ColPaliProcessor.replace_image_token}   s   € Ø×Ñ $×"7Ñ"7Õ7Ð7r&   znThis method forwards the `images` and `kwargs` arguments to ColPaliProcessor's [`~ColPaliProcessor.__call__`].)Úcustom_introc                ó4   <€ V ^8„  d   QhRS[ R,          RS[/# )r,   rE   Nr?   )r   r   )r1   r2   s   "€r'   r3   r4   ƒ   s$   ø€ ÷ 6ñ 6á˜TÕ!ð6ñ 
ñ	6r&   c                ó*   € V P                   ! RR V/VB # )rE   r   ©rZ   )r;   rE   rG   s   &&,r'   Úprocess_imagesÚColPaliProcessor.process_images€   s   € ð �}Š}Ñ5 FÐ5¨fÑ5Ð5r&   zlThis method forwards the `text` and `kwargs` arguments to ColPaliProcessor's [`~ColPaliProcessor.__call__`].c                óF   <€ V ^8„  d   QhRS[ S[S[ ,          ,          RS[/# )r,   rF   r?   )r   rH   r   )r1   r2   s   "€r'   r3   r4   �   s(   ø€ ÷ 2ñ 2á™$™y�/Õ)ð2ñ 
ñ	2r&   c                ó*   € V P                   ! RR V/VB # )rF   r   rw   )r;   rF   rG   s   &&,r'   Úprocess_queriesÚ ColPaliProcessor.process_queriesŠ   s   € ð �}Š}Ñ1 $Ð1¨&Ñ1Ð1r&   c                ó¢   <€ V ^8„  d   QhRS[ RS[R,          3,          RS[ RS[R,          3,          RS[RS[R,          RS[ RS[3,          R	R/# )
r,   Úquery_embeddingsztorch.TensorÚpassage_embeddingsÚ
batch_sizeÚoutput_dtypeztorch.dtypeÚoutput_deviceztorch.devicer?   )r   rH   ro   r   r0   )r1   r2   s   "€r'   r3   r4   ”   st   ø€ ÷ >(ñ >(á ±°^Õ0DÐ DÕEð>(ñ " .±$°~Õ2FÐ"FÕGð>(ñ ð	>(ñ
 ˜}Õ-ð>(ñ ˜^©SÐ0Õ1ð>(ð 
ñ>(r&   c           	     ó8  € \        V4      ^ 8X  d   \        R4      h\        V4      ^ 8X  d   \        R4      hV^ ,          P                  V^ ,          P                  8w  d   \        R4      hV^ ,          P                  V^ ,          P                  8w  d   \        R4      hVf   V^ ,          P                  p. p\	        ^ \        V4      V4       EF1  p. p\
        P                  P                  P                  P                  WWs,            R^ R7      p	\	        ^ \        V4      V4       FŽ  p
\
        P                  P                  P                  P                  W*W£,            R^ R7      pVP                  \
        P                  ! RW›4      P                  ^R7      ^ ,          P                  ^R7      4       K�  	  VP                  \
        P                  ! V^R7      P                  V4      P                  V4      4       EK4  	  \
        P                  ! V^ R7      # )	aÂ  
Compute the late-interaction/MaxSim score (ColBERT-like) for the given multi-vector
query embeddings (`qs`) and passage embeddings (`ps`). For ColPali, 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.
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->bcns)Údim)rg   rR   ÚdeviceÚdtyperf   ÚtorchÚnnÚutilsÚrnnÚpad_sequenceÚappendÚeinsumÚmaxÚsumÚcatÚto)r;   r   r€   r�   r‚   rƒ   ÚscoresÚiÚbatch_scoresÚbatch_queriesÚjÚbatch_passagess   &&&&&&      r'   Úscore_retrievalÚ ColPaliProcessor.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&   )r.   r-   )NNNzDescribe the image.z
Question: )NNrq   )é€   NÚcpu)r    r!   r"   r#   r   rT   r:   ÚpropertyrB   r   rZ   rb   re   rr   rx   r|   r›   r%   Ú__classdictcell__Ú__classcell__)r<   r2   s   @@r'   r*   r*   /   s±   ù‡ € Ø3Ð÷lõ lð$ ÷(ó ð(ð ÷ñ ó ð÷6Gò Gô(÷8ð 8ñ ð Fô÷6ñ 6óð6ñ ð Dô÷2óð2÷>(÷ >(ò >(r&   r*   )Útypingr   r   Ú2transformers.models.paligemma.processing_paligemmar   Úfeature_extraction_utilsr   Úimage_utilsr   r   Úprocessing_utilsr	   r
   r   Útokenization_utils_baser   r   rŒ   r   r   r   rŠ   Ú
get_loggerr    Úloggerr   r*   Ú__all__r   r&   r'   Ú<module>r«      sk   ð÷ #å Qå 4ß ?ß HÑ Hß Cß @Ñ @ñ ×ÒÛà	×	Ò	˜HÓ	%€ôÐ-°Uõ ôc(Ð)ô c(ðN ð‚r&   