Skip to content

Commit 4d4d6ba

Browse files
[Chore] Separate out vllm.utils.importlib (#27022)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
1 parent 11ae016 commit 4d4d6ba

File tree

41 files changed

+417
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+417
-391
lines changed

tests/model_executor/model_loader/tensorizer_loader/test_tensorizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from vllm.model_executor.model_loader.tensorizer_loader import (
2828
BLACKLISTED_TENSORIZER_ARGS,
2929
)
30-
from vllm.utils import PlaceholderModule
30+
from vllm.utils.import_utils import PlaceholderModule
3131

3232
from .conftest import DummyExecutor, assert_from_collective_rpc
3333

tests/utils_/test_import_utils.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3+
import pytest
4+
5+
from vllm.utils.import_utils import PlaceholderModule
6+
7+
8+
def _raises_module_not_found():
9+
return pytest.raises(ModuleNotFoundError, match="No module named")
10+
11+
12+
def test_placeholder_module_error_handling():
13+
placeholder = PlaceholderModule("placeholder_1234")
14+
15+
with _raises_module_not_found():
16+
int(placeholder)
17+
18+
with _raises_module_not_found():
19+
placeholder()
20+
21+
with _raises_module_not_found():
22+
_ = placeholder.some_attr
23+
24+
with _raises_module_not_found():
25+
# Test conflict with internal __name attribute
26+
_ = placeholder.name
27+
28+
# OK to print the placeholder or use it in a f-string
29+
_ = repr(placeholder)
30+
_ = str(placeholder)
31+
32+
# No error yet; only error when it is used downstream
33+
placeholder_attr = placeholder.placeholder_attr("attr")
34+
35+
with _raises_module_not_found():
36+
int(placeholder_attr)
37+
38+
with _raises_module_not_found():
39+
placeholder_attr()
40+
41+
with _raises_module_not_found():
42+
_ = placeholder_attr.some_attr
43+
44+
with _raises_module_not_found():
45+
# Test conflict with internal __module attribute
46+
_ = placeholder_attr.module

tests/utils_/test_utils.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from vllm.utils import (
2525
FlexibleArgumentParser,
2626
MemorySnapshot,
27-
PlaceholderModule,
2827
bind_kv_cache,
2928
common_broadcastable_dtype,
3029
current_stream,
@@ -475,46 +474,6 @@ def test_common_broadcastable_dtype(dtypes, expected_result):
475474
assert common_broadcastable_dtype(dtypes) == expected_result
476475

477476

478-
def test_placeholder_module_error_handling():
479-
placeholder = PlaceholderModule("placeholder_1234")
480-
481-
def build_ctx():
482-
return pytest.raises(ModuleNotFoundError, match="No module named")
483-
484-
with build_ctx():
485-
int(placeholder)
486-
487-
with build_ctx():
488-
placeholder()
489-
490-
with build_ctx():
491-
_ = placeholder.some_attr
492-
493-
with build_ctx():
494-
# Test conflict with internal __name attribute
495-
_ = placeholder.name
496-
497-
# OK to print the placeholder or use it in a f-string
498-
_ = repr(placeholder)
499-
_ = str(placeholder)
500-
501-
# No error yet; only error when it is used downstream
502-
placeholder_attr = placeholder.placeholder_attr("attr")
503-
504-
with build_ctx():
505-
int(placeholder_attr)
506-
507-
with build_ctx():
508-
placeholder_attr()
509-
510-
with build_ctx():
511-
_ = placeholder_attr.some_attr
512-
513-
with build_ctx():
514-
# Test conflict with internal __module attribute
515-
_ = placeholder_attr.module
516-
517-
518477
def test_model_specification(
519478
parser_with_config, cli_config_file, cli_config_file_with_model
520479
):

tests/v1/attention/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
VllmConfig,
2121
)
2222
from vllm.config.model import ModelDType
23-
from vllm.utils import resolve_obj_by_qualname
23+
from vllm.utils.import_utils import resolve_obj_by_qualname
2424
from vllm.v1.attention.backends.utils import (
2525
AttentionMetadataBuilder,
2626
CommonAttentionMetadata,

vllm/assets/audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import numpy.typing as npt
1010

11-
from vllm.utils import PlaceholderModule
11+
from vllm.utils.import_utils import PlaceholderModule
1212

1313
from .base import VLLM_S3_BUCKET_URL, get_vllm_public_assets
1414

vllm/assets/video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from huggingface_hub import hf_hub_download
1111
from PIL import Image
1212

13-
from vllm.utils import PlaceholderModule
13+
from vllm.utils.import_utils import PlaceholderModule
1414

1515
from .base import get_cache_dir
1616

vllm/attention/backends/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import enum
66

7-
from vllm.utils import resolve_obj_by_qualname
7+
from vllm.utils.import_utils import resolve_obj_by_qualname
88

99

1010
class _Backend(enum.Enum):

vllm/attention/selector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from vllm.attention.backends.abstract import AttentionBackend
1414
from vllm.attention.backends.registry import _Backend, backend_name_to_enum
1515
from vllm.logger import init_logger
16-
from vllm.utils import STR_BACKEND_ENV_VAR, resolve_obj_by_qualname
16+
from vllm.utils import STR_BACKEND_ENV_VAR
17+
from vllm.utils.import_utils import resolve_obj_by_qualname
1718

1819
logger = init_logger(__name__)
1920

vllm/benchmarks/datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from vllm.multimodal import MultiModalDataDict
4040
from vllm.multimodal.image import convert_image_mode
4141
from vllm.transformers_utils.tokenizer import AnyTokenizer
42-
from vllm.utils import PlaceholderModule
42+
from vllm.utils.import_utils import PlaceholderModule
4343

4444
try:
4545
from datasets import load_dataset

vllm/compilation/backends.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
from vllm.config import CompilationConfig, CUDAGraphMode, VllmConfig
2525
from vllm.logger import init_logger
2626
from vllm.platforms import current_platform
27-
from vllm.utils import is_torch_equal_or_newer, resolve_obj_by_qualname
27+
from vllm.utils import is_torch_equal_or_newer
28+
from vllm.utils.import_utils import resolve_obj_by_qualname
2829

2930
from .caching import VllmSerializableFunction
3031
from .compiler_interface import (

0 commit comments

Comments
 (0)