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
-
get_sentence_transformers_chat_template_kwargs–Get the saved chat template settings of a Sentence Transformers
-
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.
-
iter_rope_parameters–Yield a config's rope parameters, one dict per layer type if nested.
-
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.
Attributes:
-
CONFIG_FIELD_ALIASES(dict[str, tuple[str, ...]]) –HF config fields that models spell differently, keyed by the name vLLM uses.
CONFIG_FIELD_ALIASES = {'total_num_kv_heads': ('n_head_kv', 'num_kv_heads', 'num_key_value_heads', 'multi_query_group_num', 'num_attention_groups'), 'num_experts': ('num_experts', 'moe_num_experts', 'n_routed_experts', 'num_local_experts'), 'num_experts_per_token': ('num_experts_per_tok', 'num_experts_per_token', 'top_k_experts', 'moe_topk', 'moe_top_k', 'top_k'), 'moe_intermediate_size': ('moe_intermediate_size', 'intermediate_size'), 'num_shared_experts': ('n_shared_experts', 'moe_num_shared_experts')}
module-attribute
¶
HF config fields that models spell differently, keyed by the name vLLM uses.
ModelArchConfigConvertorBase reads a scalar from these; a caller that needs the
raw value (a per-layer list, say) passes the aliases to getattr_iter itself.
_install_hf_config_validator(name, validator, supersedes)
¶
Replace a PreTrainedConfig validator on every @strict snapshot.
@strict snapshots each validate_* method into __class_validators__
at class creation and automatic post-__init__ validation dispatches off
that frozen list, so assigning the class attribute alone only affects
explicit config.validate_*() calls. Every @strict-decorated config
class owns a snapshot, so rewrite them all, matching supersedes by
identity to leave a genuine per-model override in place.
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_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
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
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 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 | |
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
get_sentence_transformers_chat_template_kwargs(model, revision=None)
cached
¶
Get the saved chat template settings of a Sentence Transformers
CrossEncoder whose single Transformer module declares the message
modality.
Sentence Transformers formats the pairs of such checkpoints as
query/document messages with the saved chat template.
Parameters:
-
(model¶str | Path) –Local checkpoint path or Hugging Face model ID.
-
(revision¶str | None, default:None) –Model revision to inspect.
Returns:
-
dict[str, Any] | None–The saved
processing_kwargs.chat_template(possibly empty), or -
dict[str, Any] | None–Noneif the checkpoint does not declare themessagemodality.
Raises:
-
ValueError–If the saved chat template settings are unsupported.
Source code in vllm/transformers_utils/config.py
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 | |
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
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_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
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 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 | |
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
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 | |
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.