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 5, 06:00 UTC
[Bug] Fix TypeError when hf_config.architectures is None during model loading (#38849)
[Bug] Fix TypeError when hf_config.architectures is None during model loading (#38849) Signed-off-by: Tihomir Elek <tiho.elek@gmail.com>
Tihomir Elek committed
Apr 13, 2026 at 13:13 UTC
8d825b87d6590ca971823890f9705988b8709add
3 files changed
+89
-2
tests/test_config.py
+77
@@ -4,12 +4,14 @@
4
import logging
5
import os
6
from dataclasses import MISSING, Field, asdict, dataclass, field
7
+from types import SimpleNamespace
8
from unittest.mock import patch
9
10
import pydantic
11
import pytest
12
from pydantic import ValidationError
13
14
+import vllm.config.vllm as vllm_config_module
15
from vllm.compilation.backends import VllmBackend
16
from vllm.config import (
17
CompilationConfig,
@@ -45,6 +47,81 @@ def test_compile_config_repr_succeeds():
47
assert "inductor_passes" in val
48
49
50
+@pytest.mark.skip_global_cleanup
51
+def test_with_hf_config_populates_missing_architectures_from_causal_lm_mapping(
52
+ monkeypatch,
53
+):
54
+ monkeypatch.setattr(
55
+ vllm_config_module,
56
+ "replace",
57
+ lambda self, **kwargs: SimpleNamespace(**kwargs),
58
+ )
59
+ cfg = SimpleNamespace(
60
+ model_config=SimpleNamespace(
61
+ is_multimodal_model=False,
62
+ hf_config=SimpleNamespace(),
63
+ get_model_arch_config=lambda: "arch-config",
64
+ )
65
+ )
66
+ hf_config = SimpleNamespace(model_type="mistral", architectures=None)
67
+
68
+ updated = VllmConfig.with_hf_config(cfg, hf_config)
69
+
70
+ assert updated.model_config.hf_config.architectures == ["MistralForCausalLM"]
71
+ assert hf_config.architectures is None
72
+
73
+
74
+@pytest.mark.skip_global_cleanup
75
+def test_with_hf_config_preserves_explicit_architectures_override(monkeypatch):
76
+ monkeypatch.setattr(
77
+ vllm_config_module,
78
+ "replace",
79
+ lambda self, **kwargs: SimpleNamespace(**kwargs),
80
+ )
81
+ cfg = SimpleNamespace(
82
+ model_config=SimpleNamespace(
83
+ is_multimodal_model=False,
84
+ hf_config=SimpleNamespace(),
85
+ get_model_arch_config=lambda: "arch-config",
86
+ )
87
+ )
88
+ hf_config = SimpleNamespace(model_type="mistral", architectures=None)
89
+
90
+ updated = VllmConfig.with_hf_config(
91
+ cfg,
92
+ hf_config,
93
+ architectures=["Ministral3ForCausalLM"],
94
+ )
95
+
96
+ assert updated.model_config.hf_config.architectures == ["Ministral3ForCausalLM"]
97
+
98
+
99
+@pytest.mark.skip_global_cleanup
100
+def test_with_hf_config_leaves_unknown_model_type_without_architectures(
101
+ monkeypatch,
102
+):
103
+ monkeypatch.setattr(
104
+ vllm_config_module,
105
+ "replace",
106
+ lambda self, **kwargs: SimpleNamespace(**kwargs),
107
+ )
108
+ cfg = SimpleNamespace(
109
+ model_config=SimpleNamespace(
110
+ is_multimodal_model=False,
111
+ hf_config=SimpleNamespace(),
112
+ get_model_arch_config=lambda: "arch-config",
113
+ )
114
+ )
115
+ hf_config = SimpleNamespace(
116
+ model_type="not_a_real_model",
117
+ architectures=None,
118
+ )
119
+
120
+ updated = VllmConfig.with_hf_config(cfg, hf_config)
121
+
122
+ assert updated.model_config.hf_config.architectures is None
123
+
124
+
125
def test_async_scheduling_with_pipeline_parallelism_is_allowed():
126
cfg = VllmConfig(
127
scheduler_config=SchedulerConfig(
vllm/config/vllm.py
+10
@@ -559,6 +559,16 @@ class VllmConfig:
559
if architectures is not None:
560
hf_config = copy.deepcopy(hf_config)
561
hf_config.architectures = architectures
562
+ elif hf_config.architectures is None:
563
+ from transformers.models.auto.modeling_auto import (
564
+ MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,
565
+ )
566
+
567
+ if hf_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES:
568
+ hf_config = copy.deepcopy(hf_config)
569
+ hf_config.architectures = [
570
+ MODEL_FOR_CAUSAL_LM_MAPPING_NAMES[hf_config.model_type]
571
+ ]
572
573
model_config = copy.deepcopy(self.model_config)
574
vllm/model_executor/model_loader/utils.py
+2
-2
@@ -175,7 +175,7 @@ _MODEL_ARCH_BY_HASH = dict[int, tuple[type[nn.Module], str]]()
175
def _get_model_architecture(model_config: ModelConfig) -> tuple[type[nn.Module], str]:
176
from vllm.model_executor.models.adapters import as_embedding_model, as_seq_cls_model
177
178
- architectures = getattr(model_config.hf_config, "architectures", [])
178
+ architectures = getattr(model_config.hf_config, "architectures", None) or []
179
180
model_cls, arch = model_config.registry.resolve_model_cls(
181
architectures,
@@ -215,7 +215,7 @@ def get_model_architecture(model_config: ModelConfig) -> tuple[type[nn.Module],
215
model_config.runner_type,
216
model_config.trust_remote_code,
217
model_config.model_impl,
218
- tuple(getattr(model_config.hf_config, "architectures", [])),
218
+ tuple(getattr(model_config.hf_config, "architectures", None) or []),
219
)
220
)
221
if key in _MODEL_ARCH_BY_HASH: