[Bugfix] Restore model info caching for package backends (#52690)
Signed-off-by: haoyang.qian <haoyangqian@gmail.com> Co-authored-by: OpenAI Codex <codex@openai.com>
hy123 committed
Aug 19, 2026 at 19:18 UTC
b160cab156106b212ee67beb16c9725d366b8857
2 files changed
+32
-1
tests/models/test_registry.py
+30
@@ -173,6 +173,36 @@ def test_lazy_modelinfo_package_hash_includes_submodules(tmp_path):
173
assert first_hash != second_hash
174
175
176
+def test_lazy_modelinfo_package_attempts_cache_load(monkeypatch):
177
+ cached_model_info = object()
178
+ loaded_hashes = []
179
+
180
+ def fake_load_cache(self, module_hash):
181
+ loaded_hashes.append(module_hash)
182
+ return cached_model_info
183
+
184
+ monkeypatch.setattr(
185
+ _LazyRegisteredModel,
186
+ "_load_modelinfo_from_cache",
187
+ fake_load_cache,
188
+ )
189
+ monkeypatch.setattr(
190
+ "vllm.model_executor.models.registry._run_in_subprocess",
191
+ lambda _: pytest.fail("Package-backed model should use the cache path"),
192
+ )
193
+
194
+ registered_model = _LazyRegisteredModel(
195
+ module_name="vllm.model_executor.models.transformers",
196
+ class_name="TransformersForCausalLM",
197
+ )
198
+
199
+ result = registered_model.inspect_model_cls()
200
+
201
+ assert result is cached_model_info
202
+ assert len(loaded_hashes) == 1
203
+ assert loaded_hashes[0]
204
+
205
+
206
def test_hf_registry_coverage():
207
untested_archs = (
208
ModelRegistry.get_supported_archs() - HF_EXAMPLE_MODELS.get_supported_archs()
vllm/model_executor/models/registry.py
+2
-1
@@ -1004,9 +1004,10 @@ class _LazyRegisteredModel(_BaseRegisteredModel):
1004
# hardware-isolated ``vllm.models.<name>`` layout) live outside
1005
# ``vllm/model_executor/models``. Resolve the module spec directly
1006
# so the file-hash cache stays warm for them.
1007
+ model_path: Path | None = None
1008
if self.module_name.startswith("vllm.model_executor.models."):
1009
model_path = Path(__file__).parent / f"{self.module_name.split('.')[-1]}.py"
1009
- else:
1010
+ if model_path is None or not model_path.exists():
1011
try:
1012
spec = importlib.util.find_spec(self.module_name)
1013
except (ImportError, ValueError):