vllm.transformers_utils.config ¶
Functions:
-
get_config_parser–Get the config parser for a given config format.
-
get_hf_text_config–Get the "sub" config relevant to llm for multi modal models.
-
get_pooling_config–This function gets the pooling and normalize
-
get_safetensors_params_metadata–Get the safetensors parameters metadata for remote/local model repository.
-
get_sentence_transformer_tokenizer_config–Returns the tokenization configuration dictionary for a
-
is_encoder_decoder–Detect if the model with this config is used as an encoder/decoder.
-
is_interleaved–Detect if the model with this config is used with interleaved attention.
-
is_rope_parameters_nested–Check if rope_parameters is nested by layer types.
-
maybe_override_with_speculators–Resolve model configuration when speculators are detected.
-
maybe_register_config_serialize_by_value–Try to register HF model configuration class to serialize by value
-
patch_legacy_rope_type–Patch legacy RoPE type fields for backwards compatibility with
-
patch_rope_parameters–Provide backwards compatibility for RoPE.
-
register_config_parser–Register a customized vllm config parser.
-
set_default_rope_theta–Some models may have no rope_theta in their config but still use RoPE.
-
thinker_uses_mrope–Detect if the model contains a thinker config and it uses M-ROPE.
-
uses_mrope–Detect if the model with this config uses M-ROPE.
-
uses_xdrope_dim–Detect if the model with this config uses XD-ROPE.
_maybe_remap_hf_config_attrs(config) ¶
Remap config attributes to match the expected names.
Source code in vllm/transformers_utils/config.py
_maybe_update_auto_config_kwargs(kwargs, model_type) ¶
Update kwargs for AutoConfig initialization based on model_type
Source code in vllm/transformers_utils/config.py
_patch_hf_transformers_validate_rope() ¶
Transformers v5 moved the ignore_keys option from the method signature of validate_rope and replaced it with the ignore_keys_at_rope_validation parameter in the PreTrainedConfig class. This is a patch to make older versions of validate_rope() with the ignore_keys parameter work with newer versions of hf transformers (from v5 onwards)
Source code in vllm/transformers_utils/config.py
get_config_parser(config_format) ¶
Get the config parser for a given config format.
Source code in vllm/transformers_utils/config.py
get_hf_text_config(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(model, revision='main') cached ¶
This function gets the pooling and normalize config from the model - only applies to sentence-transformers models.
Parameters:
-
(model¶str) –The name of the Hugging Face model.
-
(revision¶str | None, default:'main') –The specific version of the model to use. Defaults to 'main'.
Returns:
-
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
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 | |
get_safetensors_params_metadata(model, *, revision=None) ¶
Get the safetensors parameters metadata for remote/local model repository.
Source code in vllm/transformers_utils/config.py
get_sentence_transformer_tokenizer_config(model, revision='main') cached ¶
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(config) ¶
Detect if the model with this config is used as an encoder/decoder.
Source code in vllm/transformers_utils/config.py
is_interleaved(config) ¶
Detect if the model with this config is used with interleaved attention.
Source code in vllm/transformers_utils/config.py
is_rope_parameters_nested(rope_parameters) ¶
Check if rope_parameters is nested by layer types.
Source code in vllm/transformers_utils/config.py
maybe_override_with_speculators(model, tokenizer, trust_remote_code, revision=None, vllm_speculative_config=None, hf_token=None, **kwargs) ¶
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:
-
(model¶str) –Model name or path
-
(tokenizer¶str | None) –Tokenizer name or path
-
(trust_remote_code¶bool) –Whether to trust remote code
-
(revision¶str | None, default:None) –Model revision
-
(vllm_speculative_config¶dict[str, Any] | None, default:None) –Existing vLLM speculative config
-
(hf_token¶bool | str | None, default:None) –HuggingFace token for authenticated model access
Returns:
-
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
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |
patch_legacy_rope_type(rope_parameters) ¶
Patch legacy RoPE type fields for backwards compatibility with older custom models which would otherwise fail to load.
Source code in vllm/transformers_utils/config.py
patch_rope_parameters(config) ¶
Provide backwards compatibility for RoPE.
Source code in vllm/transformers_utils/config.py
register_config_parser(config_format) ¶
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(config, default_theta) ¶
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(config) ¶
Detect if the model contains a thinker config and it uses M-ROPE.
Source code in vllm/transformers_utils/config.py
uses_mrope(config) ¶
Detect if the model with this config uses M-ROPE.
uses_xdrope_dim(config) ¶
Detect if the model with this config uses XD-ROPE.