ó
    >:jh\ ã                  ó  • % S SK Jr  S SKrS SKrS SKJr  S SKJr  S SKJ	r	  S SK
JrJrJrJrJrJ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JrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2  S S
KJ3r4  S SK5J6r6  S SK5J7r8  S SK9J:r:  S SK;J<r<  S SK=J>r>J?r?  S SK@JArAJBrB  S SKCJDrDJErEJFrFJGrGJHrH  S SKIJJrJ  S SKKJLrL  S SKMJNrN   S SK
JOrO   S SKJRrR   S SKJSrSJTrT   S SKJUrU   S S!KJVrV   S S$KJWrW  \(       a  \:" 5       (       a  S S'KXJYrY  \8R´                  " \[5      r\\" \45      \" S(5      :„  r]\" \45      \" S)5      :¬  r^\S*   r_ " S+ S,\5      r` " S- S.\`S/S09ra\b\F\a4   rc\\\\S1.rdS2\eS3'    S S4KJfrf  \f\dS5'   S6S7S8S9.0S:4S6S7S;S9.0S<4S6S7S;S9.0S=4S6S7S;S9.0S=4S6S7S;S9.0S:4S*.rgS>\eS?'   \/S@SA4\&S@SB4\1S@SC4\0S@SD4\#S@SE4\-S@SF4\.S@SG4\SHSI4\ SJSK4\$SLSM4\'SNSO4\(SPSQ4\VSRSS4\2STSU4\%SVSW4\TSXSY4/rhSZ\eS['   S7S8S9.S7S8S9.S\.S:S/4riS]\eS^'   0 S_S`SaS9.SbSaS9.ScSaS9.Sd.SeSf4_SgS`S8S9.SbS8S9.Sh.S:Sf4_SiS`S8S9.SjS8S9.Sh.S:Sf4_SkS`SaS9.SbSaS9.Sh.S:Sf4_SlS7S8S9.S7S8S9.Sm.S:S/4_SnS7S8S9.S7S8S9.Sm.S:S/4_SoSpS7S8S9.0S:S/4_SqSpS7S8S9.0S:S/4_SrSpS7S8S9.0S:S/4_SsSpS7S8S9.0S:S/4_StS7S8S9.S7S8S9.Su.S:S/4_SvS7S8S9.S7S8S9.S7S8S9.Sd.S:S/4_Sw\i_Sx\i_Sy\i_Sz\i_S{\i_\i\i\i\i\i\iS|.ErjS}\eS~'   SS€S7S;S9.0S:S/40rkS}\eS�'   S7S;S9.S7S;S9.Sm.S=S/4S6S7S;S9.0S=S/4S‚.rlS7S;S9.S7S;S9.Sm.S=S/4SpS7S;S9.0S=S/4SpS7S;S9.0S=S/4SpS7S;S9.0S=S/4SpS7S;S9.0S=S/4S7S;S9.S7S;S9.S\.S=S/4Sƒ.rm\j\l\m\kS„.rnS…\eS†'   SŽS‡ jro\Sˆ 5       rp " S‰ SŠ\S/S09rqS�S‹ jrr " SŒ S�\J5      rsg! \P a
    S SKQJOrO   GN®f = f! \P a     " S S5      rR GN¾f = f! \P a     " S S5      rS " S S5      rT GNÖf = f! \P a     " S S 5      rU GNæf = f! \P a     " S" S#5      rV GNöf = f! \P a     " S% S&5      rW GNf = f! \P a     GN�f = f)�é    )ÚannotationsN)ÚCallable)Úcontextmanager)Úfields)ÚTYPE_CHECKINGÚAnyÚLiteralÚ	TypedDictÚget_argsÚget_type_hints)Úparse)Ú	LowercaseÚSequence)Ú
AutoConfigÚ	AutoModelÚAutoModelForCausalLMÚAutoModelForMaskedLMÚ"AutoModelForSequenceClassificationÚAutoProcessorÚBlenderbotConfigÚBlenderbotSmallConfigÚFeatureExtractionMixinÚImageProcessingMixinÚLongT5ConfigÚM2M100ConfigÚMarianConfigÚ	MT5ConfigÚPegasusConfigÚPegasusXConfigÚPretrainedConfigÚPreTrainedModelÚPreTrainedTokenizerBaseÚProcessorMixinÚProphetNetConfigÚSwitchTransformersConfigÚT5ConfigÚ
UdopConfigÚ
UMT5ConfigÚWhisperConfig)Ú__version__)ÚModelOutput)Úlogging)Úis_peft_available)Úfind_adapter_config_file)Úload_onnx_modelÚload_openvino_model)ÚInputFormatterÚformat_modality)ÚMODALITY_TO_PROCESSOR_ARGÚMessageInputÚModalityÚ	PairInputÚSingleInput)ÚInputModule)Útransformer_kwargs_decorator)Úsuggest_extra_on_exception)ÚSelf)ÚBaseVideoProcessorc                  ó   • \ rS rSrSrg)r<   éE   © N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r?   ó    Úk/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sentence_transformers/base/modules/transformer.pyr<   r<   E   ó   † ÚrF   r<   )ÚT5Gemma2ConfigÚT5Gemma2TextConfigc                  ó   • \ rS rSrSrg)rI   éM   r?   Nr@   r?   rF   rG   rI   rI   M   rH   rF   rI   c                  ó   • \ rS rSrSrg)rJ   éP   r?   Nr@   r?   rF   rG   rJ   rJ   P   rH   rF   rJ   )ÚT5GemmaConfigc                  ó   • \ rS rSrSrg)rO   éX   r?   Nr@   r?   rF   rG   rO   rO   X   rH   rF   rO   )ÚMoonshineConfigc                  ó   • \ rS rSrSrg)rR   é`   r?   Nr@   r?   rF   rG   rR   rR   `   rH   rF   rR   )ÚTimmWrapperConfigc                  ó   • \ rS rSrSrg)rU   éh   r?   Nr@   r?   rF   rG   rU   rU   h   rH   rF   rU   ©Ú
PeftConfigz4.56.1z
5.4.0.dev0)úfeature-extractionúsequence-classificationútext-generationú
any-to-anyú	fill-maskc                  ó*   • \ rS rSr% S\S'   S\S'   Srg)Ú_ModalityParamsRequiredé{   ÚstrÚmethodú
str | NoneÚmethod_output_namer?   N)rA   rB   rC   rD   Ú__annotations__rE   r?   rF   rG   r`   r`   {   s   ‡ ØƒKØ"Ö"rF   r`   c                  ó$   • \ rS rSr% SrS\S'   Srg)ÚModalityParamsé€   zûParameters for a single modality entry in the modality config.

The ``format`` key is only used for the ``"message"`` modality and controls how
message content is structured: ``"structured"`` (list of typed dicts) or ``"flat"``
(direct string value).
zLiteral['structured', 'flat']Úformatr?   N©rA   rB   rC   rD   Ú__doc__rf   rE   r?   rF   rG   rh   rh   €   s   ‡ ñð *Ö)rF   rh   F)Útotal)rZ   r[   r\   r^   zdict[TransformerTask, Any]ÚTRANSFORMER_TASK_TO_AUTO_MODEL)ÚAutoModelForMultimodalLMr]   ÚtextÚforwardÚlast_hidden_state©rc   re   Útoken_embeddingsÚlogitsÚscoresÚcausal_logitsz1dict[TransformerTask, tuple[ModalityConfig, str]]ÚTRANSFORMER_TASK_DEFAULTSÚtransformersÚT5EncoderModelÚMT5EncoderModelÚUMT5EncoderModelÚUdopEncoderModelÚLongT5EncoderModelÚProphetNetEncoderÚSwitchTransformersEncoderModelz2transformers.models.blenderbot.modeling_blenderbotÚBlenderbotEncoderz>transformers.models.blenderbot_small.modeling_blenderbot_smallÚBlenderbotSmallEncoderz,transformers.models.m2m_100.modeling_m2m_100ÚM2M100Encoderz,transformers.models.pegasus.modeling_pegasusÚPegasusEncoderz0transformers.models.pegasus_x.modeling_pegasus_xÚPegasusXEncoderz0transformers.models.moonshine.modeling_moonshineÚMoonshineEncoderz,transformers.models.whisper.modeling_whisperÚWhisperEncoderz*transformers.models.marian.modeling_marianÚMarianEncoderz.transformers.models.t5gemma2.modeling_t5gemma2ÚT5Gemma2Encoderzlist[tuple[type, str, str]]Ú_ENCODER_ONLY_MODELS)Úaudio©r‹   rp   z tuple[ModalityConfig, str, bool]Ú_AUDIO_MODALITY_CONFIGÚblipÚget_text_featuresÚpooler_outputÚget_image_featuresÚget_multimodal_features)rp   Úimage©r“   rp   Úsentence_embeddingTúblip-2)rp   r“   Úsam3Úget_vision_featuresÚflavaÚgit)rp   r”   Úvisual_bertúkosmos-2r”   zgrounding-dinoÚ	paligemmaÚviltÚ
layoutlmv3)r“   r”   ÚideficsÚhubertÚ	moonshineÚsewzsew-dzunispeech-sat)Ú	unispeechÚwav2vec2zwav2vec2-conformerÚwavlmÚwhisperÚvoxtral_realtimez+dict[str, tuple[ModalityConfig, str, bool]]Ú_FEATURE_EXTRACTION_EDGE_CASESr¥   r‹   Ú_FILL_MASK_EDGE_CASES)rš   r§   )rš   rŽ   r–   rœ   r�   r¨   )rZ   r\   r]   r^   z6dict[str, dict[str, tuple[ModalityConfig, str, bool]]]Ú_EDGE_CASE_MODALITY_CONFIGSc                ó†   • U c  g[        U [        5      (       a  g[        U [        5      (       a  [        S U  5       5      $ g)zVCheck whether a tokenizers normalizer (or sequence of normalizers) includes Lowercase.FTc              3  óB   #   • U  H  n[        U[        5      v •  M     g 7f©N)Ú
isinstancer   )Ú.0Úns     rG   Ú	<genexpr>Ú!_has_lowercase.<locals>.<genexpr>¢  s   é € Ð@²Z°”:˜a¤×+Ð+²Zùó   ‚)r¯   r   r   Úany)Ú
normalizers    rG   Ú_has_lowercaser·   ›  s<   € àÑØÜ�*œi×(Ñ(ØÜ�*œh×'Ñ'ÜÑ@±ZÓ@Ó@Ð@ØrF   c           	   +  ó@  #   • U Vs0 s H  o"[        XS 5      _M     nn UR                  5        H  u  p$[        XU5        M     S v •  UR                  5        H  u  p$[        XU5        M     g s  snf ! UR                  5        H  u  p$[        XU5        M     f = f7fr®   )ÚgetattrÚitemsÚsetattr)ÚclsÚ	overridesÚnameÚ	originalsÚvalues        rG   Úset_temporary_class_attrsrÁ   ¦  s‹   é € á<EÓFºI°D”w˜s¨$Ó/Ò/¹I€IÐFð&Ø$Ÿ?™?Ö,‰KˆDÜ�C˜uÖ%ñ -ãà$Ÿ?™?Ö,‰KˆDÜ�C˜uÖ%ò -ùò Gøð %Ÿ?™?Ö,‰KˆDÜ�C˜uÖ%ò -üs&   ‚B‡A/�B )A4 Á	+BÁ4'BÂBc                  óV   • \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   S\S'   S\S	'   S
rg)ÚProcessingKwargsi²  a2  Keyword arguments applied when *calling* the processor during preprocessing.

Valid keys: ``"common"``, ``"text"``, ``"audio"``, ``"image"``, ``"video"``, ``"chat_template"``.
Modality and ``"common"`` kwargs override built-in defaults. ``"chat_template"`` kwargs are
forwarded to ``apply_chat_template``.
údict[str, Any]Úcommonrp   r‹   r“   ÚvideoÚchat_templater?   Nrk   r?   rF   rG   rÃ   rÃ   ²  s-   ‡ ñð ÓØ
ÓØÓØÓØÓØ!Ö!rF   rÃ   c                ój  • / n/ nU  H§  nSnSnU Hx  nUR                  S/ 5      n[        U[        5      (       d  M,  U HF  n[        U[        5      (       d  M  UR                  SS5      n	U	S:X  a  US-  nM9  U	S:X  d  MA  US-  nMH     Mz     UR	                  U5        UR	                  U5        M©     X4$ )ai  Count images and videos per sample from the message structure.

Some VLM processors flatten per-sample visual tokens into single tensors (e.g.
``pixel_values`` shape ``(total_visual_tokens, hidden_dim)``), losing the per-sample
association. By counting before the processor call, we get reliable per-sample counts
that downstream minibatching can use directly.
r   ÚcontentÚtypeÚ r“   é   rÆ   )Úgetr¯   ÚlistÚdictÚappend)
ÚmessagesÚ
num_imagesÚ
num_videosÚsample_messagesÚ	img_countÚ	vid_countÚmsgrÉ   ÚitemÚ	item_types
             rG   Ú_count_media_per_samplerÚ   Â  s¾   € ð €JØ€JÛ#ˆØˆ	Øˆ	Û"ˆCØ—g‘g˜i¨Ó,ˆGÜ˜g¤t×,Ñ,ÙÛ�Ü˜d¤D×)Ó)Ø $§¡¨°Ó 4�IØ  GÓ+Ø! Q™š	Ø" gÕ-Ø! Q™š	ó  ñ	 #ð 	×Ñ˜)Ô$Ø×Ñ˜)Ö$ñ $ð  Ð!Ð!rF   c                  ó:  ^ • \ rS rSr% SrSrS\S'   / SQrS\S'   S	rS
\S'   \	SSSSSSSSSSSSS.                           S5U 4S jjj5       r
\S6S j5       r\R                  S7S j5       rS8S jr\S9S j5       r\R                  S:S j5       r\S;S j5       r\S<S j5       r\S=S j5       r\S>S j5       r S?     S@S jjrSAS jrSBS jr          SCS jr          SCS jr          SCS  jr        SDS! jrSES" jr        SFS# jr            SGS$ jr      SHS% jr      SIS& jr      SJS' jr     SKS( jr!SLS) jr"\#SMS* j5       r$\#SNS+ j5       r%S	S,.SOS- jjr&\'          SP                       SQS. jj5       r(\'          SP                       SRS/ jj5       r)\'      SS               STU 4S0 jjj5       r*\#SUS1 j5       r+SVU 4S2 jjr,SWS3 jr-S4r.U =r/$ )XÚTransformeriß  a]  Hugging Face AutoModel wrapper that handles loading, preprocessing, and inference.

Loads the appropriate model class (e.g. BERT, RoBERTa, CLIP, Whisper) based on the model configuration
and the specified ``transformer_task``. Supports text, image, audio, and video modalities depending on
the underlying model. This module is typically the first module in a
:class:`~sentence_transformers.sentence_transformer.model.SentenceTransformer`, :class:`~sentence_transformers.sparse_encoder.model.SparseEncoder`,
or :class:`~sentence_transformers.cross_encoder.model.CrossEncoder` pipeline.

Args:
    model_name_or_path (str): Hugging Face model name or path to a local model directory.
    transformer_task (str, optional): The task determining which ``AutoModel``-like class to load.
        Supported values:

        - ``"feature-extraction"`` (default): :class:`~transformers.AutoModel`, e.g. used by
          :class:`~sentence_transformers.sentence_transformer.model.SentenceTransformer`.
        - ``"sequence-classification"``: :class:`~transformers.AutoModelForSequenceClassification`,
          e.g. used by :class:`~sentence_transformers.cross_encoder.model.CrossEncoder`.
        - ``"text-generation"``: :class:`~transformers.AutoModelForCausalLM`, e.g. used by generative
          :class:`~sentence_transformers.cross_encoder.model.CrossEncoder` models. Sets the ``tokenizer`` padding_side to "left".
        - ``"any-to-any"``: :class:`~transformers.AutoModelForMultimodalLM`, e.g. used by multimodal generative
          :class:`~sentence_transformers.cross_encoder.model.CrossEncoder` models (requires transformers v5+). Sets the
          ``tokenizer`` padding_side to "left".
        - ``"fill-mask"``: :class:`~transformers.AutoModelForMaskedLM`, e.g. used by
          :class:`~sentence_transformers.sparse_encoder.model.SparseEncoder`.

        Defaults to ``"feature-extraction"``.
    model_kwargs (dict[str, Any], optional): Keyword arguments forwarded to
        ``AutoModel.from_pretrained`` when loading the model. Particularly useful options include:

        - ``torch_dtype``: Override the default ``torch.dtype`` and load the model under a specific
          dtype. Can be ``torch.float16``, ``torch.bfloat16``, ``torch.float32``, or ``"auto"`` to
          use the dtype from the model's ``config.json``.
        - ``attn_implementation``: The attention implementation to use. For example ``"eager"``,
          ``"sdpa"``, or ``"flash_attention_2"``. If you ``pip install kernels``, then
          ``"flash_attention_2"`` should work without having to install ``flash_attn``. It is
          frequently the fastest option. Defaults to ``"sdpa"`` when available (torch>=2.1.1).
        - ``device_map``: Device map for model parallelism, e.g. ``"auto"``.
        - ``provider``: For ``backend="onnx"``, the ONNX execution provider
          (e.g. ``"CUDAExecutionProvider"``).
        - ``file_name``: For ``backend="onnx"`` or ``"openvino"``, the filename to load
          (e.g. for optimized or quantized models).
        - ``export``: For ``backend="onnx"`` or ``"openvino"``, whether to export the model to the
          backend format. Also set automatically if the exported file doesn't exist.

        See the `PreTrainedModel.from_pretrained
        <https://huggingface.co/docs/transformers/en/main_classes/model#transformers.PreTrainedModel.from_pretrained>`_
        documentation for more details. Defaults to None.
    processor_kwargs (dict[str, Any], optional): Keyword arguments forwarded to
        ``AutoProcessor.from_pretrained`` when loading the processor/tokenizer. See the
        `AutoTokenizer.from_pretrained
        <https://huggingface.co/docs/transformers/en/model_doc/auto#transformers.AutoTokenizer.from_pretrained>`_
        documentation for more details. Defaults to None.
    config_kwargs (dict[str, Any], optional): Keyword arguments forwarded to
        ``AutoConfig.from_pretrained`` when loading the config. See the `AutoConfig.from_pretrained
        <https://huggingface.co/docs/transformers/en/model_doc/auto#transformers.AutoConfig.from_pretrained>`_
        documentation for more details. Defaults to None.
    processing_kwargs (dict[str, dict[str, Any]], optional): Keyword arguments applied when *calling*
        the processor during preprocessing. This is a nested dict whose keys are modality names
        (``"text"``, ``"audio"``, ``"image"``, ``"video"``), ``"common"`` for kwargs shared across all
        modalities, or ``"chat_template"`` for kwargs forwarded to ``apply_chat_template`` (e.g.
        ``{"add_generation_prompt": True}``). Modality and common kwargs override the built-in defaults.
        Saved to and loaded from the model configuration file. Defaults to None.
    backend (str, optional): Backend used for model inference. Can be ``"torch"`` (default), ``"onnx"``,
        or ``"openvino"``. Defaults to ``"torch"``.
    modality_config (dict, optional): Custom modality configuration mapping modality names to method and
        output name dicts. When provided, ``module_output_name`` must also be set. The ``"message"``
        modality entry may include a ``"format"`` key (``"structured"``, ``"flat"``, or ``"auto"``)
        to control how chat-template inputs are formatted. Defaults to None.
    module_output_name (str, optional): The name of the output feature this module creates (e.g.
        ``"token_embeddings"``, ``"scores"``). Required when ``modality_config`` is provided.
        Defaults to None.
    unpad_inputs (bool, optional): Controls whether text-only inputs are concatenated without
        padding for faster inference using flash attention's variable-length functions. Non-text
        inputs (images, audio, video) are always padded normally. If ``None`` (default), unpadding
        is enabled automatically when all prerequisites are met (flash attention with variable-length
        support, ``"torch"`` backend, ``"feature-extraction"`` task). Set to ``False`` to force
        padding, which is needed for architectures that don't support unpadded inputs (e.g.
        ``qwen2_vl``). Set to ``True`` to request unpadding explicitly; a warning is logged if the
        prerequisites are not met. Defaults to None.
    max_seq_length (int, optional): Truncate any inputs longer than this value. Prefer setting
        ``model_max_length`` via ``processor_kwargs`` instead. Defaults to None.
    do_lower_case (bool, optional): If true, lowercases the input (independent of whether the model
        is cased or not). Rarely needed. Defaults to False.
    tokenizer_name_or_path (str, optional): Name or path of the tokenizer. When None,
        ``model_name_or_path`` is used. Deprecated. Defaults to None.
úsentence_bert_config.jsonrb   Úconfig_file_name)Útransformer_taskÚmodality_configÚmodule_output_nameÚprocessing_kwargsÚunpad_inputsz	list[str]Úconfig_keysTÚboolÚsave_in_rootrZ   NÚtorchF)rß   Úmodel_kwargsÚprocessor_kwargsÚconfig_kwargsrâ   Úbackendrà   rá   rã   Úmax_seq_lengthÚdo_lower_caseÚtokenizer_name_or_pathc          	     óÆ
  >• [         TU ]  5         U[        ;  a=  US:X  a  [        S5      e[	        SU S[        [        R                  5       5       35      eX l        Uc  0 nUc  0 nUc  0 nU=(       d    0 U l        1 Skn[        U R                  5      U-
  nU(       a%  [        R                  SU S[        U5       S35        Xpl        XÀl        S	U l        0 U l        0 U l        U R%                  XU5      u  nnUS
:X  a;  SU;  a5  UR&                  b!  [)        S UR&                   5       5      (       d  SUl        U R,                  " XUUU40 UD6U l        [        [0        R2                  " U R.                  R4                  5      R6                  5      1 Sk-  U l        Ub
  SU;  a  X´S'   [;        5          [<        R>                  " Ub  UOU40 UD6U l         S S S 5        U RB                  GbI  SU;  ax  [E        U RF                  S5      (       a]  U RF                  RH                  S:w  aC  [K        U RB                  RL                  U RF                  RH                  5      U RB                  l&        U(       aÄ  U RB                  RN                  (       a˜  U RB                  RP                  RR                  n[U        U5      (       dg  [W        5       /n[Y        U[Z        5      (       a  U[        U5      -  nOUb  UR]                  U5        [[        U5      U RB                  RP                  l)        O XÀRB                  l        U R                  S;   aG  SU R@                  l1        [E        U R@                  S5      (       a  SU R@                  RB                  l1        Ub  SU;   a  US   Re                  SS5      nOSn[g        U RF                  Rh                  UU R@                  S9U l5        Ubi  X€l6        U	c  [	        S5      eX�l7        URq                  5        H:  u  nn[Y        U[r        5      (       a  SU;  d  SU;  d  M)  [	        SU< SU< 35      e   O3U Ru                  U R.                  U R@                  5      u  U l6        U l7        [        Rw                  SU Rl                   35        [        U Rl                  R                  5       5      U Rj                  l<        UbN  [        R                  S5        U R@                  Rz                  R|                  U R.                  RF                  l?        X l@        g ! , (       d  f       GNW= f! [^         a    XÀRB                  R`                  l         GN*f = f) Nr]   z€The 'any-to-any' transformer task requires transformers v5+. Please upgrade transformers with `pip install transformers>=5.0.0`.zUnsupported transformer_task 'z'. Supported tasks are: >   rp   r‹   r“   rÆ   rÅ   rÇ   z%Unknown keys in `processing_kwargs`: z. Valid keys are: z. Unknown keys will be ignored. Did you mean to nest them under 'common' or a modality key ('text', 'audio', 'image', 'video')?Fr[   Ú
num_labelsc              3  óB   #   • U  H  oR                  S 5      v •  M     g7f)ÚForSequenceClassificationN)Úendswith)r°   Úarchs     rG   r²   Ú'Transformer.__init__.<locals>.<genexpr>{  s   é € ÐgÒRfÈ$Ÿ=™=Ð)D×EÐEÒRfùr´   rÌ   >   Ú	input_idsÚreturn_dictÚinputs_embedsÚattention_maskÚtoken_type_idsÚmodel_max_lengthÚmax_position_embeddingséÿÿÿÿ©r\   r]   ÚleftÚ	tokenizerÚmessagerj   Úauto)Ú
model_typeÚmessage_formatÚ	processorzãLoading the Transformer module with a custom modality_config requires also providing module_output_name with the name of the output feature that this module should create, for example "token_embeddings" or "sentence_embedding".rc   re   z"Invalid modality_config entry for zQ: each entry must be a dict with 'method' and 'method_output_name' keys, but got zActive modality config: z’The `tokenizer_name_or_path` argument is deprecated and will be removed in a future version. Please use the same path for the model and processor.)AÚsuperÚ__init__rn   ÚImportErrorÚ
ValueErrorrÎ   Úkeysrß   râ   ÚsetÚloggerÚwarningÚsortedrë   rí   Útrack_media_countsÚ_prompt_length_mappingÚ_method_signature_cacheÚ_load_configÚarchitecturesrµ   rð   Ú_load_modelÚmodelÚinspectÚ	signaturerq   Ú
parametersÚmodel_forward_paramsr:   r   Úfrom_pretrainedr  r   ÚhasattrÚconfigrü   Úminrû   Úis_fastÚbackend_tokenizerr¶   r·   r   r¯   r   rÐ   ÚAttributeErrorÚbasic_tokenizerÚpadding_siderÍ   r1   r  Úinput_formatterrà   rá   rº   rÏ   Úinfer_modalitiesÚdebugÚsupported_modalitiesÚ	__class__rA   Útokenizer_classrã   )ÚselfÚmodel_name_or_pathrß   rè   ré   rê   râ   rë   rà   rá   rã   rì   rí   rî   Ú
valid_keysÚunknown_keysr  Úis_peft_modelr¶   Únew_normalizersr  Úmodality_keyÚparamsr'  s                          €rG   r  ÚTransformer.__init__A  s  ø€ ô$ 	‰ÑÔØÔ#AÓAØ <Ó/Ü!ðZóð ô Ø0Ð1AÐ0BÐBZÔ[_Ô`~÷  aDñ  aDó  aFó  \Gð  [Hð  Ióð ð 2BÔØÑØˆLØÑ#Ø!ÐØÑ ØˆMØ3D×3JÈˆÔÚSˆ
Ü˜4×1Ñ1Ó2°ZÑ?ˆÞÜ�N‰NØ7¸°~ð F#Ü#)¨*Ó#5Ð"6ð 7RðRôð ŒØ*ÔØ"'ˆÔØ&(ˆÔ#Ø<>ˆÔ$à $× 1Ñ 1Ð2DÈ}Ó ]Ñˆ�ð Ð 9Ó9Ø MÓ1à×$Ñ$Ñ,ÜÑgÐRX×RfÒRfÓg×gÑgð
 !"ˆFÔà×%Ò%Ø°&¸'À=ñ
ØT`ñ
ˆŒ
ô %(¬×(9Ò(9¸$¿*¹*×:LÑ:LÓ(M×(XÑ(XÓ$Yò ]
ñ %
ˆÔ!ð Ñ%Ð*<ÐDTÓ*TØ3AÐ/Ñ0Ü'Õ)Ü*×:Ò:Ø*@Ñ*LÑ&ÐRdñà"ñˆDŒN÷ *ð �>‰>Ò%ð #Ð*:Ó:Ü˜DŸK™KÐ)B×CÑCØ—K‘K×7Ñ7¸2Ó=ä25Ø—N‘N×3Ñ3°T·[±[×5XÑ5Xó3�—‘Ô/ö à—>‘>×)×)Ø!%§¡×!AÑ!A×!LÑ!L�JÜ)¨*×5Ñ5Ü+4«;¨-˜Ü% j´(×;Ñ;Ø+¬t°JÓ/?Ñ?™OØ'Ñ3Ø+×2Ñ2°:Ô>ÜFNÈÓF_˜Ÿ™×8Ñ8ÔCøðUØ7DŸ™Ô4ð × Ñ Ð$EÓEØ*0ˆD�N‰NÔ'Ü�t—~‘~ {×3Ñ3Ø8>�—‘×(Ñ(Ô5ð Ñ&¨9¸Ó+GØ,¨YÑ7×;Ñ;¸HÀfÓM‰Nà#ˆNÜ-Ø—{‘{×-Ñ-¸nÐX\×XfÑXfñ 
ˆÔð Ñ&Ø#2Ô Ø!Ñ)Ü ðNóð ð
 '9Ô#Ø(7×(=Ñ(=Ö(?Ñ$�˜fÜ! &¬$×/Ñ/°8À6Ó3IÐMaÐioÕMoÜ$Ø<¸\Ñ<Lð MKØKQÉ*ðVóð ò )@ð =A×<QÑ<QÐRV×R\ÑR\Ð^b×^lÑ^lÓ<mÑ9ˆDÔ  $Ô"9Ü�‰Ð/°×0DÑ0DÐ/EÐFÔGÜ48¸×9MÑ9M×9RÑ9RÓ9TÓ4Uˆ×ÑÔ1à!Ñ-Ü�N‰NðHôð 15·±×0HÑ0H×0QÑ0QˆD�J‰J×ÑÔ-ð )Õ÷c *Ö)ûôD *ó UØGTŸ™×6Ñ6×DðUús   Æ4"T&Ì%T8 Ô&
T5Ô8$U ÕU c                ó   • U R                   $ )aÜ  Whether text-only inputs are concatenated without padding for faster inference.

Non-text inputs (images, audio, video) are always padded normally.
``None`` auto-detects, ``False`` forces padding, ``True`` requests unpadding.
Re-evaluates on every assignment, so it can be changed after loading::

    model = SentenceTransformer("my-model", model_kwargs={"attn_implementation": "flash_attention_2"})
    model[0].unpad_inputs = False  # Force padding for models that need it
)Ú_unpad_inputs©r)  s    rG   rã   ÚTransformer.unpad_inputså  s   € ð ×!Ñ!Ð!rF   c                ó®   • Xl         USL a  SU l        g U R                  5       U l        USL a(  U R                  (       d  [        R	                  S5        g g g )NFTzqunpad_inputs=True was set, but the prerequisites for skipping padding are not met. Falling back to padded inputs.)r3  Úcan_flatten_inputsÚ_can_flatten_inputsr  r  ©r)  rÀ   s     rG   rã   r5  ò  sO   € à"ÔØ�EŠ>Ø&+ˆDÕ#à&*×&>Ñ&>Ó&@ˆDÔ#Ø˜Š} T×%<×%<Ü—‘ð5õð &=ˆ}rF   c                óP  • U R                   S:w  dq  SU R                  ;  da  U R                  S:w  dQ  [        U R                  SS 5      " 5       (       a/  [        S U R                  R                  5        5       5      (       a  g SS	KJn  SS
K	J
n  SSKJn  U R                   R"                  nU" US9(       d  gU" U5      u  tpV  nUc  g[        R                  S5        U" SSSS9U l        U =R&                  1 Sk-  sl        g! [         a    [        R                  S5         gf = f)ax  Determine whether text-only inputs can be flattened (concatenated without padding) for more efficient inference.

When enabled, text-only inputs are concatenated into a single sequence and processed using flash
attention's variable-length functions, eliminating padding overhead and significantly speeding up
inference. Non-text inputs (images, audio, video) are always padded normally, even when this
returns True.

This requires:
1. The ``"feature-extraction"`` task, as model heads (e.g. ``AutoModelForSequenceClassification``)
   are incompatible with flattened inputs.
2. The ``"text"`` modality must be supported by the model.
3. All modality call methods must be ``"forward"``; ``get_..._features`` methods apply heads
   that are incompatible with flattened inputs.
4. The ``"torch"`` backend with an attention-interface-compatible model.
5. Flash attention with variable-length function support.

Note: Some architectures don't work with unpadded inputs (e.g. ``qwen2_vl``). Use
``unpad_inputs=False`` to disable this optimization for such models.

Returns:
    bool: True if text-only inputs can be flattened for efficient inference.
rZ   rp   rç   Úis_backend_compatiblec                 ó   • g)NFr?   r?   rF   rG   Ú<lambda>Ú1Transformer._can_flatten_inputs.<locals>.<lambda>  s   € ÈrF   c              3  ó0   #   • U  H  oS    S:g  v •  M     g7f)rc   rq   Nr?   )r°   r0  s     rG   r²   Ú2Transformer._can_flatten_inputs.<locals>.<genexpr>  s   é € Ð]Ò?\°V˜(Ñ# yÖ0Ò?\ùs   ‚Fr   )ÚDataCollatorWithFlattening)Úlazy_import_flash_attention)Úis_flash_attention_requestedz~Consider upgrading to transformers >= 5.0.0 to skip padding for text-only inputs, which can significantly speed up processing.)Ú"requested_attention_implementationzuUsing flattened inputs with flash attention variable-length functions to avoid padding overhead for text-only inputs.T)Úreturn_seq_idxÚreturn_flash_attn_kwargsÚreturn_position_ids>   Úseq_idxÚmax_length_kÚmax_length_qÚcu_seq_lens_kÚcu_seq_lens_q)rß   rà   rë   r¹   r  rµ   Úvaluesry   rA  Ú+transformers.modeling_flash_attention_utilsrB  Útransformers.utils.genericrC  r  r  r%  r  Ú_attn_implementationÚdata_collatorr  )r)  rA  rB  rC  Úattn_implementationÚ_Úflash_varlen_fns          rG   r8  ÚTransformer._can_flatten_inputsÿ  s   € ð0 ×!Ñ!Ð%9Ó9Ø˜T×1Ñ1Ó1Ø�|‰|˜wÓ&Ü˜4Ÿ:™:Ð'>ÁÔN×PÑPÜÑ]¸t×?SÑ?S×?ZÑ?ZÔ?\Ó]×]Ñ]àð		Ý?Ý_ÝOð #Ÿk™k×>Ñ>ÐÙ+ÐOb×cØá&AÐBUÓ&VÑ#Ð ˆ˜a !ØÑ"Øä�‰ð Dô	
ñ 8ØØ%)Ø $ñ
ˆÔð 	×!Ò!ò &
ñ 	
Õ!ð øôC ó 	Ü�L‰Lð?ôñ ð	ús   ÂD ÄD%Ä$D%c                óD  • U R                   b  U R                   R                  $ [        U R                  R                  S5      (       a%  U R                  R                  R                  5       nOU R                  R                  n[        US5      (       a  UR                  $ g)z”The maximum input sequence length. Reads from the tokenizer if available, otherwise
falls back to ``max_position_embeddings`` from the model config.NÚget_text_configrü   )r   rû   r  r  r  rW  rü   )r)  Útext_configs     rG   rì   ÚTransformer.max_seq_lengthF  s|   € ð �>‰>Ñ%Ø—>‘>×2Ñ2Ð2ô �4—:‘:×$Ñ$Ð&7×8Ñ8ØŸ*™*×+Ñ+×;Ñ;Ó=‰KàŸ*™*×+Ñ+ˆKä�;Ð 9×:Ñ:Ø×6Ñ6Ð6ØrF   c                ó@   • U R                   b  XR                   l        gg)zTSet the maximum input sequence length. Only effective when a tokenizer is available.N)r   rû   r9  s     rG   rì   rY  W  s   € ð �>‰>Ñ%Ø.3�N‰NÕ+ð &rF   c                ó   • U R                   $ )z!The underlying transformer model.)r  r4  s    rG   Ú
auto_modelÚTransformer.auto_model]  s   € ð �z‰zÐrF   c                ó.   • U R                   R                  $ )z#The underlying model configuration.)r  r  r4  s    rG   r  ÚTransformer.configb  s   € ð �z‰z× Ñ Ð rF   c                óH   • [        U R                  R                  5       5      $ )z]The list of supported input modalities (e.g. ``"text"``, ``"image"``, ``("image", "text")``).)rÎ   rà   r
  r4  s    rG   Ú
modalitiesÚTransformer.modalitiesg  s   € ô �D×(Ñ(×-Ñ-Ó/Ó0Ð0rF   c                ó†   • [        U R                  [        5      (       a  U R                  $ [        U R                  SS5      $ )zVThe tokenizer, extracted from the processor. Returns ``None`` for non-text processors.r   N)r¯   r  r"   r¹   r4  s    rG   r   ÚTransformer.tokenizerl  s3   € ô �d—n‘nÔ&=×>Ñ>Ø—>‘>Ð!Ü�t—~‘~ {°DÓ9Ð9rF   c                ó  • U(       d  0 $ SS0nSSS.SS00 0 S.nU R                   R                  S:X  a  S	US
   S'   SU R                  ;   a  UR                  U R                  S   5        U H:  nU R                  R	                  U5      =n(       d  M'  XV   R                  U5        M<     U R
                  R                  U5      u  p‰n
U
R                  5        H  u  pkXV   R                  U5        M     U R                  =(       a6    US:H  =(       d*    US:H  =(       a    U R
                  R                  U	S   5      nU(       a   US	 US   R                  SS5        SUS   S'   SU R                  ;   a$  US:w  a  U R
                  R                  X‰5      u  p‰OcX€R                  ;  aT  [        S[        U5       SSR                  S [!        U R                  R#                  5       [$        S9 5       5       35      eSnU(       a)  US:X  a#  U R
                  R'                  U	S   U5      U	S'   OBU(       a;  US:X  a5  U R
                  R)                  U	S   U5      U	S'   U R*                  " U40 UD6nSnSnU R,                  (       a'  U R.                  (       a  US:X  a  [1        U	S   5      u  pï[3        5          U R5                  X‰XT5      nSSS5        Ub,  SW;   a&  [6        R8                  " U[6        R:                  S9US'   Ub,  SW;   a&  [6        R8                  " U[6        R:                  S9US'   U(       a\  [=        WR?                  5       6  Vs/ s H  n[A        [=        UU5      5      PM     nnU RC                  U5      nUR                  SS5        UWS'   Ub  UUS'   U RD                  S;   aC  U RF                  RH                  S:w  a$  [        S U RF                  RH                  < S!35      eS"US#'   U$ ! , (       d  f       GN2= fs  snf )$aa  Preprocess inputs into model-ready features.

Args:
    inputs: List of inputs. Can contain strings, dicts with modality keys, PIL images,
        or numpy/torch arrays for audio/video.
    prompt: Optional prompt to prepend to text inputs or inject as a system message.
    **kwargs: Additional keyword arguments forwarded to prompt length computation
        (e.g. ``task``). Only used when ``prompt`` is provided for text inputs.

Returns:
    Dictionary containing preprocessed tensors with a ``modality`` key indicating the
    input type and optionally a ``prompt_length`` key for prompt-aware pooling.
Úreturn_tensorsÚptTÚlongest_first)ÚpaddingÚ
truncationri  )rp   r‹   r“   rÆ   r§   Ú
max_lengthr‹   rÅ   rp   r  NFÚreturn_attention_maskz
Modality 'z8' is not supported by this model. Supported modalities: z, c              3  ó8   #   • U  H  n[        U5      v •  M     g 7fr®   )r2   )r°   Úms     rG   r²   Ú)Transformer.preprocess.<locals>.<genexpr>²  s   é € Ð2|ÒO{È!´?À1×3EÐ3EÒO{ùs   ‚)ÚkeyÚimage_grid_thw)ÚdtypeÚnum_images_per_sampleÚvideo_grid_thwÚnum_videos_per_sampleÚlabelsÚmodalityÚprompt_lengthrþ   rÿ   zThe processor padding side is zñ, but causal models require left padding so that the last token position is always a real token. This is needed for efficient logit computation (logits_to_keep=1) and for LogitScore. Please set ``processing_kwargs={"padding_side": "left"}``.rÌ   Úlogits_to_keep)%r  r  râ   ÚupdaterÍ   r#  Úparse_inputsrº   r7  Úis_text_only_messagesÚpoprà   Úbatch_to_messager	  r2   Újoinr  r
  rb   Úprepend_prompt_to_messagesÚprepend_prompt_to_textsÚ_get_prompt_lengthÚtrainingr  rÚ   r:   Ú_call_processorrç   ÚtensorÚlongÚziprM  rÏ   rQ  rß   r  r"  )r)  ÚinputsÚpromptÚkwargsÚcommon_kwargsÚmodality_kwargsr/  r½   rw  Úprocessor_inputsÚextra_modality_kwargsÚextra_kwargsÚshould_flattenrx  rs  ru  Úprocessor_outputrM  Ú
per_samples                      rG   Ú
preprocessÚTransformer.preprocesss  s!  € ö& ØˆIà)¨4Ð0ˆà $°OÑDØ Ð&ØØñ	
ˆð �;‰;×!Ñ! YÓ.ð 3?ˆO˜GÑ$ YÑ/ð �t×-Ñ-Ó-Ø× Ñ  ×!7Ñ!7¸Ñ!AÔBÛ+ˆLØ ×2Ñ2×6Ñ6°|ÓDÐDˆy×DØÑ-×4Ñ4°YÖ?ñ ,ð =A×<PÑ<P×<]Ñ<]Ð^dÓ<eÑ9ˆÐ$9à*?×*EÑ*EÖ*GÑ&ˆLØÑ)×0Ñ0°Ö>ñ +Hð
 ×0Ñ0÷ 
Ø˜Ñ÷ sØ˜IÑ%×q¨$×*>Ñ*>×*TÑ*TÐUeÐfoÑUpÓ*qð 	ö ØÐ.Ð/Ø˜FÑ#×'Ñ'¨	°4Ô8Ø?DˆO˜FÑ#Ð$;Ñ<ð ˜×,Ñ,Ó,°¸YÓ1FØ)-×)=Ñ)=×)NÑ)NÈxÓ)jÑ&ˆHÐ&Ø×1Ñ1Ó1ÜØœ_¨XÓ6Ð7ð 8)Ø)-¯©Ñ2|ÌvÐVZ×VjÑVj×VoÑVoÓVqÔwzÒO{Ó2|Ó)|Ð(}ðóð ð ˆÞ�h )Ó+Ø*.×*>Ñ*>×*YÑ*YØ  Ñ+¨Vó+Ð˜YÒ'ö
 ˜ FÓ*Ø'+×';Ñ';×'SÑ'SÐTdÐekÑTlÐntÓ'uÐ˜VÑ$Ø ×3Ò3°FÑE¸fÑEˆMð
 !%ÐØ $ÐØ�=�=˜T×4×4¸ÀYÓ9NÜ;RÐScÐdmÑSnÓ;oÑ8Ð!ä'Õ)Ø#×3Ñ3°HÐP_ÓoÐ÷ *ð !Ñ,Ð1AÐEUÓ1UÜ8=¿ºÐEZÔbg×blÑblÑ8mÐÐ4Ñ5Ø Ñ,Ð1AÐEUÓ1UÜ8=¿ºÐEZÔbg×blÑblÑ8mÐÐ4Ñ5æäLOÐQa×QhÑQhÓQjÑLkÓlÒLkÀ&œ$œsÐ#3°VÓ<Ö=ÑLkˆJÐlØ#×1Ñ1°*Ó=ÐØ× Ñ  ¨4Ô0à'/Ð˜Ñ$ØÑ$Ø0=Ð˜_Ñ-à× Ñ Ð$EÓEØ�~‰~×*Ñ*¨fÓ4Ü Ø4°T·^±^×5PÑ5PÑ4Sð TQð Qóð ð 23ÐÐ-Ñ.àÐ÷9 *Ö)üò ms   Ê5O3ÍPÏ3
Pc                ó”  • UR                  SS5      nU R                  U   nUS   nUS   n[        U[        5      (       a  U4nO [        U[        5      (       a  [        U5      n0 UEUESS0En[        U R                  US5      nUc  [        SU S	35      eUS
:X  a6  UR                  5        V	V
s0 s H  u  pšX�R                  ;   d  M  Xš_M     nn	n
O€U R                  R                  U5      nUc7  [        [        R                  " U5      R                  5      nXÀR                  U'   UR                  5        V	V
s0 s H  u  pšXœ;   d  M  Xš_M     nn	n
Ub  SU;   a  SUS'   U" S0 UD6nUnUb  U H  n Xï   nM
     UR*                  S:X  a!  UR-                  S5      R/                  SS5      nXáU R0                  '   SU;   aÊ  SU;   aÄ  [3        5       (       aµ  SSKJn  [        U R                  U5      (       a”  U R                  R8                  R:                  (       ao  US   R<                  S   nUS   n[>        R@                  " UU R                  R8                  RB                  URD                  S9n[>        RF                  " UU4SS9US'   [I        U R                  RJ                  S5      (       a3  U R                  RJ                  RL                  (       a  SU;   a  US   US'   U$ s  sn
n	f s  sn
n	f ! [         ["        4 aE     [        Xï5      n GM¡  ! [$         a'    [%        SU< S['        U5      R(                   S35      ef = ff = f)ai  Forward pass through the transformer model.

Dispatches to the appropriate model method based on the ``modality`` key in ``features``
and writes the result into ``features[self.module_output_name]``.

Args:
    features: Input features dictionary produced by :meth:`preprocess`. Must contain the
        keys expected by the underlying model (e.g. ``input_ids``, ``pixel_values``, etc.).
        A ``modality`` key selects the modality config to use; defaults to ``"text"``
        when absent.
    **kwargs: Additional keyword arguments forwarded to the model method (override features).

Returns:
    The updated ``features`` dict with the model output stored under ``self.module_output_name``
    (e.g. ``token_embeddings``, ``sentence_embedding``, ``scores``, or ``causal_logits``).
    May also include ``all_layer_embeddings`` if ``output_hidden_states`` is enabled.
rw  rp   rc   re   r÷   TNz#Model does not have the requested 'z' methodrq   Úhidden_statesÚoutput_hidden_stateszCould not access output key z% via indexing or attribute access on Ú.é   é   rÌ   rö   rù   r   )Ú	PeftModel)Údevice)ÚdimÚall_layer_embeddingsr?   )'rÍ   rà   r¯   rb   rÎ   Útupler¹   r  r	  rº   r  r  r  r  r  r  ÚKeyErrorÚ	TypeErrorr   rÊ   rA   ÚndimÚflattenÚ	transposerá   r-   Úpeftr›  Úactive_peft_configÚis_prompt_learningÚshaperç   ÚonesÚnum_virtual_tokensrœ  Úcatr  r  r—  )r)  ÚfeaturesrŠ  Úmodality_nameÚmodality_paramsÚmethod_namere   Ú
all_kwargsÚmodel_methodrp  rÀ   Úfiltered_kwargsÚmethod_paramsÚmodel_outputÚ	embeddingÚ
output_keyr›  Ú
batch_sizerù   Úprefix_attention_masks                       rG   rq   ÚTransformer.forwardç  sJ  € ð& #+§,¡,¨z¸6Ó"BˆØ×.Ñ.¨}Ñ=ˆØ% hÑ/ˆØ,Ð-AÑBÐÜÐ(¬#×.Ñ.Ø"4Ð!6ÑÜÐ*¬D×1Ñ1Ü!&Ð'9Ó!:Ðð A˜Ð@ FÐ@¨M¸4Ñ@ˆ
Ü˜tŸz™z¨;¸Ó=ˆØÑÜÐBÀ;À-ÈxÐXÓYÐYà˜)Ó#Ø<F×<LÑ<LÔ<NÔsÒ<N©j¨cÐRU×YrÑYrÑRr›z˜sšzÑ<NˆOÑsˆOà ×8Ñ8×<Ñ<¸[ÓIˆMØÑ$Ü #¤G×$5Ò$5°lÓ$C×$NÑ$NÓ O�Ø<I×,Ñ,¨[Ñ9Ø<F×<LÑ<LÔ<NÔgÒ<N©j¨cÐRUÑRf›z˜sšzÑ<NˆOÑgð Ñ)¨oÐASÓ.SØ6:ˆOÐ2Ñ3á#Ñ6 oÑ6ˆà ˆ	ØÑ)Û0�
ðØ )Ñ 5’Iñ 1ð �>‰>˜QÓð "×)Ñ)¨!Ó,×6Ñ6°q¸!Ó<ˆIà,5�×(Ñ(Ñ)ð ˜(Ó"Ð'7¸8Ó'CÔHY×H[ÑH[Ý&ä˜$Ÿ*™* i×0Ñ0°T·Z±Z×5RÑ5R×5e×5eØ% kÑ2×8Ñ8¸Ñ;�
Ø!)Ð*:Ñ!;�Ü(-¯
ª
Ø §
¡
× =Ñ =× PÑ PÐYg×YnÑYnñ)Ð%ô .3¯YªYÐ8MÈ~Ð7^ÐdeÑ-f�Ð)Ñ*ô �D—J‘J×%Ñ%Ð'=×>Ñ>Ø—
‘
×!Ñ!×6×6Ø <Ó/à/;¸OÑ/LˆHÐ+Ñ,àˆùóu tùó høô !¤)Ð,ó 	ðÜ$+¨IÓ$Bœ	øÜ)ó Ü,Ø:¸:¹.ð I"Ü"& y£/×":Ñ":Ð!;¸1ð>óð ðúð	ús6   Â1K&Ã
K&Ä<K,ÅK,Å5K2Ë2MÌLÌ1MÍMc                ó  ^ • [        T R                  R                  [        5      (       a   T R                  R                  R                  $ U 4S jnU" T R                  R                  5      =nb  U$ [        T R                  R                  S5      (       a+  U" T R                  R                  R                  5      =nb  U$ [        T R                  R                  S5      (       ad  T R                  R                  R                  R                  5        H2  n[        T R                  R                  U5      nU" U5      =nc  M0  Us  $    [        S[        T R                  R                  5      R                   S35      e)zçGet the output embedding dimension from the transformer model.

Returns:
    int: The hidden dimension size of the model's embeddings.

Raises:
    ValueError: If the embedding dimension cannot be determined from the model config.
c                ón  >• [        U S5      (       a  TR                  S:X  a  U R                  $ [        U S5      (       a  U R                  $ S HG  n[        X5      (       d  M  [	        X5      n[        U[        5      (       a  U(       a  US   s  $ ME  Us  $    [        U S5      (       a  U R                  $ g )NÚprojection_dimr•   Úhidden_size)Úneck_hidden_sizesÚhidden_sizesÚ
embed_dimsrý   Ú
hidden_dim)r  rá   r¼  r½  r¹   r¯   rÎ   rÁ  )r  Ú	attr_namerÀ   r)  s      €rG   Úget_hidden_size_from_configÚHTransformer.get_embedding_dimension.<locals>.get_hidden_size_from_configS  sª   ø€ ô �vÐ/×0Ñ0°T×5LÑ5LÐPdÓ5dØ×,Ñ,Ð,ä�v˜}×-Ñ-Ø×)Ñ)Ð)ÛP�	Ü˜6×-Ó-Ü# FÓ6�EÜ! %¬×.Ñ.Þ Ø#(¨¡9Ò,ñ !ð  %šñ Qô �v˜|×,Ñ,Ø×(Ñ(Ð(ØrF   rX  Úsub_configszHCould not determine embedding dimension from model config. Config type: r˜  )r¯   r  r  rU   Únum_featuresr  rX  rÅ  r
  r¹   r	  rÊ   rA   )r)  rÃ  r½  Úsub_config_nameÚ
sub_configs   `    rG   Úget_embedding_dimensionÚ#Transformer.get_embedding_dimensionF  s8  ø€ ô �d—j‘j×'Ñ'Ô):×;Ñ;Ø—:‘:×$Ñ$×1Ñ1Ð1õ	ñ* 7°t·z±z×7HÑ7HÓIÐIˆKÑVØÐô �4—:‘:×$Ñ$ m×4Ñ4Ù:¸4¿:¹:×;LÑ;L×;XÑ;XÓYÐY�ÑfØ"Ð"ô �4—:‘:×$Ñ$ m×4Ñ4Ø#'§:¡:×#4Ñ#4×#@Ñ#@×#EÑ#EÖ#G�Ü$ T§Z¡Z×%6Ñ%6¸ÓH�
Ù#>¸zÓ#JÐJ�KÓWØ&Ò&ñ $Hô
 ØVÔW[Ð\`×\fÑ\f×\mÑ\mÓWn×WwÑWwÐVxÐxyÐzó
ð 	
rF   c                ó¾   • US:X  a  U R                  US   X45      $ [        U R                  [        5      (       a  U R	                  XX45      $ U R                  XX45      $ )a8  Call the appropriate processor with the correct arguments.

Dispatches based on the processor type and modality:

1. **Message modality**: delegates to :meth:`_process_chat_messages`.
2. **Multi-modal processor** (:class:`ProcessorMixin`): delegates to
   :meth:`_call_multimodal_processor`, which handles both legacy (flat kwargs) and
   transformers v5 (per-modality kwargs) calling conventions.
3. **Single-modality processor** (tokenizer, feature extractor, image/video processor):
   delegates to :meth:`_call_single_modality_processor`, which matches the processor
   type and passes the primary input as a positional argument when available.

Args:
    modality: The modality or tuple of modalities being processed.
    processor_inputs: Dictionary of processor argument names to lists of values.
    modality_kwargs: Per-modality configuration kwargs (keys: ``"text"``, ``"image"``,
        ``"audio"``, ``"video"``).
    common_kwargs: Common kwargs passed to all processor calls (e.g. ``padding``,
        ``return_tensors``).

Returns:
    Processor output dictionary.
r  )Ú_process_chat_messagesr¯   r  r#   Ú_call_multimodal_processorÚ_call_single_modality_processor)r)  rw  r�  rŒ  r‹  s        rG   r„  ÚTransformer._call_processor{  s]   € ð< �yÓ Ø×.Ñ.Ð/?À	Ñ/JÈOÓkÐkä�d—n‘n¤n×5Ñ5Ø×2Ñ2°8ÈÓnÐnà×3Ñ3°HÐP_ÓoÐorF   c           
     óp  • UR                  5        VVs0 s H  u  pV[        R                  " XU5      U_M     nnnU R                  R                  S;   d  [
        (       d-  US:X  a  0 US   EUS   EnOX1   nU R                  " S0 UDUDUD6$ U R                  " S0 UDUS   US   US   US   US.D6$ s  snnf )	zZCall a :class:`ProcessorMixin` processor, handling both legacy and v5 calling conventions.>   r—   Úclipsegr§   rŒ   rp   r‹   r“   rÆ   ©Útext_kwargsÚimages_kwargsÚaudio_kwargsÚvideos_kwargsr‹  r?   )rº   r3   rÍ   r  r  Ú0_TRANSFORMERS_PROCESSOR_SUPPORTS_MODALITY_KWARGSr  )r)  rw  r�  rŒ  r‹  rp  rÀ   rŠ  s           rG   rÍ  Ú&Transformer._call_multimodal_processor¡  sæ   € ð ^n×]sÑ]sÔ]uÔvÒ]uÉzÈsÔ5×9Ò9¸#ÓCÀUÒJÑ]uÐÑvð �K‰K×"Ñ"Ð&DÓDßCÒCð Ð,Ó,àP˜O¨FÑ3ÐP°ÀwÑ7OÐP‘à(Ñ2�Ø—>’>ÑPÐ$4ÐP¸ÐPÀ-ÑPÐPð �~Š~ñ 
Øð
à'¨Ñ/Ø)¨'Ñ2Ø(¨Ñ1Ø)¨'Ñ2Ø'ó
ð 	
ùó! ws   ”#B2c                ó®  • S[         US   4S[        US   4S[        US   4S[        US   4/nU Hj  u  pgn[	        U R
                  U5      (       d  M#  0 UEUEn	Xb;   a(  UR                  U5      n
U R
                  " U
40 UDU	D6s  $ U R
                  " S0 UDU	D6s  $    [        S[        U R
                  5      R                   S[        U5       S35      e)	zWCall a single-modality processor (tokenizer, feature extractor, image/video processor).rp   r‹   rÆ   r“   z2Could not determine how to call processor of type z for modality 'Ú'r?   )r"   r   r<   r   r¯   r  r}  ÚRuntimeErrorrÊ   rA   r2   )r)  rw  r�  rŒ  r‹  Úprocessor_type_checksÚmodality_typeÚprocessor_classÚtype_kwargsÚcall_kwargsÚprimary_inputs              rG   rÎ  Ú+Transformer._call_single_modality_processorÃ  s
  € ð Ô,¨o¸fÑ.EÐFØÔ,¨o¸gÑ.FÐGØÔ(¨/¸'Ñ*BÐCØÔ*¨O¸GÑ,DÐEð	!
Ðó <QÑ7ˆM¨KÜ˜dŸn™n¨o×>Ñ>Ùà:˜[Ð:¨MÐ:ˆKð Ó0Ø 0× 4Ñ 4°]Ó C�Ø—~’~ mÑWÐ7GÐWÈ;ÑWÒWØ—>’>ÑDÐ$4ÐD¸ÑDÒDñ <Qô Ø@ÄÀdÇnÁnÓAU×A^ÑA^Ð@_ð `Ü,¨XÓ6Ð7°qð:ó
ð 	
rF   c                ó^  • SU R                   ;  a/  [        S[        U R                   R                  5       5       35      eU R                  R                  S0 5      n[        U R                  [        5      (       a“  [        (       aW  U R                  R                  " U4SSUR                  S5      US   R                  SS5      US	   US
   US   US   US.S.UD6$ U R                  R                  " U4SSUS	   US
   US   US   US.UD6$ 1 SknXSR                  5       -   Vs0 s H  ofUR                  U5      _M     nnUXRS	   R                  5       -   Vs0 s H  ofUS	   R                  U5      _M     sn-  nU R                  R                  " U4SSUS	   US.UDUD6$ s  snf s  snf )z:Process chat messages using the processor's chat template.r  znThe model does not support 'message' modality, but the input looks like a chat message. Supported modalities: rÇ   Trf  rÆ   Úload_audio_from_videoFrp   r“   r‹   rÒ  )Útokenizer÷   rf  rä  ré   )rå  r÷   rÓ  rÔ  rÕ  rÖ  r‹  >   ri  rk  rj  rf  )rå  r÷   Útokenizer_kwargsr‹  )rà   r	  rÎ   r
  râ   rÍ   r¯   r  r#   Ú=_TRANSFORMERS_APPLY_CHAT_TEMPLATE_RECOMMENDS_PROCESSOR_KWARGSÚapply_chat_templater}  )r)  rÑ   rŒ  r‹  Úchat_template_kwargsÚtop_level_kwarg_namesrp  Útop_level_kwargss           rG   rÌ  Ú"Transformer._process_chat_messagesä  s  € ð ˜D×0Ñ0Ó0Üð)Ü)-¨d×.BÑ.B×.GÑ.GÓ.IÓ)JÐ(KðMóð ð  $×5Ñ5×9Ñ9¸/È2ÓNÐÜ�d—n‘n¤n×5Ñ5÷ MÒLØ—~‘~×9Ò9Øðà!Ø $Ø#0×#4Ñ#4Ð5EÓ#FØ*9¸'Ñ*B×*FÑ*FÐG^Ð`eÓ*fà'6°vÑ'>Ø)8¸Ñ)AØ(7¸Ñ(@Ø)8¸Ñ)AØ)6ñ&ñð +ñð ð  —~‘~×9Ò9Øð
à!Ø $Ø /°Ñ 7Ø"1°'Ñ":Ø!0°Ñ!9Ø"1°'Ñ":Ø"/ñ
ð +ñ
ð 
ò !ZÐØCX×[mÑ[mÓ[oÒCoÓpÒCo¸C ×!2Ñ!2°3Ó!7Ò7ÑCoÐÐpØØ=RÐekÑUl×UqÑUqÓUsÒ=só
Ú=s°c� Ñ(×,Ñ,¨SÓ1Ò1Ñ=sñ
ñ 	
Ðð �~‰~×1Ò1Øð
àØØ,¨VÑ4Ø'ñ
ð ð
ð #ñ
ð 	
ùò qùò
s   Ä&F%ÅF*c                ó¤  • U/[        UR                  5       5      Q7nX0R                  ;   a  U R                  U   $ U R                  " U/40 UD6nSU;  a  SU R                  U'   gUS   R                  S   nU R
                  nUS   S   R                  5       nUb%  [        US5      (       a  XvR                  ;   a  US-  nXPR                  U'   U$ )z�Return the length of the prompt in tokens, excluding any trailing special token.

Returns None if the processor does not produce ``input_ids``.
rö   Nrý   ).rý   Úall_special_idsrÌ   )	r  rº   r  r“  r¨  r   rØ   r  rî  )r)  r‰  rŠ  Ú	cache_keyÚtokenized_promptrx  r   Ú
last_tokens           rG   r‚  ÚTransformer._get_prompt_length&  sÝ   € ð
 Ð5œf V§\¡\£^Ó4Ñ5ˆ	Ø×3Ñ3Ó3Ø×.Ñ.¨yÑ9Ð9àŸ?š?¨F¨8Ñ>°vÑ>ÐØÐ.Ó.Ø59ˆD×'Ñ'¨	Ñ2ØØ(¨Ñ5×;Ñ;¸BÑ?ˆà—N‘Nˆ	Ø% kÑ2°7Ñ;×@Ñ@ÓBˆ
ØÑ ¤W¨YÐ8I×%JÑ%JÈz×]vÑ]vÓOvØ˜QÑˆMØ1>×#Ñ# IÑ.ØÐrF   c                ó|  • [        UUR                  S5      UR                  S5      UR                  S5      UR                  SS5      UR                  SS5      S9nUbF  US	:w  a  [        S
5      e[        5       (       d  [	        S5      eSSKJn  UR                  " U40 UD6S4$ [        R                  " U40 UD6S4$ )a%  Loads the transformers or PEFT configuration

Args:
    model_name_or_path (str): The model name on Hugging Face (e.g. 'sentence-transformers/all-MiniLM-L6-v2')
        or the path to a local model directory.
    backend (str): The backend used for model inference. Can be `torch`, `onnx`, or `openvino`.
    config_kwargs (dict[str, Any]): Keyword arguments passed to the Hugging Face Transformers config.

Returns:
    tuple[PeftConfig | PretrainedConfig, bool]: The model configuration and a boolean indicating whether the model is a PEFT model.
Ú	cache_dirÚtokenÚrevisionÚ	subfolderrË   Úlocal_files_onlyF)rô  rõ  rö  r÷  rø  rç   a  PEFT models can currently only be loaded with the `torch` backend. To use other backends, load the model with `backend="torch"`, call `model.transformers_model.merge_and_unload()`, save that model with `model.save_pretrained()` and then load the model with the desired backend.zgLoading a PEFT model requires installing the `peft` package. You can install it via `pip install peft`.r   rX   T)	r.   rÍ   r	  r-   r  r¥  rY   r  r   )r)  r*  rë   rê   Úadapter_config_filerY   s         rG   r  ÚTransformer._load_config<  sÚ   € ô 7ØØ#×'Ñ'¨Ó4Ø×#Ñ# GÓ,Ø"×&Ñ& zÓ2Ø#×'Ñ'¨°RÓ8Ø*×.Ñ.Ð/AÀ5ÓIñ
Ðð Ñ*Ø˜'Ó!ä ðwóð ô
 %×&Ñ&Ü!Ø}óð õ (à×-Ò-Ð.@ÑRÀMÑRÐTXÐXÐXä×)Ò)Ð*<ÑNÀÑNÐPUÐUÐUrF   c                ó*  • US:X  aU  U(       a  UR                  SS5        US:X  a  U R                  " X40 UD6nUb  U$ [        U   nUR                  " U4SU0UD6$ US:X  a  [	        SUUUS.UD6$ US:X  a  [        SUUUS.UD6$ [        S	U S
35      e)a1  Loads the transformers or PEFT model into the `auto_model` attribute

Args:
    model_name_or_path (str): The model name on Hugging Face (e.g. 'sentence-transformers/all-MiniLM-L6-v2')
        or the path to a local model directory.
    config ("PeftConfig" | PretrainedConfig): The model configuration.
    backend (str): The backend used for model inference. Can be `torch`, `onnx`, or `openvino`.
    is_peft_model (bool): Whether the model is a PEFT model.
    model_kwargs (dict[str, Any]): Keyword arguments passed to the Hugging Face Transformers model.
rç   rö  NrZ   r  Úonnx)r*  r  Ú	task_nameÚopenvinozUnsupported backend 'z6'. `backend` should be `torch`, `onnx`, or `openvino`.r?   )r}  Ú_load_encoder_only_modelrn   r  r/   r0   r	  )	r)  r*  rß   r  rë   r-  rè   r  Ú	model_clss	            rG   r  ÚTransformer._load_modeld  sè   € ð* �gÓö Ø× Ñ  ¨TÔ2àÐ#7Ó7Ø×5Ò5Ð6HÑaÐT`Ña�ØÑ$Ø �Lä6Ð7GÑHˆIØ×,Ò,Ð-?Ñ_ÈÐ_ÐR^Ñ_Ð_Ø˜ÓÜ"ð Ø#5ØØ*ñð ñ	ð ð ˜
Ó"Ü&ð Ø#5ØØ*ñð ñ	ð ô Ð4°W°IÐ=sÐtÓuÐurF   c                ób  ^^^• S	UUU4S jjn[        T[        5      (       a  SSKJn  STl        U" U5      $ [        T[
        5      (       a  SSKJn  U" UTR                  SS9$ [         HA  u  pxn	[        TU5      (       d  M  [        [        R                  " U5      U	5      n
U" U
5      s  $    g)
a<  Load encoder-only variants for encoder-decoder architectures.

Checks :data:`_ENCODER_ONLY_MODELS` for standard mappings and handles a few special cases
(T5Gemma, T5Gemma2) that require extra configuration before loading.

Returns the loaded model, or None if the config doesn't match any encoder-only architecture.
Nc                ó”   >• [        U 4SS/0UD6   U R                  " T4SU=(       d    T0TD6sS S S 5        $ ! , (       d  f       g = f)NÚ"_keys_to_ignore_on_load_unexpectedz	decoder.*r  )rÁ   r  )r   Úload_configÚextra_class_attrsr  rè   r*  s      €€€rG   Ú_load_encoderÚ;Transformer._load_encoder_only_model.<locals>._load_encoder¦  sR   ø€ Ü*ØñØ?J¸mðØO`óð !×0Ò0Ð1CÑrÈK×LaÐ[aÐrÐeqÑr÷÷ ÷ ús	   ‘9¹
Ar   )ÚT5GemmaEncoderModelF)r‰   zmodel.encoder)r  Úbase_model_prefixr®   )r¯   rO   ry   r	  Úis_encoder_decoderrI   Ú.transformers.models.t5gemma2.modeling_t5gemma2r‰   ÚencoderrŠ   r¹   Ú	importlibÚimport_module)r)  r*  r  rè   r  r	  r‰   Ú
config_clsÚmodule_pathÚ
class_nameÚencoder_clss    ```       rG   rÿ  Ú$Transformer._load_encoder_only_model˜  s¢   ú€ ÷	sñ 	sô �fœm×,Ñ,Ý8à(-ˆFÔ%Ù Ð!4Ó5Ð5ä�fœn×-Ñ-ÝVñ ! ¸f¿n¹nÐ`oÑpÐp÷ 4HÑ/ˆJ ZÜ˜& *×-Ó-Ü%¤i×&=Ò&=¸kÓ&JÈJÓW�Ù$ [Ó1Ò1ñ 4Hð
 rF   c                ó†  • [         U R                     u  p4US   S   nU R                  X5      =nb]  Uu  px[        US5      (       aE  UR                  b8  SU;  a2  0 UR                  SSUS.5      ESU R                  R                  0EUS'   Xx4$ U R                  U5      n	[        US5      (       a  UR                  b  U	R                  S5        U R                  UR                  5      n
U
b  XZ;   a;  0 nU	 H0  n[        SUS9nUS:X  a  U R                  R                  US'   XÇU'   M2     Xt4$ U R                  S	:X  ah  0 nU	 H\  nUS:X  a  M  S
U S3n[        X5      (       d  M#  [        X5      nU R                  U5      nU(       a  SU;   a	  USS.X{'   MU  USS.X{'   M^     US4$ U	 Vs0 s H	  nUSUS._M     snU4$ s  snf )a   Infer the modality configuration and module output name from the model and processor.

First checks :meth:`infer_modalities_edge_cases` for hard-coded overrides, then falls back
to general inference based on the processor type and model forward signature.
rp   re   NrÇ   r  rq   rs   rj   rZ   Úget_Ú	_featuresr�   r•   )rx   rß   Úinfer_modalities_edge_casesr  rÇ   rÍ   r#  r  Úinfer_modalities_from_processorrÐ   Ú_get_method_output_fieldsrq   rh   r¹   )r)  r  r  Údefault_modality_configÚdefault_module_output_nameÚdefault_method_output_nameÚresultrà   rá   ra  Úoutput_fieldsrw  Úentryr¯  rc   Úmethod_output_fieldss                   rG   r$  ÚTransformer.infer_modalitiesÁ  s*  € ô ?XÐX\×XmÑXmÑ>nÑ;ÐØ%<¸VÑ%DÐEYÑ%ZÐ"à×6Ñ6°uÓHÐHˆFÑUØ28Ñ/ˆOä�y /×2Ñ2°y×7NÑ7NÑ7ZØ OÓ3ð2Ø)×-Ñ-Ø"¨yÐPjÑ$kóð2ð ! $×"6Ñ"6×"EÑ"Eñ	2�O IÑ.ð #Ð6Ð6à×9Ñ9¸)ÓDˆ
Ü�9˜o×.Ñ.°9×3JÑ3JÑ3VØ×Ñ˜iÔ(ð ×6Ñ6°u·}±}ÓEˆØÑ Ð$>Ó$OØ.0ˆOÛ&�Ü&¨iÐLfÑg�Ø˜yÓ(Ø&*×&:Ñ&:×&IÑ&I�E˜(‘OØ,1 Ó)ñ	 'ð
 #Ð>Ð>ð × Ñ Ð$8Ó8Ø.0ˆOÛ&�Ø˜yÓ(Ùà $ X J¨iÐ8�Ü˜5×.Ó.Ü$ UÓ8�FØ+/×+IÑ+IÈ&Ó+QÐ(Þ+°ÐCWÓ0WØ?JÐbqÑ4r˜Ó1à?JÐbfÑ4g˜Ó1ñ 'ð #Ð$8Ð8Ð8ñ 'ó
â&�ð  ÐB\Ñ]Ò]Ù&ñ
ð &ð&ð 	&ùò 
s   Æ)F>c                ó¶  • [         R                  U R                  5      nUc  gUR                  UR                  R                  5      nUc  gUu  pVnU(       d  XV4$ 0 nUR                  5        Hf  u  pš[        XS   5      (       d#  [        R                  SU
S   < SU	< S35        M;  [        XS   5      nU
S   U R                  U
S   U5      S.X‰'   Mh     X†4$ )aÝ  Return a ``(modality_config, module_output_name)`` for model types that cannot be handled
by the general :meth:`infer_modalities` inference path, or ``None`` to fall through.

Looks up the model type in the task-specific edge case configs from
:data:`_EDGE_CASE_MODALITY_CONFIGS`. For entries that require output name validation
(transformers v4/v5 compat), resolves each modality's ``method_output_name`` against the
actual model method via :meth:`_infer_method_output_name`.
Nrc   zModel does not have method z for modality z. Skipping.re   rs   )r«   rÍ   rß   r  r  rº   r  r  Úwarning_oncer¹   Ú_infer_method_output_name)r)  r  r  Útask_edge_casesr   Ú
raw_configrá   Úvalidate_output_namesrà   rw  r0  rc   s               rG   r  Ú'Transformer.infer_modalities_edge_cases  sø   € ô 6×9Ñ9¸$×:OÑ:OÓPˆØÑ"Øà×#Ñ# E§L¡L×$;Ñ$;Ó<ˆØ‰=Øà@EÑ=ˆ
Ð(=Þ$ØÐ1Ð1à*,ˆØ *× 0Ñ 0Ö 2ÑˆHÜ˜5¨Ñ"2×3Ñ3Ü×#Ñ#Ø1°&¸Ñ2BÑ1EÀ^ÐT\ÑS_Ð_jÐkôñ Ü˜U¨8Ñ$4Ó5ˆFà  Ñ*Ø&*×&DÑ&DÀVÐL`ÑEaÐciÓ&jñ)ˆOÓ%ñ !3ð Ð2Ð2rF   c                ó¶  • SSSSS.n[        U[        5      (       aE  U R                  5       =(       d    0 nUR                  5        VVs/ s H  u  pEXC;   d  M  UPM     snn$ [        [
        [        [        S.nUR                  5        H  u  pW[        X5      (       d  M  U/s  $    [        R                  S[        U5      R                   S35        / $ s  snnf )	zWDetermine which modalities the processor supports by inspecting its attributes or type.rp   r“   r‹   rÆ   )r   Úimage_processorÚfeature_extractorÚvideo_processor)rp   r‹   rÆ   r“   z6Could not determine modalities from processor of type z#. Returning an empty modality list.)r¯   r#   Ú_get_processor_attributesrº   r"   r   r<   r   r  r  rÊ   rA   )r)  r  Úprocessor_attribute_mappingÚprocessor_attributesÚprocessor_attributer­  Úmodality_checksrÞ  s           rG   r  Ú+Transformer.infer_modalities_from_processor-  sé   € ð  Ø&Ø!(Ø&ñ	<
Ð#ô �i¤×0Ñ0Ø#'×#AÑ#AÓ#C×#IÀrÐ ð ;V×:[Ñ:[Ô:]ôâ:]Ñ6Ð'Ø&Ñ>÷ Ù:]òð ô ,Ü+Ü'Ü)ñ	1
ˆð />×.CÑ.CÖ.EÑ*ˆMÜ˜)×5Ó5Ø%�Ò&ñ /Fô 	�‰ØDÄTÈ)Ã_×E]ÑE]ÐD^ð _0ð 0ô	
ð ˆ	ùó)s   Á	CÁCc                óÐ   • [        U R                  S5      (       a  U R                  R                  5       $ [        U R                  S5      (       a  U R                  R                  $ g)zÝGet the attributes of the processor if available. Will be removed in the future as transformers v5
becomes the minimum requirement.

Returns:
    list[str] | None: The processor attribute names, or None if not available.
Úget_attributesÚ
attributesN)r  r  r5  r6  r4  s    rG   r.  Ú%Transformer._get_processor_attributesP  sM   € ô �4—>‘>Ð#3×4Ñ4Ø—>‘>×0Ñ0Ó2Ð2Ü�T—^‘^ \×2Ñ2Ø—>‘>×,Ñ,Ð,ØrF   c                óÔ   ^• U4S jm [        U 5      R                  SS5      nT" U5      nUc  g[        U5       Vs/ s H  o3R                  PM     sn$ ! [         a     gf = fs  snf )zÎExtract the output field names from a method's return type annotation.

Args:
    method (Callable): The method to inspect.

Returns:
    list[str] | None: List of output field names, or None if not found.
c                ó    >• [        U [        5      (       a  [        U [        5      (       a  U $ [	        U 5       H  nT" U5      =nc  M  Us  $    g r®   )r¯   rÊ   Ú
issubclassr+   r   )Útype_annotationÚsub_annotationr  Úfind_model_output_classs      €rG   r=  ÚFTransformer._get_method_output_fields.<locals>.find_model_output_classh  sL   ø€ Ü˜/¬4×0Ñ0´ZÀÔQ\×5]Ñ5]Ø&Ð&Ü"*¨?Ö";�Ù5°nÓEÐE�FÓRØ!’Mñ #<ð rF   ÚreturnN)r   rÍ   Ú	Exceptionr   r¾   )rc   Úreturn_annotationÚoutput_classÚfieldr=  s       @rG   r  Ú%Transformer._get_method_output_fields]  sq   ø€ õ	ð	Ü .¨vÓ 6× :Ñ :¸8ÀTÓ JÐñ /Ð/@ÓAˆØÑØÜ(.¨|Ô(<Ó=Ò(<˜u—
”
Ñ(<Ñ=Ð=øô ó 	Ùð	üò
 >s   ‰A ½A%Á
A"Á!A"c                óN   • [         R                  U5      =(       d    / nX;   a  U $ g)a`  Validate that ``method_output_name`` is present in the method's return type annotation.

Returns the name if found, or ``None`` if the method's output type does not include it.
Primarily needed for transformers v4 compatibility: v5 often allows ``pooler_output``
from ``get_..._features`` methods, but v4 didn't use ``BaseModelOutputWithPooling`` yet.
N)rÜ   r  )re   rc   r  s      rG   r%  Ú%Transformer._infer_method_output_namey  s(   € ô $×=Ñ=¸fÓE×KÈˆØÓ.Ø%Ð%ØrF   ©Úsafe_serializationc               óŽ   • U R                   R                  XS9  U R                  R                  U5        U R                  U5        g)z@Save the model, processor, and module config to ``output_path``.rG  N)r  Úsave_pretrainedr  Úsave_config)r)  Úoutput_pathrH  ÚargsrŠ  s        rG   ÚsaveÚTransformer.save†  s7   € à�
‰
×"Ñ" ;Ð"ÑVØ�‰×&Ñ& {Ô3Ø×Ñ˜Õ%rF   c                óH   • U R                  UUUUUUUUU	U
US9nU " SSU0UD6$ )zWLoad a Transformer module from a pretrained model directory or Hugging Face model name.)r*  r÷  rõ  Úcache_folderrö  rø  Útrust_remote_coderè   ré   rê   rë   r*  r?   )Ú_load_init_kwargs)r¼   r*  r÷  rõ  rQ  rö  rø  rR  rè   ré   rê   rë   rŠ  Úinit_kwargss                 rG   ÚloadÚTransformer.loadŒ  sP   € ð& ×+Ñ+Ø1ØØØ%ØØ-Ø/Ø%Ø-Ø'Øð ,ð 
ˆñ ÑHÐ&8ÐH¸KÑHÐHrF   c           	     óþ  • U R                  UUUUUUS9nUUUUUUS.nSSSS.nUR                  5        H2  u  nnUU;   a  UR                  U5      UU'   UR                  U0 5        M4     US   R	                  U5        US   R	                  U5        US   R	                  U5        U(       a  US   R	                  U5        U	(       a  US   R	                  U	5        U
(       a  US   R	                  U
5        0 UESU0E$ )z±Build the kwargs dict for ``__init__`` by merging config file, hub kwargs, and caller overrides.

Priority (highest to lowest): caller kwargs > hub kwargs > config file values.
)r*  r÷  rõ  rQ  rö  rø  )r÷  rõ  rô  rö  rø  rR  rè   ré   rê   )Ú
model_argsÚtokenizer_argsÚconfig_argsrë   )r  rº   r}  Ú
setdefaultrz  )r¼   r*  r÷  rõ  rQ  rö  rø  rR  rè   ré   rê   rë   rŠ  r  Ú
hub_kwargsÚ_OLD_TO_NEWÚold_nameÚnew_names                     rG   rS  ÚTransformer._load_init_kwargs®  s/  € ð, —‘Ø1ØØØ%ØØ-ð !ð 
ˆð #ØØ%Ø Ø 0Ø!2ñ
ˆ
ð )Ø0Ø*ñ
ˆð
 #.×"3Ñ"3Ö"5ÑˆH�hØ˜6Ó!Ø#)§:¡:¨hÓ#7��xÑ Ø×Ñ˜h¨Ö+ñ #6ð 	ˆ~Ñ×%Ñ% jÔ1ØÐ!Ñ"×)Ñ)¨*Ô5ØˆÑ×&Ñ& zÔ2ö Ø�>Ñ"×)Ñ)¨,Ô7ÞØÐ%Ñ&×-Ñ-Ð.>Ô?ÞØ�?Ñ#×*Ñ*¨=Ô9à-�&Ð-˜) WÑ-Ð-rF   c                ó|  >• U(       a  U/O/ SQnU H  n[         TU ]  UUUUUUUS9n	U	(       d  M    O   S H(  n
U
W	;   d  M  SXš   ;   d  M  Xš   R                  S5        M*     SW	;   a´  1 Skn0 nU	S   R                  5        H‘  u  pÞSU;   aa  [	        UR                  S5      5      nU Vs/ s H  nUU;  d  M  UPM     nnU(       a   [        R                  SU< S	U< S
35        Mf  XìU'   Ml  XÛ;  a  [        R                  SU< S35        M�  XìU'   M“     XÉS'   U	$ U R                  U	5      u  U	S'   U	S'   U	$ s  snf )a  Load the module config, trying several legacy config filenames for backward compatibility.

Handles deserialization of ``modality_config`` tuple keys (stored as comma-separated strings
in JSON) and strips ``trust_remote_code`` from all sub-dicts for security.
)rÝ   zsentence_roberta_config.jsonzsentence_distilbert_config.jsonzsentence_camembert_config.jsonzsentence_albert_config.jsonz sentence_xlm-roberta_config.jsonzsentence_xlnet_config.json)r*  r÷  Úconfig_filenamerõ  rQ  rö  rø  )rX  rè   rY  ré   rZ  rê   rR  rà   >   rp   r‹   r“   rÆ   r  Ú+z%Ignoring unknown modality components z in modality_config key r˜  zIgnoring unknown modality key z in modality_config.rá   )	r  r  r}  rº   rŸ  Úsplitr  r  Ú_get_default_modality_config)r¼   r*  r÷  rb  rõ  rQ  rö  rø  Úconfig_filenamesr  rp  Úvalid_single_modalitiesÚdeserialized_modality_configr/  r0  ÚpartsÚpÚinvalidr'  s                     €rG   r  ÚTransformer.load_configó  s’  ø€ ö$ ð Ñòð 	ó  0ˆOÜ‘WÑ(Ø#5Ø#Ø /ØØ)Ø!Ø!1ð )ð ˆF÷ ˆvÙñ  0ó
ˆCð �f�}Ð!4¸¹Õ!CØ‘—‘Ð 3Ö4ñ
ð  Ó&â&TÐ#Ø+-Ð(Ø(.Ð/@Ñ(A×(GÑ(GÖ(IÑ$�Ø˜,Ó&Ü! ,×"4Ñ"4°SÓ"9Ó:�EÙ*/ÓTª% Q°1Ð<SÑ3SŸq©%�GÐTÞÜŸ™ØCÀGÁ;ÐNfÐgsÑfvÐvwÐxôñ !Ø:@°Ó7à#ÓBÜŸ™Ð)GÈÑGWÐWkÐ'lÔmÙ ØAG°Ó>ñ )Jð )EÐ$Ñ%ð ˆð GJ×FfÑFfÐgmÓFnÑCˆFÐ$Ñ% vÐ.BÑ'Càˆùò- Us   Â+
D9Â9D9c                ó4   • [         U R                  SS5         $ )a[  Get the default modality configuration for the current transformer task.

Returns:
    tuple[ModalityConfig, str]: A tuple of (modality_config, module_output_name).
        The modality_config maps modality keys to dicts with 'method' and 'method_output_name'.
        The module_output_name is the name of the output feature this module creates.
rß   rZ   )rx   rÍ   )r  s    rG   re  Ú(Transformer._get_default_modality_configH  s   € ô )¨¯©Ð4FÐH\Ó)]Ñ^Ð^rF   c                ó,  >• [         TU ]  5       nU R                  R                  5        VVs0 s H  u  p#[	        U5      U_M     snnUS'   U R
                  (       d  UR                  SS5        U R                  c  UR                  SS5        U$ s  snnf )zdReturn the config dict for serialization, with tuple modality keys joined as plus-separated strings.rà   râ   Nrã   )r  Úget_config_dictrà   rº   r2   râ   r}  rã   )r)  Úconfig_dictrw  r0  r'  s       €rG   rp  ÚTransformer.get_config_dictS  s‹   ø€ ä‘gÑ-Ó/ˆàFJ×FZÑFZ×F`ÑF`ÔFbô*
ÚFbÑ2B°(ŒO˜HÓ% vÒ-ÑFbò*
ˆÐ%Ñ&ð ×%×%Ø�O‰OÐ/°Ô6Ø×ÑÑ$Ø�O‰O˜N¨DÔ1ØÐùó*
s   ­Bc                óv   • S[        U R                  5       U R                  R                  R                  S9 S3$ )NzTransformer()ÚarchitectureÚ))rÏ   rp  r  r'  rA   r4  s    rG   Ú__repr__ÚTransformer.__repr___  s3   € Øœd 4×#7Ñ#7Ó#9ÈÏ
É
×H\ÑH\×HeÑHeÑfÐgÐghÐiÐirF   )r  r  r3  rë   r7  rQ  rí   r#  rà   r  r  rá   râ   r  r  rß   rã   )r*  rb   rß   ÚTransformerTaskrè   údict[str, Any] | Noneré   ry  rê   ry  râ   zProcessingKwargs | Nonerë   z$Literal['torch', 'onnx', 'openvino']rà   zModalityConfig | Nonerá   rd   rã   úbool | Nonerì   ú
int | Nonerí   rå   rî   rd   r?  ÚNone)r?  rz  )rÀ   rz  r?  r|  ©r?  rå   )r?  r{  )rÀ   r{  r?  r|  )r?  r!   )r?  r    )r?  úlist[Modality])r?  zPreTrainedTokenizerBase | Noner®   )rˆ  zlist[SingleInput | PairInput]r‰  rd   r?  rÄ   )r¬  rÄ   r?  rÄ   )r?  Úint)
rw  r5   r�  zdict[str, list]rŒ  údict[str, dict[str, Any]]r‹  rÄ   r?  rÄ   )rÑ   zlist[list[MessageInput]]rŒ  r€  r‹  rÄ   r?  rÄ   )r‰  rb   r?  r{  )r*  rb   rë   rb   rê   rÄ   r?  z*tuple[PeftConfig | PretrainedConfig, bool])r*  rb   rß   zfLiteral['feature-extraction', 'sequence-classification', 'text-generation', 'any-to-any', 'fill-mask']r  zPeftConfig | PretrainedConfigrë   rb   r-  rå   r?  r!   )r*  rb   r  r    r?  zPreTrainedModel | None)r  r!   r  zmProcessorMixin | PreTrainedTokenizerBase | FeatureExtractionMixin | BaseVideoProcessor | ImageProcessingMixinr?  útuple[ModalityConfig, str])r  r!   r  úXProcessorMixin | PreTrainedTokenizerBase | FeatureExtractionMixin | ImageProcessingMixinr?  z!tuple[ModalityConfig, str] | None)r  r‚  r?  r~  )r?  úlist[str] | None)rc   r   r?  rƒ  )re   rb   rc   r   r?  rd   )rL  rb   rH  rå   r?  r|  )
rË   NNNFFNNNrç   )r*  rb   r÷  rb   rõ  úbool | str | NonerQ  rd   rö  rd   rø  rå   rR  rå   rè   ry  ré   ry  rê   ry  rë   rb   r?  r;   )r*  rb   r÷  rb   rõ  r„  rQ  rd   rö  rd   rø  rå   rR  rå   rè   ry  ré   ry  rê   ry  rë   rb   r?  rÄ   )rË   NNNNF)r*  rb   r÷  rb   rb  rd   rõ  r„  rQ  rd   rö  rd   rø  rå   r?  rÄ   )r  rÄ   r?  r�  )r?  rÄ   )r?  rb   )0rA   rB   rC   rD   rl   rÞ   rf   rä   ræ   r9   r  Úpropertyrã   Úsetterr8  rì   r\  r  ra  r   r“  rq   rÉ  r„  rÍ  rÎ  rÌ  r‚  r  r  rÿ  r$  r  r  r.  Ústaticmethodr  r%  rN  ÚclassmethodrU  rS  r  re  rp  rv  rE   Ú__classcell__)r'  s   @rG   rÜ   rÜ   ß  s  ø‡ ñUðn 8Ð�cÓ7ò€K�ó ð €L�$Óà!ð
 -AØ.2Ø26Ø/3Ø59Ø8?Ø15Ø)-Ø$(Ø%)Ø#Ø-1ña)àða)ð *ð	a)ð
 ,ða)ð 0ða)ð -ða)ð 3ða)ð 6ða)ð /ða)ð 'ða)ð "ða)ð #ða)ð ða)ð !+ða)ð  
÷!a)ó "ða)ðF ó
"ó ð
"ð ×Ñó
ó ð
ôEðN óó ðð  ×Ñó4ó ð4ð
 óó ðð ó!ó ð!ð ó1ó ð1ð ó:ó ð:ð "ðr à-ðr ð ðr ð
 
õr ôh]ô~3
ðj$pàð$pð *ð$pð 3ð	$pð
 &ð$pð 
ô$pðL 
àð 
ð *ð 
ð 3ð	 
ð
 &ð 
ð 
ô 
ðD
àð
ð *ð
ð 3ð	
ð
 &ð
ð 
ô
ðB@
à*ð@
ð 3ð@
ð &ð	@
ð
 
ô@
ôDð,&VØ"%ð&VØ03ð&VØDRð&Và	3ô&VðP2vàð2vð
ð2vð .ð2vð ð2vð ð2vð 
ô2vðh'àð'ð !ð'ð
 
 ô'ðRC&àðC&ððC&ð 
$ôC&ðJ%3àð%3ð lð%3ð 
+ô	%3ðN!àkð!ð 
ô!ôFð ó>ó ð>ð6 ó
ó ð
ð HL÷ &ð ð
 Ø#'Ø#'Ø#Ø!&à"'Ø.2Ø26Ø/3ØðIàðIð ð	Ið
 !ðIð !ðIð ðIð ðIð  ðIð ,ðIð 0ðIð -ðIð ðIð  
ô!Ió ðIðB ð
 Ø#'Ø#'Ø#Ø!&à"'Ø.2Ø26Ø/3ØðB.àðB.ð ð	B.ð
 !ðB.ð !ðB.ð ðB.ð ðB.ð  ðB.ð ,ðB.ð 0ðB.ð -ðB.ð ðB.ð  
ô!B.ó ðB.ðH ð Ø&*Ø#'Ø#'Ø#Ø!&ðRàðRð ðRð $ð	Rð
 !ðRð !ðRð ðRð ðRð 
÷Ró ðRðh ó_ó ð_÷
÷jò jrF   rÜ   r}  )rÑ   zlist[list[dict[str, Any]]]r?  ztuple[list[int], list[int]])tÚ
__future__r   r  r  Úcollections.abcr   Ú
contextlibr   Údataclassesr   Útypingr   r   r	   r
   r   r   rç   Úpackaging.versionr   Úparse_versionÚtokenizers.normalizersr   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   Útransformers_versionÚtransformers.utilsr+   r,   Útransformers_loggingÚtransformers.utils.import_utilsr-   Útransformers.utils.peft_utilsr.   Úsentence_transformers.backendr/   r0   Ú#sentence_transformers.base.modalityr1   r2   Ú)sentence_transformers.base.modality_typesr3   r4   r5   r6   r7   Ú/sentence_transformers.base.modules.input_moduler8   Ú%sentence_transformers.util.decoratorsr9   Ú&sentence_transformers.util.environmentr:   r;   r  Útyping_extensionsr<   rI   rJ   rO   rR   rU   r¥  rY   Ú
get_loggerrA   r  r×  rç  rx  r`   rh   rÏ   ÚModalityConfigrn   rf   ro   rx   rŠ   r�   r©   rª   Ú_TEXT_GENERATION_EDGE_CASESÚ_ANY_TO_ANY_EDGE_CASESr«   r·   rÁ   rÃ   rÚ   rÜ   r?   rF   rG   Ú<module>r¢     sñ  ðÞ "ã Û Ý $Ý %Ý ß S× Sã Ý 4ß 6÷÷ ÷ ÷ ÷ ÷ ÷ õ8 =Ý *Ý >Ý =Ý Bç Nß O÷õ õ HÝ NÝ Mð'ÝðÝ/ðß?ðÝ*ðÝ,ðÝ.ö Ñ&×(Ñ(Ýà	×	(Ò	(¨Ó	2€á3@ÐAUÓ3VÑYfÐgoÓYpÑ3pÐ 0Ù@MÐNbÓ@cÑgtØóhñ AÐ =ð Øañ€ô
#˜iô #ô
*Ð,°Eò *ð �h Ð.Ñ/€ð $ØAØ+Ø%ñ	>Ð Ð :ó ð	Ý5ð 	!ð # <Ñ0ð 
˜IÐ=PÑQÐRØðð
 
˜I¸XÑFÐGØð ð
 
˜I¸XÑFÐGØðð
 
˜I¸XÑFÐGØðð
 
˜I¸XÑFÐGØðñ#PÐ ÐLó ð4 ˆ~Ð/Ð0Ø�Ð 1Ð2Ø�Ð!3Ð4Ø�Ð!3Ð4Ø�>Ð#7Ð8Ø�~Ð':Ð;Ø˜~Ð/OÐPØÐKÐM`ÐaàØHØ ðð
 ÐAÀ?ÐSØÐBÐDTÐUØÐGÐIZÐ[ØÐHÐJ\Ð]ØÐBÐDTÐUØÐ?ÀÐQð ÐIÐK\Ð]ð-5Ð Ð1ó ð> &Ð=PÑQØ&/ÐGZÑ[ñð Ø	ð<Ð Ð8ó ðhOà
à2È/ÑZØ 4ÈOÑ\Ø*CÐ[jÑkñ	
ð
 	ØððhOð à2ÐJ]Ñ^Ø 4ÐL_Ñ`ñ	
ð 	ØððhOð& à2ÐJ]Ñ^Ø 5ÐM`Ñañ	
ð 	Øðð'hOð6 à2È/ÑZØ 4ÈOÑ\ñ	
ð 	Øðð7hOðH 
à(Ð@SÑTØ*3ÐK^Ñ_ñ	
ð 	ØððIhOðX à(Ð@SÑTØ*3ÐK^Ñ_ñ	
ð 	ØððYhOðj Ø	 yÐH[Ñ\Ð]ØØððkhOðt Ø	 yÐH[Ñ\Ð]ØØððuhOð~ Ø	 yÐH[Ñ\Ð]ØØððhOðH Ø	 yÐH[Ñ\Ð]ØØððIhOðT à )ÐATÑUØ*3ÐK^Ñ_ñ	
ð 	ØððUhOðf à(Ð@SÑTØ )ÐATÑUØ*3ÐK^Ñ_ñ	
ð
 	ØððghOðz Ð$ð{hOð| Ð'ð}hOð~ 
Ð!ðhOð@ Ð#ðAhOðB Ð+ðChOðD (Ø&Ø0Ø#Ø%Ø.òOhOÐ Ð Kó hðZ à 	ÀÑJð	
ð 	Øðð
FÐ ÐBó 
ð   )ÀÑIØ*3È8ÑTñ	
ð 	Øðð ˜yÀÑIð	
ð 	ØðñÐ ð0  )ÀÑIØ*3È8ÑTñ	
ð 	Øðð 
 yÈÑQÐRØØðð 
 yÈÑQÐRØØðð 
 yÈÑQÐRØØðð 
 yÈÑQÐRØØðð !*ÀÑJØ*3È8ÑTñ	
ð 	ØðñA(Ð ðV 9Ø2Ø(Ø&ñ	WÐ ÐSó ôð ñ&ó ð&ô"�y¨ò "ô "ô:Aj�+õ AjøðC ó 'ß&Ð&ð'ûð
 ó ÷ô ðûð ó ÷ñ ÷ô ðûð ó ÷ô ðûð ó ÷ô ðûð ó ÷ô ðûðh ó 	Úð	ús~   ÃM0 ÃN ÃN Ã"N; Ã)O Ã0O) Å1P  Í0N Í?N ÎNÎNÎN8Î7N8Î;OÏOÏO&Ï%O&Ï)O=Ï<O=Ð P
Ð	P
