vllm.transformers_utils.config ¶
_maybe_remap_hf_config_attrs ¶
Remap config attributes to match the expected names.
Source code in vllm/transformers_utils/config.py
_maybe_update_auto_config_kwargs ¶
Update kwargs for AutoConfig initialization based on model_type
Source code in vllm/transformers_utils/config.py
get_config_parser ¶
get_config_parser(config_format: str) -> ConfigParserBase
Get the config parser for a given config format.
Source code in vllm/transformers_utils/config.py
get_hf_text_config ¶
Get the "sub" config relevant to llm for multi modal models. No op for pure text models.
Source code in vllm/transformers_utils/config.py
get_pooling_config cached ¶
This function gets the pooling and normalize config from the model - only applies to sentence-transformers models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model | str | The name of the Hugging Face model. | required |
revision | str | None | The specific version of the model to use. Defaults to 'main'. | 'main' |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None | A dictionary containing the pooling type and whether normalization is used, or None if no pooling configuration is found. |
Source code in vllm/transformers_utils/config.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 | |
get_safetensors_params_metadata ¶
Get the safetensors parameters metadata for remote/local model repository.
Source code in vllm/transformers_utils/config.py
get_sentence_transformer_tokenizer_config cached ¶
get_sentence_transformer_tokenizer_config(
model: str | Path, revision: str | None = "main"
) -> dict[str, Any] | None
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.
Source code in vllm/transformers_utils/config.py
is_encoder_decoder ¶
is_encoder_decoder(config: PretrainedConfig) -> bool
Detect if the model with this config is used as an encoder/decoder.
Source code in vllm/transformers_utils/config.py
is_interleaved ¶
is_interleaved(config: PretrainedConfig) -> bool
Detect if the model with this config is used with interleaved attention.
Source code in vllm/transformers_utils/config.py
is_rope_parameters_nested ¶
Check if rope_parameters is nested by layer types.
Source code in vllm/transformers_utils/config.py
maybe_override_with_speculators ¶
maybe_override_with_speculators(
model: str,
tokenizer: str | None,
trust_remote_code: bool,
revision: str | None = None,
vllm_speculative_config: dict[str, Any] | None = None,
**kwargs,
) -> tuple[str, str | None, dict[str, Any] | None]
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model | str | Model name or path | required |
tokenizer | str | None | Tokenizer name or path | required |
trust_remote_code | bool | Whether to trust remote code | required |
revision | str | None | Model revision | None |
vllm_speculative_config | dict[str, Any] | None | Existing vLLM speculative config | None |
Returns:
| Type | Description |
|---|---|
tuple[str, str | None, dict[str, Any] | None] | Tuple of (resolved_model, resolved_tokenizer, speculative_config) |
Source code in vllm/transformers_utils/config.py
maybe_register_config_serialize_by_value ¶
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
Source code in vllm/transformers_utils/config.py
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | |
patch_rope_parameters ¶
Provide backwards compatibility for RoPE.
Source code in vllm/transformers_utils/config.py
register_config_parser ¶
register_config_parser(config_format: str)
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'>
Source code in vllm/transformers_utils/config.py
set_default_rope_theta ¶
set_default_rope_theta(
config: PretrainedConfig, default_theta: float
) -> None
Some models may have no rope_theta in their config but still use RoPE. This function sets a default rope_theta if it's missing.
Source code in vllm/transformers_utils/config.py
thinker_uses_mrope ¶
thinker_uses_mrope(config: PretrainedConfig) -> bool
Detect if the model contains a thinker config and it uses M-ROPE.
Source code in vllm/transformers_utils/config.py
uses_mrope ¶
uses_mrope(config: PretrainedConfig) -> bool
Detect if the model with this config uses M-ROPE.
uses_xdrope_dim ¶
uses_xdrope_dim(config: PretrainedConfig) -> int
Detect if the model with this config uses XD-ROPE.