[Chore] Separate out vllm.utils.importlib (#27022)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -27,7 +27,7 @@ from vllm.model_executor.model_loader.tensorizer import (
|
||||
from vllm.model_executor.model_loader.tensorizer_loader import (
|
||||
BLACKLISTED_TENSORIZER_ARGS,
|
||||
)
|
||||
from vllm.utils import PlaceholderModule
|
||||
from vllm.utils.import_utils import PlaceholderModule
|
||||
|
||||
from .conftest import DummyExecutor, assert_from_collective_rpc
|
||||
|
||||
|
||||
46
tests/utils_/test_import_utils.py
Normal file
46
tests/utils_/test_import_utils.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import pytest
|
||||
|
||||
from vllm.utils.import_utils import PlaceholderModule
|
||||
|
||||
|
||||
def _raises_module_not_found():
|
||||
return pytest.raises(ModuleNotFoundError, match="No module named")
|
||||
|
||||
|
||||
def test_placeholder_module_error_handling():
|
||||
placeholder = PlaceholderModule("placeholder_1234")
|
||||
|
||||
with _raises_module_not_found():
|
||||
int(placeholder)
|
||||
|
||||
with _raises_module_not_found():
|
||||
placeholder()
|
||||
|
||||
with _raises_module_not_found():
|
||||
_ = placeholder.some_attr
|
||||
|
||||
with _raises_module_not_found():
|
||||
# Test conflict with internal __name attribute
|
||||
_ = placeholder.name
|
||||
|
||||
# OK to print the placeholder or use it in a f-string
|
||||
_ = repr(placeholder)
|
||||
_ = str(placeholder)
|
||||
|
||||
# No error yet; only error when it is used downstream
|
||||
placeholder_attr = placeholder.placeholder_attr("attr")
|
||||
|
||||
with _raises_module_not_found():
|
||||
int(placeholder_attr)
|
||||
|
||||
with _raises_module_not_found():
|
||||
placeholder_attr()
|
||||
|
||||
with _raises_module_not_found():
|
||||
_ = placeholder_attr.some_attr
|
||||
|
||||
with _raises_module_not_found():
|
||||
# Test conflict with internal __module attribute
|
||||
_ = placeholder_attr.module
|
||||
@@ -24,7 +24,6 @@ from vllm.transformers_utils.detokenizer_utils import convert_ids_list_to_tokens
|
||||
from vllm.utils import (
|
||||
FlexibleArgumentParser,
|
||||
MemorySnapshot,
|
||||
PlaceholderModule,
|
||||
bind_kv_cache,
|
||||
common_broadcastable_dtype,
|
||||
current_stream,
|
||||
@@ -475,46 +474,6 @@ def test_common_broadcastable_dtype(dtypes, expected_result):
|
||||
assert common_broadcastable_dtype(dtypes) == expected_result
|
||||
|
||||
|
||||
def test_placeholder_module_error_handling():
|
||||
placeholder = PlaceholderModule("placeholder_1234")
|
||||
|
||||
def build_ctx():
|
||||
return pytest.raises(ModuleNotFoundError, match="No module named")
|
||||
|
||||
with build_ctx():
|
||||
int(placeholder)
|
||||
|
||||
with build_ctx():
|
||||
placeholder()
|
||||
|
||||
with build_ctx():
|
||||
_ = placeholder.some_attr
|
||||
|
||||
with build_ctx():
|
||||
# Test conflict with internal __name attribute
|
||||
_ = placeholder.name
|
||||
|
||||
# OK to print the placeholder or use it in a f-string
|
||||
_ = repr(placeholder)
|
||||
_ = str(placeholder)
|
||||
|
||||
# No error yet; only error when it is used downstream
|
||||
placeholder_attr = placeholder.placeholder_attr("attr")
|
||||
|
||||
with build_ctx():
|
||||
int(placeholder_attr)
|
||||
|
||||
with build_ctx():
|
||||
placeholder_attr()
|
||||
|
||||
with build_ctx():
|
||||
_ = placeholder_attr.some_attr
|
||||
|
||||
with build_ctx():
|
||||
# Test conflict with internal __module attribute
|
||||
_ = placeholder_attr.module
|
||||
|
||||
|
||||
def test_model_specification(
|
||||
parser_with_config, cli_config_file, cli_config_file_with_model
|
||||
):
|
||||
|
||||
@@ -20,7 +20,7 @@ from vllm.config import (
|
||||
VllmConfig,
|
||||
)
|
||||
from vllm.config.model import ModelDType
|
||||
from vllm.utils import resolve_obj_by_qualname
|
||||
from vllm.utils.import_utils import resolve_obj_by_qualname
|
||||
from vllm.v1.attention.backends.utils import (
|
||||
AttentionMetadataBuilder,
|
||||
CommonAttentionMetadata,
|
||||
|
||||
Reference in New Issue
Block a user