From 5deb0073f0922cfce1d35930971a130fe68bd834 Mon Sep 17 00:00:00 2001 From: soaringk Date: Wed, 24 Jun 2026 11:36:12 +0800 Subject: [PATCH 1/2] Fix model info cache for package models Signed-off-by: soaringk --- tests/models/test_registry.py | 17 +++++++++++++++++ vllm/model_executor/models/registry.py | 22 ++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/models/test_registry.py b/tests/models/test_registry.py index 0715409abda6..b10a79e51e73 100644 --- a/tests/models/test_registry.py +++ b/tests/models/test_registry.py @@ -16,6 +16,7 @@ as_seq_cls_model, ) from vllm.model_executor.models.registry import ( + _LazyRegisteredModel, _MULTIMODAL_MODELS, _SPECULATIVE_DECODING_MODELS, _TEXT_GENERATION_MODELS, @@ -127,6 +128,22 @@ def test_registry_is_pp(model_arch, is_pp, init_cuda): ) +def test_lazy_modelinfo_package_hash_includes_submodules(tmp_path): + package_dir = tmp_path / "model_package" + package_dir.mkdir() + init_file = package_dir / "__init__.py" + init_file.write_text("from .model import Model\n", encoding="utf-8") + model_file = package_dir / "model.py" + model_file.write_text("class Model: pass\n", encoding="utf-8") + + first_hash = _LazyRegisteredModel._get_modelinfo_module_hash(init_file) + + model_file.write_text("class Model:\n supports_pp = True\n", encoding="utf-8") + second_hash = _LazyRegisteredModel._get_modelinfo_module_hash(init_file) + + assert first_hash != second_hash + + def test_hf_registry_coverage(): untested_archs = ( ModelRegistry.get_supported_archs() - HF_EXAMPLE_MODELS.get_supported_archs() diff --git a/vllm/model_executor/models/registry.py b/vllm/model_executor/models/registry.py index 5fb28b1c765a..c7c37f26cd92 100644 --- a/vllm/model_executor/models/registry.py +++ b/vllm/model_executor/models/registry.py @@ -845,6 +845,25 @@ def _get_cache_filename(self) -> str: cls_name = f"{self.module_name}-{self.class_name}".replace(".", "-") return f"{cls_name}.json" + @staticmethod + def _get_modelinfo_module_hash(model_path: Path) -> str: + if model_path.name == "__init__.py": + # Package entry points often re-export classes implemented in + # submodules, so include the package contents in the cache key. + module_paths = sorted(model_path.parent.rglob("*.py")) + root_path = model_path.parent + else: + module_paths = [model_path] + root_path = model_path.parent + + hasher = safe_hash(b"", usedforsecurity=False) + for path in module_paths: + hasher.update(path.relative_to(root_path).as_posix().encode("utf-8")) + hasher.update(b"\0") + hasher.update(path.read_bytes()) + hasher.update(b"\0") + return hasher.hexdigest() + def _load_modelinfo_from_cache(self, module_hash: str) -> _ModelInfo | None: try: try: @@ -911,8 +930,7 @@ def inspect_model_cls(self) -> _ModelInfo: module_hash = None if model_path is not None and model_path.exists(): - with open(model_path, "rb") as f: - module_hash = safe_hash(f.read(), usedforsecurity=False).hexdigest() + module_hash = self._get_modelinfo_module_hash(model_path) mi = self._load_modelinfo_from_cache(module_hash) if mi is not None: From 4f23ad446e20a24f14fb4a98e43b963cf0e006c5 Mon Sep 17 00:00:00 2001 From: soaringk Date: Mon, 29 Jun 2026 15:04:23 +0800 Subject: [PATCH 2/2] Fix registry test import ordering Signed-off-by: soaringk --- tests/models/test_registry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/models/test_registry.py b/tests/models/test_registry.py index b10a79e51e73..7e3ecb372e26 100644 --- a/tests/models/test_registry.py +++ b/tests/models/test_registry.py @@ -16,11 +16,11 @@ as_seq_cls_model, ) from vllm.model_executor.models.registry import ( - _LazyRegisteredModel, _MULTIMODAL_MODELS, _SPECULATIVE_DECODING_MODELS, _TEXT_GENERATION_MODELS, ModelRegistry, + _LazyRegisteredModel, ) from vllm.platforms import current_platform