Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from vllm.model_executor.model_loader.tensorizer_loader import (
BLACKLISTED_TENSORIZER_ARGS,
)
from vllm.utils import PlaceholderModule
from vllm.utils.importlib import PlaceholderModule

from .conftest import DummyExecutor, assert_from_collective_rpc

Expand Down
46 changes: 46 additions & 0 deletions tests/utils_/test_importlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest

from vllm.utils.importlib 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
41 changes: 0 additions & 41 deletions tests/utils_/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from vllm.utils import (
FlexibleArgumentParser,
MemorySnapshot,
PlaceholderModule,
bind_kv_cache,
common_broadcastable_dtype,
current_stream,
Expand Down Expand Up @@ -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
):
Expand Down
2 changes: 1 addition & 1 deletion tests/v1/attention/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
VllmConfig,
)
from vllm.config.model import ModelDType
from vllm.utils import resolve_obj_by_qualname
from vllm.utils.importlib import resolve_obj_by_qualname
from vllm.v1.attention.backends.utils import (
AttentionMetadataBuilder,
CommonAttentionMetadata,
Expand Down
2 changes: 1 addition & 1 deletion vllm/assets/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy.typing as npt

from vllm.utils import PlaceholderModule
from vllm.utils.importlib import PlaceholderModule

from .base import VLLM_S3_BUCKET_URL, get_vllm_public_assets

Expand Down
2 changes: 1 addition & 1 deletion vllm/assets/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from huggingface_hub import hf_hub_download
from PIL import Image

from vllm.utils import PlaceholderModule
from vllm.utils.importlib import PlaceholderModule

from .base import get_cache_dir

Expand Down
2 changes: 1 addition & 1 deletion vllm/attention/backends/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import enum

from vllm.utils import resolve_obj_by_qualname
from vllm.utils.importlib import resolve_obj_by_qualname


class _Backend(enum.Enum):
Expand Down
3 changes: 2 additions & 1 deletion vllm/attention/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from vllm.attention.backends.abstract import AttentionBackend
from vllm.attention.backends.registry import _Backend, backend_name_to_enum
from vllm.logger import init_logger
from vllm.utils import STR_BACKEND_ENV_VAR, resolve_obj_by_qualname
from vllm.utils import STR_BACKEND_ENV_VAR
from vllm.utils.importlib import resolve_obj_by_qualname

logger = init_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion vllm/benchmarks/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from vllm.multimodal import MultiModalDataDict
from vllm.multimodal.image import convert_image_mode
from vllm.transformers_utils.tokenizer import AnyTokenizer
from vllm.utils import PlaceholderModule
from vllm.utils.importlib import PlaceholderModule

try:
from datasets import load_dataset
Expand Down
3 changes: 2 additions & 1 deletion vllm/compilation/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from vllm.config import CompilationConfig, CUDAGraphMode, VllmConfig
from vllm.logger import init_logger
from vllm.platforms import current_platform
from vllm.utils import is_torch_equal_or_newer, resolve_obj_by_qualname
from vllm.utils import is_torch_equal_or_newer
from vllm.utils.importlib import resolve_obj_by_qualname

from .caching import VllmSerializableFunction
from .compiler_interface import (
Expand Down
3 changes: 2 additions & 1 deletion vllm/compilation/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from vllm.config import CompilationMode, VllmConfig, set_current_vllm_config
from vllm.logger import init_logger
from vllm.sequence import IntermediateTensors
from vllm.utils import resolve_obj_by_qualname, supports_dynamo
from vllm.utils import supports_dynamo
from vllm.utils.importlib import resolve_obj_by_qualname

from .monitor import start_monitoring_torch_compile

Expand Down
3 changes: 2 additions & 1 deletion vllm/config/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from vllm.config.utils import config
from vllm.logger import init_logger
from vllm.platforms import current_platform
from vllm.utils import is_torch_equal_or_newer, resolve_obj_by_qualname
from vllm.utils import is_torch_equal_or_newer
from vllm.utils.importlib import resolve_obj_by_qualname

if TYPE_CHECKING:
from vllm.config import VllmConfig
Expand Down
3 changes: 2 additions & 1 deletion vllm/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
)
from vllm.transformers_utils.runai_utils import ObjectStorageModel, is_runai_obj_uri
from vllm.transformers_utils.utils import maybe_model_redirect
from vllm.utils import LayerBlockType, LazyLoader, common_broadcastable_dtype
from vllm.utils import LayerBlockType, common_broadcastable_dtype
from vllm.utils.importlib import LazyLoader

if TYPE_CHECKING:
from transformers import PretrainedConfig
Expand Down
2 changes: 1 addition & 1 deletion vllm/config/speculative.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from vllm.config.parallel import ParallelConfig
from vllm.config.utils import config
from vllm.logger import init_logger
from vllm.utils import LazyLoader
from vllm.utils.importlib import LazyLoader

if TYPE_CHECKING:
from transformers import PretrainedConfig
Expand Down
2 changes: 1 addition & 1 deletion vllm/distributed/parallel_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
from vllm.utils import (
direct_register_custom_op,
get_distributed_init_method,
resolve_obj_by_qualname,
supports_custom_op,
)
from vllm.utils.importlib import resolve_obj_by_qualname


@dataclass
Expand Down
3 changes: 2 additions & 1 deletion vllm/entrypoints/openai/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
SamplingParams,
StructuredOutputsParams,
)
from vllm.utils import random_uuid, resolve_obj_by_qualname
from vllm.utils import random_uuid
from vllm.utils.importlib import resolve_obj_by_qualname

EMBED_DTYPE_TO_TORCH_DTYPE = {
"float32": torch.float32,
Expand Down
2 changes: 1 addition & 1 deletion vllm/entrypoints/openai/speech_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from vllm.logger import init_logger
from vllm.model_executor.models import SupportsTranscription
from vllm.outputs import RequestOutput
from vllm.utils import PlaceholderModule
from vllm.utils.importlib import PlaceholderModule

try:
import librosa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
)
from vllm.logger import init_logger
from vllm.transformers_utils.tokenizer import AnyTokenizer
from vllm.utils import import_from_path
from vllm.utils.collections import is_list_of
from vllm.utils.importlib import import_from_path

logger = init_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion vllm/lora/punica_wrapper/punica_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from vllm.logger import init_logger
from vllm.platforms import current_platform
from vllm.utils import resolve_obj_by_qualname
from vllm.utils.importlib import resolve_obj_by_qualname

from .punica_base import PunicaWrapperBase

Expand Down
2 changes: 1 addition & 1 deletion vllm/model_executor/layers/pooler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from vllm.model_executor.models.adapters import _load_st_projector
from vllm.pooling_params import PoolingParams
from vllm.tasks import PoolingTask
from vllm.utils import resolve_obj_by_qualname
from vllm.utils.importlib import resolve_obj_by_qualname
from vllm.v1.outputs import PoolerOutput
from vllm.v1.pool.metadata import PoolingCursor, PoolingMetadata

Expand Down
3 changes: 2 additions & 1 deletion vllm/model_executor/model_loader/tensorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from vllm.logger import init_logger
from vllm.model_executor.layers.vocab_parallel_embedding import VocabParallelEmbedding
from vllm.platforms import current_platform
from vllm.utils import FlexibleArgumentParser, PlaceholderModule
from vllm.utils import FlexibleArgumentParser
from vllm.utils.importlib import PlaceholderModule

if TYPE_CHECKING:
from vllm.engine.arg_utils import EngineArgs
Expand Down
2 changes: 1 addition & 1 deletion vllm/model_executor/model_loader/weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
get_quantization_config,
)
from vllm.platforms import current_platform
from vllm.utils import PlaceholderModule
from vllm.utils.importlib import PlaceholderModule

try:
from runai_model_streamer import SafetensorsStreamer
Expand Down
2 changes: 1 addition & 1 deletion vllm/multimodal/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import numpy.typing as npt

from vllm.utils import PlaceholderModule
from vllm.utils.importlib import PlaceholderModule

from .base import MediaIO

Expand Down
2 changes: 1 addition & 1 deletion vllm/multimodal/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import numpy as np
from typing_extensions import NotRequired, TypeVar, deprecated

from vllm.utils import LazyLoader
from vllm.utils.collections import full_groupby, is_list_of
from vllm.utils.importlib import LazyLoader
from vllm.utils.jsontree import json_map_leaves

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion vllm/multimodal/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import torch
from typing_extensions import assert_never

from vllm.utils import LazyLoader
from vllm.utils.collections import is_list_of
from vllm.utils.importlib import LazyLoader

from .audio import AudioResampler
from .inputs import (
Expand Down
3 changes: 2 additions & 1 deletion vllm/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from vllm import envs
from vllm.plugins import PLATFORM_PLUGINS_GROUP, load_plugins_by_group
from vllm.utils import resolve_obj_by_qualname, supports_xccl
from vllm.utils import supports_xccl
from vllm.utils.importlib import resolve_obj_by_qualname

from .interface import CpuArchEnum, Platform, PlatformEnum

Expand Down
2 changes: 1 addition & 1 deletion vllm/plugins/io_processors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from vllm.config import VllmConfig
from vllm.plugins import IO_PROCESSOR_PLUGINS_GROUP, load_plugins_by_group
from vllm.plugins.io_processors.interface import IOProcessor
from vllm.utils import resolve_obj_by_qualname
from vllm.utils.importlib import resolve_obj_by_qualname

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion vllm/reasoning/abs_reasoning_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from typing import TYPE_CHECKING, Any

from vllm.logger import init_logger
from vllm.utils import import_from_path
from vllm.utils.collections import is_list_of
from vllm.utils.importlib import import_from_path

if TYPE_CHECKING:
from vllm.entrypoints.openai.protocol import (
Expand Down
2 changes: 1 addition & 1 deletion vllm/transformers_utils/runai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from vllm import envs
from vllm.assets.base import get_cache_dir
from vllm.logger import init_logger
from vllm.utils import PlaceholderModule
from vllm.utils.importlib import PlaceholderModule

logger = init_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion vllm/transformers_utils/s3_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import fnmatch
from typing import TYPE_CHECKING, Optional

from vllm.utils import PlaceholderModule
from vllm.utils.importlib import PlaceholderModule

if TYPE_CHECKING:
from botocore.client import BaseClient
Expand Down
Loading