[Feat] Support Pipeline Resolution Based on HF Config & Make Pipeline Registry Eager (#3760)
Signed-off-by: Alex Brooks <albrooks@redhat.com>
This commit is contained in:
1 parent
f6894f4308
commit
465f1464d2
44 files changed
+1038
-1126
No files matched your search
@@ -1,76 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Unit tests for GLM-Image model __init__.py lazy import pattern.
|
||||
|
||||
The ``__init__.py`` uses ``__getattr__`` for lazy loading to avoid importing
|
||||
``transformers.models.glm_image`` at module init, which may not be available
|
||||
in all environments.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
class TestLazyImport:
|
||||
"""Test the __getattr__ lazy import pattern in glm_image __init__.py."""
|
||||
|
||||
def test_getattr_exists_and_is_callable(self):
|
||||
"""Verify __getattr__ exists and is callable."""
|
||||
import vllm_omni.model_executor.models.glm_image as glm_image_pkg
|
||||
|
||||
assert hasattr(glm_image_pkg, "__getattr__")
|
||||
assert callable(glm_image_pkg.__getattr__)
|
||||
|
||||
def test_getattr_returns_class_for_known_attribute(self):
|
||||
"""Verify __getattr__ returns GlmImageForConditionalGeneration for known attribute."""
|
||||
import vllm_omni.model_executor.models.glm_image as glm_image_pkg
|
||||
|
||||
# Call __getattr__ directly to test the lazy import logic
|
||||
result = glm_image_pkg.__getattr__("GlmImageForConditionalGeneration")
|
||||
|
||||
# Verify we get a class (the actual GlmImageForConditionalGeneration)
|
||||
assert result is not None
|
||||
assert isinstance(result, type)
|
||||
assert result.__name__ == "GlmImageForConditionalGeneration"
|
||||
|
||||
def test_getattr_raises_for_unknown_attribute(self):
|
||||
"""Verify __getattr__ raises AttributeError for unknown attributes."""
|
||||
import vllm_omni.model_executor.models.glm_image as glm_image_pkg
|
||||
|
||||
# Test unknown attribute via __getattr__ directly
|
||||
with pytest.raises(AttributeError, match="has no attribute"):
|
||||
glm_image_pkg.__getattr__("UnknownClass")
|
||||
|
||||
def test___all___exports_correct_symbols(self):
|
||||
"""Verify __all__ contains the expected exported symbols."""
|
||||
import vllm_omni.model_executor.models.glm_image as glm_image_pkg
|
||||
|
||||
assert hasattr(glm_image_pkg, "__all__")
|
||||
assert "GlmImageForConditionalGeneration" in glm_image_pkg.__all__
|
||||
|
||||
|
||||
class TestLazyImportDoesNotImportTransformersAtInit:
|
||||
"""Verify that importing the package does not eagerly load transformers."""
|
||||
|
||||
def test_glm_image_module_has_getattr(self):
|
||||
"""Test that the module has __getattr__ for lazy loading."""
|
||||
import vllm_omni.model_executor.models.glm_image as glm_image_pkg
|
||||
|
||||
# The module should have __getattr__
|
||||
assert hasattr(glm_image_pkg, "__getattr__")
|
||||
assert callable(glm_image_pkg.__getattr__)
|
||||
|
||||
# And __all__
|
||||
assert hasattr(glm_image_pkg, "__all__")
|
||||
|
||||
def test_module_has_proper_structure(self):
|
||||
"""Test that the module has proper Python module structure."""
|
||||
import vllm_omni.model_executor.models.glm_image as glm_image_pkg
|
||||
|
||||
# Should be a module
|
||||
assert hasattr(glm_image_pkg, "__name__")
|
||||
assert glm_image_pkg.__name__ == "vllm_omni.model_executor.models.glm_image"
|
||||
|
||||
# Should have __file__ (even if it's a package)
|
||||
assert hasattr(glm_image_pkg, "__file__")
|
||||
@@ -19,9 +19,8 @@ from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.config.pipeline_registry import _OMNI_PIPELINES
|
||||
from vllm_omni.config.pipeline_registry import OMNI_PIPELINES
|
||||
from vllm_omni.config.stage_config import (
|
||||
_PIPELINE_REGISTRY,
|
||||
PipelineConfig,
|
||||
StageExecutionType,
|
||||
)
|
||||
@@ -34,13 +33,13 @@ _PIPELINE_KEY = "minicpmo_4_5"
|
||||
|
||||
class TestRegistryDeclaration:
|
||||
def test_declared_in_omni_pipelines(self) -> None:
|
||||
assert _PIPELINE_KEY in _OMNI_PIPELINES
|
||||
assert _PIPELINE_KEY in OMNI_PIPELINES
|
||||
|
||||
def test_visible_in_central_registry(self) -> None:
|
||||
assert _PIPELINE_KEY in _PIPELINE_REGISTRY
|
||||
assert _PIPELINE_KEY in OMNI_PIPELINES
|
||||
|
||||
def test_lazy_load_returns_pipeline_config(self) -> None:
|
||||
pipeline = _PIPELINE_REGISTRY[_PIPELINE_KEY]
|
||||
pipeline = OMNI_PIPELINES[_PIPELINE_KEY]
|
||||
assert isinstance(pipeline, PipelineConfig)
|
||||
assert pipeline.model_type == _PIPELINE_KEY
|
||||
assert pipeline.model_arch == "MiniCPMO45OmniForConditionalGeneration"
|
||||
@@ -49,7 +48,7 @@ class TestRegistryDeclaration:
|
||||
class TestPipelineTopology:
|
||||
@pytest.fixture(scope="class")
|
||||
def pipeline(self) -> PipelineConfig:
|
||||
return _PIPELINE_REGISTRY[_PIPELINE_KEY]
|
||||
return OMNI_PIPELINES[_PIPELINE_KEY]
|
||||
|
||||
def test_two_stages(self, pipeline: PipelineConfig) -> None:
|
||||
assert len(pipeline.stages) == 2
|
||||
@@ -99,7 +98,7 @@ class TestArchAliases:
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def pipeline(self) -> PipelineConfig:
|
||||
return _PIPELINE_REGISTRY[_PIPELINE_KEY]
|
||||
return OMNI_PIPELINES[_PIPELINE_KEY]
|
||||
|
||||
def test_shared_minicpmo_alias_present(self, pipeline: PipelineConfig) -> None:
|
||||
# MiniCPM-o 4.5 ships ``architectures=["MiniCPMO"]`` in its HF config.
|
||||
@@ -123,7 +122,7 @@ class TestHfConfigPredicate:
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def predicate(self):
|
||||
pipeline = _PIPELINE_REGISTRY[_PIPELINE_KEY]
|
||||
pipeline = OMNI_PIPELINES[_PIPELINE_KEY]
|
||||
assert pipeline.hf_config_predicate is not None, (
|
||||
"MiniCPM-o 4.5 pipeline must declare hf_config_predicate to "
|
||||
"avoid misrouting MiniCPM-o 2.6 checkpoints into the 4.5 path."
|
||||
|
||||
Reference in new issue
Block a user