
    .`iI                        U d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ d dlmZmZmZ d dlZd dlmZ d d	lmZ d d
lmZmZ d dlmZ d dlmZmZ d dlmZ d dlmZ  d dl!m"Z" d dl#m$Z$ d dl%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2m3Z3 	 d dl4m5Z5 n# e6$ r	 d dl4m7Z5 Y nw xY we"j8        rd dl9m:Z: nd dlm:Z: dZ; e$e<          Z= G d de>          Z? e?di ddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d3d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRZ@e>eAeBe         f         eCdS<   dTdUiZDe>eAeAf         eCdV<   dWdXidYdZidWdXid[ZEe>eAe>eAef         f         eCd\<   d]e>eAef         d^eFfd_ZG G d` dae(          ZH G db dce(          ZIeHeIddZJe>eAeBe(         f         eCde<   edf         ZKdgeAd^e(fdhZLdgeAfdiZMdjedkeNd^dfdlZOdjed^dfdmZPd]e>eAef         d^dfdnZQdjed^eFfdoZRdjed^eFfdpZSdjed^eFfdqZTdjed^eUfdrZVdjed^eFfdsZWdjed^eFfdtZXdue>eAef         dveAfdwZYdjed^efdxZZ	 	 ddyeAdzeAdz  d{eFd|eAdz  d}e>eAef         dz  d^e[eAeAdz  e>eAef         dz  f         fd~Z\	 	 	 	 	 ddyeAez  d{eFd|eAdz  deAdz  dgeAeKz  de>eAef         dz  deegef         dz  d^efdZ]e	 ddyeAd|eAdz  d^e>eAef         dz  fd            Z^deAfdZ_e	 ddyeAez  d|eAdz  fd            Z`ddZa	 	 ddyeAez  deFeAz  dz  d|eAdz  d^e>eAef         fdZbdjefdZc	 	 ddyeAd{eFd|eAdz  dgeAeKz  d^edz  f
dZddddyeAd|eAdz  fdZe	 ddeAe jf        z  d{eFd|eAdz  d^e>eAef         dz  fdZge	 ddyeAez  d|eAdz  d^ehe>eAef                  dz  fd            ZidddyeAd|eAdz  d^e>eAef         fdZjd^e>fdZkd^eUfdZldS )    N)Callable)asdict)cachepartial)version)Path)AnyLiteral	TypeAlias)get_safetensors_metadata)Version)GenerationConfigPretrainedConfig)get_image_processor_config)!MODEL_FOR_CAUSAL_LM_MAPPING_NAMESMODEL_MAPPING_NAMES)get_tokenizer_config)CONFIG_NAME)envs)init_logger)parse_safetensors_file_metadata   )ConfigParserBase)check_gguf_fileis_ggufis_remote_ggufsplit_remote_gguf)file_or_path_existsget_hf_file_to_dictlist_repo_filestry_get_local_file
with_retry)ALLOWED_ATTENTION_LAYER_TYPES)ALLOWED_LAYER_TYPES)
AutoConfigparams.jsonc                        e Zd Z fdZ xZS )LazyConfigDictc                     t          t                                          |          x}t                    r|S dd lmc m} t          ||          S )Nr   )
isinstancesuper__getitem__typevllm.transformers_utils.configstransformers_utilsconfigsgetattr)selfkeyvaluer0   	__class__s       r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/transformers_utils/config.pyr,   zLazyConfigDict.__getitem__@   s\    uww223777e>> 	L999999999w&&&    )__name__
__module____qualname__r,   __classcell__)r5   s   @r6   r(   r(   ?   s8        ' ' ' ' ' ' ' ' 'r7   r(   afmoeAfmoeConfigbagelBagelConfigchatglmChatGLMConfigdeepseek_vl_v2DeepseekVLV2Configdeepseek_v32DeepseekV3Config	flex_olmoFlexOlmoConfig
hunyuan_vlHunYuanVLConfigisaacIsaacConfigkimi_linearKimiLinearConfigkimi_vlKimiVLConfigkimi_k25KimiK25Config
RefinedWebRWConfigRefinedWebModeljais
JAISConfigmlp_speculatorMLPSpeculatorConfigmedusaMedusaConfigmidashenglmMiDashengLMConfigeagleEAGLEConfigspeculatorsSpeculatorsConfignemotronNemotronConfigolmo3Olmo3Configovis
OvisConfigultravoxUltravoxConfigstep3_vlStep3VLConfig
step3_textStep3TextConfig
qwen3_nextQwen3NextConfiglfm2_moeLfm2MoeConfigtarsier2Tarsier2Config_CONFIG_REGISTRY
llm_configtext_config_CONFIG_ATTRS_MAPPINGhas_no_defaults_at_initTattn_implementationeager)internvl_chatLlama_Nemotron_Nano_VLNVLM_D_AUTO_CONFIG_KWARGS_OVERRIDESrope_parametersreturnc                 |    | sdS t          |                                                               t                    S )z2Check if rope_parameters is nested by layer types.F)setkeysissubsetr#   )r~   s    r6   is_rope_parameters_nestedr   s   s:      u##%%&&//0MNNNr7   c                   R    e Zd Z	 	 ddeez  dededz  dedz  deeef         f
dZ	dS )	HFConfigParserNmodeltrust_remote_coderevisioncode_revisionr   c                 T   t           j        j        |d<   t          j        |f|||d|\  }}|                    d          }||                    d          dn|}|                    dd           x}	|	                    d|          }|t          v r t          |         }
 |
j        |f|||d|}nb	 t          ||          }t          j        |f|||d|}n9# t          $ r,}|s#d	t          |          v rd
}t          |          ||d }~ww xY wt          |          }||fS )Nlocal_files_only)r   r   r   
model_typespeculators_configr_   hf_overrides)r   )r   r   r   z.requires you to execute the configuration filezFailed to load the model config. If the model is a custom model not yet available in the HuggingFace transformers library, consider setting `trust_remote_code=True` in LLM or using the `--trust-remote-code` flag in the CLI.)huggingface_hub	constantsHF_HUB_OFFLINEr   get_config_dictgetpoprs   from_pretrained _maybe_update_auto_config_kwargsr%   
ValueErrorstrRuntimeError_maybe_remap_hf_config_attrs)r2   r   r   r   r   kwargsconfig_dict_r   r   config_classconfigeerr_msgs                 r6   parsezHFConfigParser.parse|   s    &5%>%M!")9
'/	
 

 
 
Q !__\22
 ??#788D   #JJ~t<<<LI%)),
CCJ)))+J7L1\1!+"3	 
  FF9&ZXXX#3&7%"/	 
      )HCPQFFRRA  'w//Q6G .f55F""s   6'C 
D('DDNN
r8   r9   r:   r   r   booltupledictr   r    r7   r6   r   r   {   s|        
  $$(?# ?#Tz?#  ?# *	?#
 Tz?# 
t%%	&?# ?# ?# ?# ?# ?#r7   r   c                   R    e Zd Z	 	 ddeez  dededz  dedz  deeef         f
dZ	dS )	MistralConfigParserNr   r   r   r   r   c                    t          ||          }|                    d          x}	 t          ||fi |}||d<   ddlm} 	 t          j        |f||d|\  }	}
n# t          $ r i }	Y nw xY w |||	          }t          |dd           x}ret          |t                    rP|j        t          |          z  }||z  }d |D             |_        t          t          d |          d           |_        ||fS )Nmax_position_embeddingsr   )adapt_config_dict)r   r   )defaultssliding_windowc                     g | ]}|dnd	S )Nfull_attentionsliding_attentionr   ).0
layer_types     r6   
<listcomp>z-MistralConfigParser.parse.<locals>.<listcomp>   s4     " " " %/$6  <O" " "r7   )_download_mistral_config_filer   _maybe_retrieve_max_pos_from_hf'vllm.transformers_utils.configs.mistralr   r   r   OSErrorr1   r*   listnum_hidden_layerslenlayer_typesnextfilterr   )r2   r   r   r   r   r   r   r   r   hf_config_dictr   r   r   pattern_repeatsr   s                  r6   r   zMistralConfigParser.parse   s    4E8DD'27P'Q'QQ# 'Fx' '#)' '# 6MK12MMMMMM	  0 @!!+! ! 	! !NAA  	  	  	 NNN	  #";HHH &f.>EEEN 		M:DL
 L
 		M %6#n:M:MMO(?:K" ""-" " "F %)n)E)Et$L$LF!F""s   A A+*A+r   r   r   r7   r6   r   r      s|        
  $$(/# /#Tz/#  /# *	/#
 Tz/# 
t%%	&/# /# /# /# /# /#r7   r   )hfmistral_CONFIG_FORMAT_TO_CONFIG_PARSER)autor   r   config_formatc                 b    | t           vrt          d|  d          t          |                      S )z0Get the config parser for a given config format.zUnknown config format `z`.)r   r   )r   s    r6   get_config_parserr      s9    ;;;D=DDDEEE*=9;;;r7   c                       fd}|S )a]  Register a customized vllm config parser.
     When a config format is not supported by vllm, you can register a customized
    config parser to support it.
     Args:
         config_format (str): The config parser format name.
     Examples:

         >>> from vllm.transformers_utils.config import (get_config_parser,
                                                         register_config_parser)
         >>> from vllm.transformers_utils.config_parser_base import ConfigParserBase
         >>>
         >>> @register_config_parser("custom_config_parser")
         ... class CustomConfigParser(ConfigParserBase):
         ...     def parse(
         ...         self,
         ...         model: Union[str, Path],
         ...         trust_remote_code: bool,
         ...         revision: str | None = None,
         ...         code_revision: str | None = None,
         ...         **kwargs,
         ...     ) -> tuple[dict, PretrainedConfig]:
         ...         raise NotImplementedError
         >>>
         >>> type(get_config_parser("custom_config_parser"))
         <class 'CustomConfigParser'>
    c                     t           v rt                              d|            t          | t                    st          d          | t           <   t                              d|            | S )Nz_Config format `%s` is already registered, and will be overwritten by the new parser class `%s`.z;The config parser must be a subclass of `ConfigParserBase`.z5Registered config parser `%s` with config format `%s`)r   loggerwarning
issubclassr   r   info)config_parser_clsr   s    r6   _wrapperz(register_config_parser.<locals>._wrapper   s    ;;;NN<!	   +-=>> 	M   :K'6C	
 	
 	

 ! r7   r   )r   r   s   ` r6   register_config_parserr     s#    8! ! ! ! !( Or7   r   default_thetac                 d    t          | dd          	ddi| _        d| j        vr|| j        d<   dS dS )zSome models may have no rope_theta in their config but still use RoPE.
    This function sets a default rope_theta if it's missing.r~   N	rope_typedefault
rope_theta)r1   r~   )r   r   s     r6   set_default_rope_thetar   7  sM     v($//7"-y!96111/<|,,, 21r7   c                    ddl m} ddg} || |dd          }g d} || |dd          }t          | d	d          }t          t	          d
                    t          d          k     r_t          | dd          x}|| _        |||t          | dd          s	ddi| _        |
|| j        d<   |
|| j        d<   |
|| j        d	<   nM|t          | dd          r:||| _        ||| _        |                                  | 	                                 t          | dd          dS t          | j                  r-| j                                        D ]}t          |           dS t          | j                   dS )z)Provide backwards compatibility for RoPE.r   )getattr_iterr   rotary_emb_baseNT)warn)partial_rotary_factor
rotary_pctrotary_emb_fraction original_max_position_embeddingstransformersz
5.0.0.dev0rope_scalingr~   r   r   r   )vllm.config.utilsr   r1   r   r   r~   r   r   standardize_rope_paramsvalidate_roper   valuespatch_rope_parameters_dict)r   r   namesr   r   omper   rope_parameters_layer_types           r6   patch_rope_parametersr   @  s   ...... ,-EfeT===JJJJE(L4HHH6=tDDDw~&&''',*?*???#FNDAAALN%1F""$0&"3T::  &19%=F"!3=F"<0 ,>SF"#:;IMF"#EF		763Dd#K#K	 ! *F ,+@F(&&((( v($//7 !!788 ;*0*@*G*G*I*I 	C 	C&&'ABBBB	C 	C 	#6#9:::::r7   c                    d| v rId| v rE| d         }| d         }|dk    r|dk    s|dk    r|dk    rn||k    rt          d| d| d	          d| vr)d| v r%| d         | d<   t                              d
           d| vrt          d          | d         dk    r!d| d<   t                              d           d S | d         dk    r4d| vrt          d          d| d<   t                              d           d S d S )Nr   r-   sulongropemroper   z#Found conflicts between 'rope_type=z' (modern field) and 'type=z6' (legacy field). You should only specify one of them.z,Replacing legacy 'type' key with 'rope_type'z-rope_parameters should have a 'rope_type' keyz/Replacing legacy rope_type 'su' with 'longrope'mrope_sectionzDLegacy rope_type 'mrope' requires 'mrope_section' in rope_parametersz1Replacing legacy rope_type 'mrope' with 'default')r   r   r   r   )r~   r   rope_type_legacys      r6   r   r   t  s}   o%%&O*C*C#K0	*62$$j)@)@''I,B,B***7i 7 7$47 7 7   /))f.G.G'6v'>$BCCC/))HIII{#t++'1$HIIIII		%	0	0/11V   (1$JKKKKK 
1	0r7   c                 4    t          | dd           }|dS d|v S )Nr~   Fr   r1   )r   r~   s     r6   _uses_mroper     s*    f&7>>Ouo--r7   c                     t          |           p/t          |                                           pt          |           S )z1Detect if the model with this config uses M-ROPE.)r   get_text_configthinker_uses_mroper   s    r6   
uses_mroper     s@     	F 	&v--//00	&f%%r7   c                 t    t          | dd          }|dS t          |dd          }|dS t          |          S )zADetect if the model contains a thinker config and it uses M-ROPE.thinker_configNFru   )r1   r   )r   r   thinker_text_configs      r6   r   r     sK    V%5t<<Nu!.-FF"u)***r7   c                 ,   t          | dd          }|$t          |t                    rt          |          S t          | dd          }|dS t          |t                    r2d|v r.|d         }|$t          |t                    rt          |          S dS )z2Detect if the model with this config uses XD-ROPE.xdrope_sectionNr   r   )r1   r*   r   r   r   )r   r   r   s      r6   uses_xdrope_dimr     s    V%5t<<N!j&F&F!>"""6>488Lq,%% '*:l*J*J%&67%*^T*J*J%~&&&1r7   c                 v    dt           dt          fd} ||           p ||                                           S )zCDetect if the model with this config is used as an encoder/decoder.r   r   c                 $    t          | dd          S )Nis_encoder_decoderFr   r   s    r6   _is_encoder_decoderz/is_encoder_decoder.<locals>._is_encoder_decoder  s    v3U;;;r7   )r   r   r   )r   r  s     r6   r  r    sU    <$4 < < < < < v&&W*=*=f>T>T>V>V*W*WWr7   c                     |                                  }t          |dd          x}r t          t          |                    dk    S dS )zR
    Detect if the model with this config is used with interleaved attention.
    r   Nr   F)r   r1   r   r   )r   ru   r   s      r6   is_interleavedr    sN     ((**Kk=$???{ )3{##$$q((5r7   r   r   c                 X    |t           v r |                     t           |                    | S )zI
    Update kwargs for AutoConfig initialization based on model_type
    )r}   update)r   r   s     r6   r   r     s-     2223J?@@@Mr7   c                    t                                           D ]f\  }}t          | |          rQt          | |          s%|                     |t	          | |          i           t
                              d||           g| S )z4Remap config attributes to match the expected names.z&Remapped config attribute '%s' to '%s')rv   itemshasattrr  r1   r   debug)r   old_attrnew_attrs      r6   r   r     s    399;; W W(68$$ 	W68,, Ex)B)BCDDDLLA8XVVVMr7   r   	tokenizerr   r   vllm_speculative_configc                    t          |           r,t          |           j        |d<   t          |           j        }n3t	          |           r"t          |           \  }}t          |          }nd}t          j        j        |d<   t          j
        || n|f||d|\  }	}|	                    d          }
|
| ||fS ddlm} |                    |	          }| |d	<   |
d
         d         }|x} }| ||fS )a!  
    Resolve model configuration when speculators are detected.

    Checks if the provided model is a speculators model and if so, extracts
    the target model configuration and builds the speculative config.

    Args:
        model: Model name or path
        tokenizer: Tokenizer name or path
        trust_remote_code: Whether to trust remote code
        revision: Model revision
        vllm_speculative_config: Existing vLLM speculative config

    Returns:
        Tuple of (resolved_model, resolved_tokenizer, speculative_config)
    	gguf_fileNr   )r   r   r   r   )r`   )r   r   verifiername_or_path)r   r   nameparentr   r   r   r   r   r   r   r   0vllm.transformers_utils.configs.speculators.baser`   extract_vllm_speculative_config)r   r  r   r   r  r   gguf_model_reporepo_idr   r   r   r`   speculative_configverifier_models                 r6   maybe_override_with_speculatorsr    sJ   0 u "5kk.{u++,			 &u--
w--!0!:!IF%5 (o+  	 NK %)=>>!i!888 SRRRRR*JJ K  
 #(w (
3NCN&&EI)///r7   r   r   hf_overrides_kwhf_overrides_fnc                    t          |           }t          |           }	|rOt          |           r,t          |           j        |d<   t          |           j        } n|	rt          |           \  } }
|dk    r	 t          | t          |          rd}nq|r|	rt          | t          |          rd}nS|	rBt          | t          |          s+d}t                              |           t          |          t          d          n8# t          $ r+}d                    | 	          }t          |          |d }~ww xY wt          |          } |j        | f||||d
|\  |r*dt"          dt$          ffd}j        dv r |dd           |rPj        t(          vrt+          dj         d          t(          j                 }                    d|gi           j        sSj        t0          vrt                              d           n*t0          j                 }                    d|gi                               dd           }|"t          | d|          rt7          d| |          }||_        |                    dd           }|dv rft;          j        d          s+dt>          j         d<   t          !                    d|           n't:          j"        st          #                    d|           |r0t          $                    d|                               |           |r&t          $                    d|            |          tK                     tK          &                                           tN          t"          tP          f         }tS          dd           }|r"|D ]}tK          tS          |                      |rtU                       S )Nr  r   r   r   r   a  Could not find config.json for remote GGUF model repo. To load remote GGUF model through `<repo_id>:<quant_type>`, ensure your model has config.json (HF format) file. Otherwise please specify --hf-config-path <original_repo> in engine args to fetch config from unquantized hf model.a	  Could not detect config format for no config file found. With config_format 'auto', ensure your model has either config.json (HF format) or params.json (Mistral format). Otherwise please specify your_custom_config_format in engine args for customized config parser.ak  Invalid repository ID or local directory specified: '{model}'.
Please verify the following requirements:
1. Provide a valid Hugging Face repository ID.
2. Specify a local directory that contains a recognized configuration file.
   - For Hugging Face models: ensure the presence of a 'config.json'.
   - For Mistral models: ensure the presence of a 'params.json'.
)r   )r   r   r   r   r3   gguf_defaultc                 B    | vr                     | |i           dS dS )am  
            Apply GGUF defaults unless explicitly configured.

            This function reads/writes external `config` and `config_dict`.
            If the specified `key` is not in `config_dict` (i.e. not explicitly
            configured and the default HF value is used), it updates the
            corresponding `config` value to `gguf_default`.
            N)r  )r3   r!  r   r   s     r6   apply_gguf_defaultz&get_config.<locals>.apply_gguf_default  s5     +%%sL122222 &%r7   >   	qwen3_moenorm_topk_probTzCan't get gguf config for .architectureszModel config does not have a top-level 'architectures' field: expecting `hf_overrides={'architectures': ['...']}` to be passed in engine args.quantization_configzhf_quant_config.json	scale_fmt)ue8m0VLLM_USE_DEEP_GEMM_E8M01zGDetected quantization_config.scale_fmt=%s; enabling UE8M0 for DeepGEMM.zModel config requests UE8M0 (quantization_config.scale_fmt=%s), but VLLM_USE_DEEP_GEMM_E8M0=0 is set; UE8M0 for DeepGEMM disabled.zOverriding HF config with %ssub_configs)+r   r   r   r   r  r  r   r   MISTRAL_CONFIG_NAMEHF_CONFIG_NAMEr   errorr   	Exceptionformatr   r   r   r	   r   r   r   r  r'  r   r   r   r   r(  r   is_setosenviron	info_oncer+  warning_oncer  r   r   r   r   r1   (maybe_register_config_serialize_by_value)r   r   r   r   r   r  r  r   _is_gguf_is_remote_ggufr   r   r   error_messageconfig_parserr#  r   r(  r)  
SubConfigsr-  
sub_configr   r   s                         @@r6   
get_configr?  )  s    u~~H$U++O 	05!! 	0"&u++"2F;KK&EE 	0 )//HE1.	3 #5*=QQQ  ) ? 7J~8 8 8  !% ! )<~* * * P  W%%% ))) C    	3 	3 	3# f5f!!  ]++2	3 &m44M---+#$   K  7
	3C 
	3s 
	3 
	3 
	3 
	3 
	3 
	3 
	3 -- /666  7$EEEPF<MPPPQQQ6v7HI
5666  	;$777NN"    -V->?JMM?ZL9::: &//*?FF "':%x( (" 2"E8
 
 &%8"'++K>>	
"";899 8;
45  7     1 	##7
     '3_EEEo&&& )3_EEE (( &!!!&0022333 &6!67J%,V]D%I%IK ?% 	? 	?J!'&*"="=>>>> 30222Ms   9BD 
D:&D55D:mainc                    t          |           rt          |           \  } }d}d}t          | ||          rt          || |          }|dS t                              d           t          d |D             d          }t          t          d |D             d                    }|rdd	lm	}m
} d
                    |d                   }	t          |	| |          pi }
t                              d           d|i}|
                                D ]H\  }}|du r?t          |          }||v r||d<   "||v r||d<   ,t                              d||           I|S dS )a  
    This function gets the pooling and normalize
    config from the model - only applies to
    sentence-transformers models.

    Args:
        model: The name of the Hugging Face model.
        revision: The specific version of the model to use.
            Defaults to 'main'.

    Returns:
        A dictionary containing the pooling type and whether
            normalization is used, or None if no pooling configuration is found.
    modules.jsonN)r   config_namer   z2Found sentence-transformers modules configuration.c              3   2   K   | ]}|d          dk    |V  dS )r-   z$sentence_transformers.models.PoolingNr   r   items     r6   	<genexpr>z%get_pooling_config.<locals>.<genexpr>  s>       	
 	
F|EEE EEEE	
 	
r7   c              3   2   K   | ]}|d          dk    |V  dS )r-   z&sentence_transformers.models.NormalizeNr   rE  s     r6   rG  z%get_pooling_config.<locals>.<genexpr>  s>        <#KKK KKKK r7   Fr   )SEQ_POOLING_TYPESTOK_POOLING_TYPESz{}/config.jsonpathzFound pooling configuration.use_activationTseq_pooling_typetok_pooling_typezSkipping unrelated field: %r=%r)r   r   r   r   r   r   r   r   vllm.config.poolerrI  rJ  r2  r	  parse_pooling_typer  )r   r   r   modules_file_namemodules_dictpooling	normalizerI  rJ  pooling_file_namepooling_dictr   r3   valpooling_types                  r6   get_pooling_configrY    s   & e ,$U++q&L!2X   O ++<eXNNt
KKDEEE	
 	
$	
 	
 	

 	 G  (  
 	
 	
	 	I  KKKKKKKK,33GFODD*+<eXNNTRT2333"2I!>$**,, 	N 	NHCd{{1#66#4441=F-..!%6661=F-..LL!BCMMM4r7   pooling_namec                     d| v r|                      dd          } d| v r|                     dd          d         } d| v rd} |                                 S )Npooling_mode_ r   r   r   	lasttokenlast)replacesplitupper)rZ  s    r6   rP  rP  /  si    ,&&#++OR@@
l#))#q11!4l""r7   c                    g d}d|D ]*}t          | ||          	 t          || |          r n+sdt          |                                           sC	 t	          | |          }n# t
          $ r g }Y nw xY w|D ]}||v rt          || |          r nsdS t                              d           t          fddD                       rS dS )a  
    Returns the tokenization configuration dictionary for a
    given Sentence Transformer BERT model.

    Parameters:
    - model (str|Path): The name of the Sentence Transformer
    BERT model.
    - revision (str, optional): The revision of the m
    odel to use. Defaults to 'main'.

    Returns:
    - dict: A dictionary containing the configuration parameters
    for the Sentence Transformer BERT model.
    )zsentence_bert_config.jsonzsentence_roberta_config.jsonzsentence_distilbert_config.jsonzsentence_camembert_config.jsonzsentence_albert_config.jsonz sentence_xlm-roberta_config.jsonzsentence_xlnet_config.jsonN)r   	file_namer   r   z3Found sentence-transformers tokenize configuration.c              3       K   | ]}|v V  	d S Nr   )r   kencoder_dicts     r6   rG  z<get_sentence_transformer_tokenizer_config.<locals>.<genexpr>t  s(      
J
J1
J
J
J
J
J
Jr7   )max_seq_lengthdo_lower_case)	r!   r   r   is_absoluter    r1  r   r   all)r   r   !sentence_transformer_config_filesconfig_file
repo_filesrC  rh  s         @r6   )get_sentence_transformer_tokenizer_configrp  <  sP   $) ) )% L8  UkHUUU /{E8LLL  U 7 7 9 9 	(BBBJJ 	 	 	JJJ	 = 	 	Kj((2;xPP E t
KKEFFF

J
J
J
J&I
J
J
JJJ 4s   A+ +A:9A:c                     	 ddl } d}n# t          $ r d}Y nw xY w	 ddl}ddlddlddlm} d|ffd}|j                            ||           |r9	                    |            ddl
m} |r|j        	                    |            dS dS dS # t          $ r'}t                              d	|
           Y d}~dS d}~ww xY w)ab  Try to register HF model configuration class to serialize by value

    If trust_remote_code is set, and the model's config file specifies an
    `AutoConfig` class, then the config class is typically an instance of
    a custom class imported from the HF modules cache.

    Examples:

    >>> from transformers import AutoConfig
    >>> klass = AutoConfig.from_pretrained(
    ...     "meta-llama/Meta-Llama-3-8B", trust_remote_code=True
    ... )
    >>> klass.__class__  # transformers.models.llama.configuration_llama.LlamaConfig
    >>> import transformers_modules  # error, not initialized
    >>> klass = AutoConfig.from_pretrained(
    ...     "deepseek-ai/DeepSeek-V2.5", trust_remote_code=True
    ... )
    >>> import transformers_modules  # success, initialized
    >>> klass.__class__  # transformers_modules.deepseek-ai.DeepSeek-V2.5.98b11844770b2c3ffc18b175c758a803640f4e77.configuration_deepseek.DeepseekV2Config

    In the DeepSeek example, the config class is an instance of a custom
    class that is not serializable by default. This class will not be
    importable in spawned workers, and won't exist at all on
    other nodes, which breaks serialization of the config.

    In this function we tell the cloudpickle serialization library to pass
    instances of these generated classes by value instead of by reference,
    i.e. the class definition is serialized along with its data so that the
    class module does not need to be importable on the receiving end.

    See: https://github.com/cloudpipe/cloudpickle?tab=readme-ov-file#overriding-pickles-serialization-mechanism-for-importable-constructs
    r   NTF)
VllmConfigr   c                 >    j                             |           ffS rf  )loadsdumps)r   cloudpicklepickles    r6   _reduce_configz@maybe_register_config_serialize_by_value.<locals>._reduce_config  s!    L;#4#4V#<#<">??r7   )rayzUnable to register remote classes used by trust_remote_code with by-value serialization. This may lead to a later error. If remote code is not needed remove `--trust-remote-code`exc_info)transformers_modulesImportErrormultiprocessingrw  rv  vllm.configrr  reducerregisterregister_pickle_by_valuevllm.v1.executor.ray_utilsry  r1  r   r   )	r|  transformers_modules_availabler~  rr  rx  ry  r   rv  rw  s	          @@r6   r8  r8  y  s   B/####)-&& / / /).&&&/!
******
	@: 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	((^DDD * 	O001EFFF 766666 O889MNNNNN	O 	OO O  
 
 
,  	 	
 	
 	
 	
 	
 	
 	
 	
 	

s$    A/B 
CB??Chf_tokenc                     t           j        rt                      S t          |           rt	          |           j        } n!t          |           rt          |           \  } }t          | f||d|S )N)tokenr   )	r   VLLM_USE_MODELSCOPEr   r   r   r  r   r   r   )r   r  r   r   r   s        r6   get_hf_image_processor_configr    s      vvu ,U"			 ,$U++q% 4:  r7   c                 t    |                                  }|| urt          |d          st          d          |S )zaGet the "sub" config relevant to llm for multi modal models.
    No op for pure text models.
    num_attention_headszThe text_config extracted from the model config does not have `num_attention_heads` attribute. This indicates a mismatch between the model config and vLLM's expectations. Please ensure that the model config is compatible with vLLM.)r   r
  r   )r   ru   s     r6   get_hf_text_configr    sP     ((**K&  >S)T)T D
 
 	
 r7   c                     t          |           rd S 	 t          j        | |          S # t          $ r= 	 t	          | |||          }t          j        |          cY S # t          $ r Y Y d S w xY ww xY w)Nr   )r   r   r   )r   r   r   r   r?  from_model_config)r   r   r   r   r   s        r6   try_get_generation_configr    s     u~~ t/
 
 
 	
  
 
 
		"3!+	  F $5f===== 	 	 	444	
s,   ) 
A0&AA0
A,'A0+A,,A0r   c                t    t          t          | |          }	 t          |d          S # t          $ r Y d S w xY w)Nr   zError retrieving safetensors)r   r   r"   r1  )r   r    get_safetensors_metadata_partials      r6   try_get_safetensors_metadatar    sa    
 (/ %(( ( ($,.L
 
 	
    tts   ) 
77pretrained_model_name_or_pathc                 J    	 t          | ||          S # t          $ r Y d S w xY w)N)r   r   )r   r1  )r  r   r   s      r6   try_get_tokenizer_configr    sK    
#)/
 
 
 	

    tts    
""c                 r   	 t          d| |          }|sd S t          |t                    r|                    dg           }d |D             }|sd S g }|D ]O}|                    dd          }|r| dnd}t          || |          }|s5||d<   |                    |           P|S # t
          $ r Y d S w xY w)	NrB  modulesc                 D    g | ]}|                     d           dk    |S )r-   z"sentence_transformers.models.Dense)r   )r   ms     r6   r   z)try_get_dense_modules.<locals>.<listcomp>5  s4     
 
 
!%%--3W"W"WA"W"W"Wr7   rK  r]  z/config.jsonzconfig.jsonfolder)r   r*   r   r   appendr1  )	r   r   r  dense_moduleslayer_configsmoduler  config_pathlayer_configs	            r6   try_get_dense_modulesr  (  s   
%neXFF 	4gt$$ 	1kk)R00G
 

 
 
  	4# 	/ 	/FZZ++F5;NV1111K.{E8LLL %+L"  ....   tts   B( 9B( AB( (
B65B6c                   i }t          |           x}                                r"|                    d          }d |D             }n:t          | |          }|r'|j        x}rd |                                D             }|S )zC
    Get the safetensors metadata for remote model repository.
    z*.safetensorsc                     i | ]@}|                                 t          |                                          D ]\  }}||	AS r   )is_filer   r	  )r   	file_path
param_namer   s       r6   
<dictcomp>z3get_safetensors_params_metadata.<locals>.<dictcomp>U  sp     
 
 
  ""
 %DI$N$N$T$T$V$V	
 
 !
D 
 
 
 
r7   r   c                 l    i | ]1}|j                                         D ]\  }}|t          |          2S r   )tensorsr	  r   )r   file_mtr  r   s       r6   r  z3get_safetensors_params_metadata.<locals>.<dictcomp>^  sY       (/(=(=(?(?  %J F4LL   r7   )r   existsglobr  files_metadatar   )r   r   full_metadata
model_pathsafetensors_to_checkrepo_mtfiles_mts          r6   get_safetensors_params_metadatar  J  s     M5kk!
))++ )??
 
1
 
 
 /uxHHH 	G$:: 	 '00  M
 r7   c                     d}t          || |          }|t          d| d|  d          t          |t                    sJ |S )Nr&   zFailed to load mistral 'z' config for model zT. Please check if the model is a mistral-format model and if the config file exists.)r   r   r*   r   )r   r   config_file_namer   s       r6   r   r   f  st    $%&6xHHK.'7 . .. . .
 
 	

 k4(((((r7   c                     d}	 |                     dd          }t          | ||d          }|                                j        x}r|}n3# t          $ r&}t
                              d|           Y d }~nd }~ww xY w|S )Ni  r   Fr   )r   r   r   r   z|The params.json file is missing 'max_position_embeddings' and could not get a value from the HF config. Defaulting to 128000rz  )r   r?  r   r   r1  r   r   )r   r   r   r   trust_remote_code_val	hf_confighf_valuer   s           r6   r   r   s  s    %
 &

+> F F3	
 
 
	 !0022JJ8 	/&.# 
 
 
$ 	 	 	
 	
 	
 	
 	
 	
 	
 	

 #"s   AA 
A;A66A;r   r   )NNr   NN)r@  )r   N)Nr   rf  )mr4  collections.abcr   dataclassesr   	functoolsr   r   importlib.metadatar   pathlibr   typingr	   r
   r   r   r   packaging.versionr   r   r   r   .transformers.models.auto.image_processing_autor   &transformers.models.auto.modeling_autor   r   *transformers.models.auto.tokenization_autor   transformers.utilsr   r/  vllmr   vllm.loggerr   vllm.transformers_utils.utilsr   config_parser_baser   
gguf_utilsr   r   r   r   
repo_utilsr   r   r    r!   r"    transformers.configuration_utilsr#   r}  r$   r  
modelscoper%   r.  r8   r   r   r(   rs   r   r-   __annotations__rv   r}   r   r   r   r   r   ConfigFormatr   r   floatr   r   r   r   r   r   intr   r  r  r   r   r   r  r?  rY  rP  rp  r8  r  r  r  r  PathLiker  r   r  r  r   r   r   r7   r6   <module>r     s   
				 $ $ $ $ $ $       $ $ $ $ $ $ $ $ & & & & & &       * * * * * * * * * *     4 4 4 4 4 4 % % % % % % ; ; ; ; ; ; ; ; U U U U U U        L K K K K K < < < < < <       # # # # # # I I I I I I 0 0 0 0 0 0                        NNNNNNN            (%%%%%%%''''''# 	X		' ' ' ' 'T ' ' ' 7En 7 7 7
-7
-7 O7 ('	7
 $#7 7 ! 7 -7 #"7 N7 _7 z7 J7 
7 )(7  >!7" $##7$ -%7& $#'7( )7* -+7, 
-7. /70 _172 ! 374 ! 576 _778 97 $sD!1223   @ -) tCH~   
 064g>($/< < tCc3h$78   OtCH~ O$ O O O O@# @# @# @# @#% @# @# @#F0# 0# 0# 0# 0#* 0# 0# 0#h "F F c40@+A&A!B   
 <S <-= < < < <0# 0 0 0 0f=#3 =E =d = = = =1;"2 1;t 1; 1; 1; 1;hLS#X L4 L L L LD.( .T . . . .' D    
+/ 
+D 
+ 
+ 
+ 
+,     "X/ XD X X X X+     T#s(^     )9 >N      59;0 ;0;0Tz;0 ;0 Dj	;0
 "#s(^d2;0 3d
DcNT112;0 ;0 ;0 ;0B   $(.-1MQu u:uu Dju :	u
 %u #s(^d*u /02BBCdJu u u u up  "J JJDjJ 
#s(^dJ J J JZ
 S 
  
  
  
  .49 9:9!$t9 9 9 9xI
 I
 I
 I
\ #' :Sj4 Dj
 
#s(^   &/    (  (.	  Dj %	
    D     Dj   (   #&#4 Dj 
#s(^d	       :Dj 
$sCx.D    H     Dj 
#s(^	   8
d 
 
 
 
## # # # # # #s   B B*)B*