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},
"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(
chatglm="ChatGLMConfig",
deepseek_vl_v2="DeepseekVLV2Config",
deepseek_v3="DeepseekV3Config",
deepseek_v32="DeepseekV3Config",
kimi_vl="KimiVLConfig",
Llama_Nemotron_Nano_VL="Nemotron_Nano_VL_Config",
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",
)
)
HFConfigParser ¶
Bases: ConfigParserBase
Source code in vllm/transformers_utils/config.py
parse ¶
parse(
model: Union[str, Path],
trust_remote_code: bool,
revision: Optional[str] = None,
code_revision: Optional[str] = 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: Union[str, Path],
trust_remote_code: bool,
revision: Optional[str] = None,
code_revision: Optional[str] = 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 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: Optional[str] = None,
revision: Optional[str] = None,
token: Union[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: Union[str, Path],
trust_remote_code: bool,
revision: Optional[str] = None,
code_revision: Optional[str] = None,
config_format: Union[str, ConfigFormat] = "auto",
hf_overrides_kw: Optional[dict[str, Any]] = None,
hf_overrides_fn: Optional[
Callable[[PretrainedConfig], PretrainedConfig]
] = None,
**kwargs,
) -> PretrainedConfig
Source code in vllm/transformers_utils/config.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
|
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: Union[str, Path],
revision: Optional[str] = "main",
) -> Optional[bytes]
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: Union[str, Path],
hf_token: Optional[Union[bool, str]] = None,
revision: Optional[str] = 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 | Optional[str] | The specific version of the model to use. Defaults to 'main'. | 'main' |
Returns:
Type | Description |
---|---|
Optional[dict] | 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
¶
get_sentence_transformer_tokenizer_config(
model: Union[str, Path],
revision: Optional[str] = "main",
)
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_repo_files cached
¶
list_repo_files(
repo_id: str,
*,
revision: Optional[str] = None,
repo_type: Optional[str] = None,
token: Union[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: Optional[str] = None,
vllm_speculative_config: Optional[
dict[str, Any]
] = None,
**kwargs,
) -> tuple[str, str, Optional[dict[str, Any]]]
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 | Optional[str] | Model revision | None |
vllm_speculative_config | Optional[dict[str, Any]] | Existing vLLM speculative config | None |
Returns:
Type | Description |
---|---|
tuple[str, str, Optional[dict[str, Any]]] | 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
patch_rope_scaling ¶
Provide backwards compatibility for RoPE.
Source code in vllm/transformers_utils/config.py
patch_rope_scaling_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: Optional[str] = None,
... code_revision: Optional[str] = None,
... **kwargs) -> tuple[dict, PretrainedConfig]:
... raise NotImplementedError
>>>
>>> type(get_config_parser("custom_config_parser"))
<class 'CustomConfigParser'>
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_generation_config ¶
try_get_generation_config(
model: str,
trust_remote_code: bool,
revision: Optional[str] = None,
config_format: Union[str, ConfigFormat] = "auto",
) -> Optional[GenerationConfig]
Source code in vllm/transformers_utils/config.py
try_get_local_file ¶
try_get_local_file(
model: Union[str, Path],
file_name: str,
revision: Optional[str] = "main",
) -> Optional[Path]
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: Union[str, PathLike],
trust_remote_code: bool,
revision: Optional[str] = None,
) -> Optional[dict[str, Any]]
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