@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 8e13d9fe6d
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 14, 05:30 UTC

[Misc] Further clean up some redundant config definitions (#22649)

Signed-off-by: Isotr0py <2037008807@qq.com>

Isotr0py committed Aug 12, 2025 at 00:22 UTC 8e13d9fe6d486f3bfa096e28d683601d72a5a1cc
4 files changed +34 -85
vllm/transformers_utils/config.py
+33 -18
@@ -32,11 +32,10 @@ from vllm.logger import init_logger
32 from vllm.transformers_utils.configs import (ChatGLMConfig, DeepseekVLV2Config,
33 EAGLEConfig, JAISConfig,
34 KimiVLConfig, MedusaConfig,
35 - MllamaConfig, MLPSpeculatorConfig,
35 + MLPSpeculatorConfig,
36 Nemotron_Nano_VL_Config,
37 - NemotronConfig, NVLM_D_Config,
38 - OvisConfig, RWConfig,
39 - SpeculatorsConfig,
37 + NemotronConfig, OvisConfig,
38 + RWConfig, SpeculatorsConfig,
39 Step3TextConfig, Step3VLConfig,
40 UltravoxConfig)
41 # yapf: enable
@@ -68,10 +67,6 @@ def _get_hf_token() -> Optional[str]:
67 return None
68
69
71 -_CONFIG_REGISTRY_OVERRIDE_HF: dict[str, type[PretrainedConfig]] = {
72 - "mllama": MllamaConfig
73 -}
74 -
70 _CONFIG_REGISTRY: dict[str, type[PretrainedConfig]] = {
71 "chatglm": ChatGLMConfig,
72 "deepseek_vl_v2": DeepseekVLV2Config,
@@ -85,18 +80,30 @@ _CONFIG_REGISTRY: dict[str, type[PretrainedConfig]] = {
80 "eagle": EAGLEConfig,
81 "speculators": SpeculatorsConfig,
82 "nemotron": NemotronConfig,
88 - "NVLM_D": NVLM_D_Config,
83 "ovis": OvisConfig,
84 "ultravox": UltravoxConfig,
85 "step3_vl": Step3VLConfig,
86 "step3_text": Step3TextConfig,
93 - **_CONFIG_REGISTRY_OVERRIDE_HF
87 }
88
89 _CONFIG_ATTRS_MAPPING: dict[str, str] = {
90 "llm_config": "text_config",
91 }
92
93 +_AUTO_CONFIG_KWARGS_OVERRIDES: dict[str, dict[str, Any]] = {
94 + "internvl_chat": {
95 + "has_no_defaults_at_init": True
96 + },
97 + # transformers regards mllama as is_encoder_decoder=False
98 + # vllm needs is_encoder_decoder=True to enable cross-attention
99 + "mllama": {
100 + "is_encoder_decoder": True
101 + },
102 + "NVLM_D": {
103 + "has_no_defaults_at_init": True
104 + },
105 +}
106 +
107
108 class ConfigFormat(str, enum.Enum):
109 AUTO = "auto"
@@ -273,11 +280,12 @@ def thinker_uses_mrope(config: PretrainedConfig) -> bool:
280
281 def is_encoder_decoder(config: PretrainedConfig) -> bool:
282 """Detect if the model with this config is used as an encoder/decoder."""
276 - text_config = getattr(config, "text_config", None)
277 - if text_config is not None:
278 - return is_encoder_decoder(text_config)
283
280 - return getattr(config, "is_encoder_decoder", False)
284 + def _is_encoder_decoder(config: PretrainedConfig) -> bool:
285 + return getattr(config, "is_encoder_decoder", False)
286 +
287 + return (_is_encoder_decoder(config)
288 + or _is_encoder_decoder(config.get_text_config()))
289
290
291 def is_interleaved(config: PretrainedConfig) -> bool:
@@ -291,13 +299,21 @@ def is_interleaved(config: PretrainedConfig) -> bool:
299 return False
300
301
302 +def _maybe_update_auto_config_kwargs(kwargs: dict[str, Any], model_type: str):
303 + """
304 + Update kwargs for AutoConfig initialization based on model_type
305 + """
306 + if model_type in _AUTO_CONFIG_KWARGS_OVERRIDES:
307 + kwargs.update(_AUTO_CONFIG_KWARGS_OVERRIDES[model_type])
308 + return kwargs
309 +
310 +
311 def _maybe_remap_hf_config_attrs(config: PretrainedConfig) -> PretrainedConfig:
312 """Remap config attributes to match the expected names."""
313 for old_attr, new_attr in _CONFIG_ATTRS_MAPPING.items():
314 if hasattr(config, old_attr):
315 if not hasattr(config, new_attr):
316 config.update({new_attr: getattr(config, old_attr)})
300 - delattr(config, old_attr)
317 logger.debug("Remapped config attribute '%s' to '%s'", old_attr,
318 new_attr)
319 return config
@@ -408,15 +424,14 @@ def get_config(
424 )
425 else:
426 try:
427 + kwargs = _maybe_update_auto_config_kwargs(
428 + kwargs, model_type=model_type)
429 config = AutoConfig.from_pretrained(
430 model,
431 trust_remote_code=trust_remote_code,
432 revision=revision,
433 code_revision=code_revision,
434 token=_get_hf_token(),
417 - # some old custom model's config needs
418 - # `has_no_defaults_at_init=True` to work.
419 - has_no_defaults_at_init=trust_remote_code,
435 **kwargs,
436 )
437 except ValueError as e:
vllm/transformers_utils/configs/__init__.py
+1 -5
@@ -17,13 +17,11 @@ from vllm.transformers_utils.configs.falcon import RWConfig
17 from vllm.transformers_utils.configs.jais import JAISConfig
18 from vllm.transformers_utils.configs.kimi_vl import KimiVLConfig
19 from vllm.transformers_utils.configs.medusa import MedusaConfig
20 -from vllm.transformers_utils.configs.mllama import MllamaConfig
20 from vllm.transformers_utils.configs.mlp_speculator import MLPSpeculatorConfig
21 from vllm.transformers_utils.configs.moonvit import MoonViTConfig
22 from vllm.transformers_utils.configs.nemotron import NemotronConfig
23 from vllm.transformers_utils.configs.nemotron_h import NemotronHConfig
24 from vllm.transformers_utils.configs.nemotron_vl import Nemotron_Nano_VL_Config
26 -from vllm.transformers_utils.configs.nvlm_d import NVLM_D_Config
25 from vllm.transformers_utils.configs.ovis import OvisConfig
26 from vllm.transformers_utils.configs.speculators.base import SpeculatorsConfig
27 from vllm.transformers_utils.configs.step3_vl import (Step3TextConfig,
@@ -34,18 +32,16 @@ from vllm.transformers_utils.configs.ultravox import UltravoxConfig
32 __all__ = [
33 "ChatGLMConfig",
34 "DeepseekVLV2Config",
35 + "EAGLEConfig",
36 "RWConfig",
37 "JAISConfig",
38 "MedusaConfig",
40 - "EAGLEConfig",
41 - "MllamaConfig",
39 "MLPSpeculatorConfig",
40 "MoonViTConfig",
41 "KimiVLConfig",
42 "NemotronConfig",
43 "NemotronHConfig",
44 "Nemotron_Nano_VL_Config",
48 - "NVLM_D_Config",
45 "OvisConfig",
46 "SpeculatorsConfig",
47 "UltravoxConfig",
vllm/transformers_utils/configs/mllama.py deleted
-31
@@ -1,31 +0,0 @@
1 -# SPDX-License-Identifier: Apache-2.0
2 -# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 -
4 -from transformers.models.mllama import configuration_mllama as mllama_hf_config
5 -
6 -
7 -class MllamaTextConfig(mllama_hf_config.MllamaTextConfig):
8 - '''
9 - Use this class to override is_encoder_decoder:
10 - - transformers regards mllama as is_encoder_decoder=False
11 - - vllm needs is_encoder_decoder=True to enable cross-attention
12 - '''
13 -
14 - def __init__(
15 - self,
16 - **kwargs,
17 - ):
18 - super().__init__(**kwargs)
19 - self.is_encoder_decoder = True
20 -
21 -
22 -class MllamaConfig(mllama_hf_config.MllamaConfig):
23 -
24 - def __init__(
25 - self,
26 - text_config=None,
27 - **kwargs,
28 - ):
29 - if isinstance(text_config, dict):
30 - text_config = MllamaTextConfig(**text_config)
31 - super().__init__(text_config=text_config, **kwargs)
vllm/transformers_utils/configs/nvlm_d.py deleted
-31
@@ -1,31 +0,0 @@
1 -# SPDX-License-Identifier: Apache-2.0
2 -# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 -
4 -# Adapted from
5 -# https://huggingface.co/nvidia/NVLM-D-72B/blob/main/configuration_nvlm_d.py
6 -# --------------------------------------------------------
7 -# NVLM-D
8 -# Copyright (c) 2024 NVIDIA
9 -# Licensed under Apache 2.0 License [see LICENSE for details]
10 -# --------------------------------------------------------
11 -from transformers import Qwen2Config
12 -from transformers.configuration_utils import PretrainedConfig
13 -
14 -
15 -class NVLM_D_Config(PretrainedConfig):
16 - model_type = 'NVLM_D'
17 - is_composition = True
18 -
19 - def __init__(self, vision_config=None, llm_config=None, **kwargs):
20 - super().__init__(**kwargs)
21 -
22 - # Handle vision_config initialization
23 - if vision_config is None:
24 - vision_config = {}
25 -
26 - # Handle llm_config initialization
27 - if llm_config is None:
28 - llm_config = {}
29 -
30 - self.vision_config = PretrainedConfig(**vision_config)
31 - self.text_config = Qwen2Config(**llm_config)