vllm.transformers_utils.config ¶
Functions:
-
checkpoint_has_lm_head–Whether the checkpoint contains an
lm_headtensor of its own. -
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_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
-
mrope_num_dims–Number of M-RoPE position channels the model consumes.
-
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.
_iter_rope_parameters(config) ¶
Yield a config's rope parameters, one dict per layer type if nested.
Source code in vllm/transformers_utils/config.py
_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
_mrope_section(config) ¶
Return the M-RoPE section this config declares, if any.
xdrope_section is the legacy name HunYuan-VL checkpoints use for the same field; upstream Transformers normalises it to mrope_section.
Source code in vllm/transformers_utils/config.py
_patch_hf_transformers_allowed_layer_types(extra_layer_types) ¶
Extend transformers' ALLOWED_LAYER_TYPES so its strict config validation accepts layer types (e.g. deepseek_sparse_attention) that a checkpoint declares but upstream transformers has not registered yet.
Source code in vllm/transformers_utils/config.py
_patch_hf_transformers_nested_rope_validation() ¶
Drop shared entries sitting alongside a nested rope_parameters dict.
Transformers validates a dict with any layer-type key by iterating all of its values, so a shared entry next to the per-layer dicts raises an AttributeError. The per-layer dicts already carry their own defaults by the time validation runs, so the shared entries can be dropped.
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
checkpoint_has_lm_head(model, *, revision=None) cached ¶
Whether the checkpoint contains an lm_head tensor of its own.
Parameters:
-
(model¶str) –Name or path of the model repository.
-
(revision¶str | None, default:None) –The specific model version to use.
Returns:
-
bool | None–Noneif the checkpoint contents could not be determined, for example -
bool | None–because it is not stored as safetensors.
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
936 937 938 939 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 1014 1015 1016 1017 1018 | |
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, default:'main') –The revision of the model 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_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
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 | |
mrope_num_dims(config) ¶
Number of M-RoPE position channels the model consumes.
Each section entry sizes one channel, so the section length is the channel count. Interleaved M-RoPE also accepts a 2 section variant whose positions are still 3D, so never return fewer than 3.
Source code in vllm/transformers_utils/config.py
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.
Parameters:
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.