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.
_maybe_remap_hf_config_attrs(config)
¶
Remap config attributes to match the expected names.
_maybe_update_auto_config_kwargs(kwargs, model_type)
¶
Update kwargs for AutoConfig initialization based on model_type.
_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.
_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.
checkpoint_has_lm_head(model, *, revision=None)
cached
¶
get_config_parser(config_format)
¶
Get the config parser for a given config format.
get_hf_text_config(config)
¶
Get the "sub" config relevant to llm for multi modal models. No op for pure text models.
get_pooling_config(model, revision='main')
cached
¶
get_safetensors_params_metadata(model, *, revision=None)
¶
Get the safetensors parameters metadata for remote/local model repository.
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.
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.
is_encoder_decoder(config)
¶
Detect if the model with this config is used as an encoder/decoder.
is_rope_parameters_nested(rope_parameters)
¶
Check if rope_parameters is nested by layer types.
iter_rope_parameters(config)
¶
Yield a config's rope parameters, one dict per layer type if nested.
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:
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
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.
patch_legacy_rope_type(rope_parameters)
¶
Patch legacy RoPE type fields for backwards compatibility with older custom models which would otherwise fail to load.
patch_rope_parameters(config)
¶
Provide backwards compatibility for RoPE.
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'>
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.
thinker_uses_mrope(config)
¶
Detect if the model contains a thinker config and it uses M-ROPE.
uses_mrope(config)
¶
Detect if the model with this config uses M-ROPE.