A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[Chore] Separate out optional dependency checks from vllm.utils (#27207)
Signed-off-by: dongbo910220 <1275604947@qq.com> Signed-off-by: dongbo910220 <32610838+dongbo910220@users.noreply.github.com> Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com> Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
dongbo910220 committed
Oct 22, 2025 at 22:44 UTC
3ae082c373a864ec421d7e9118906f3b7add2bf5
22 files changed
+60
-64
tests/kernels/attention/test_deepgemm_attention.py
+2
-1
@@ -6,7 +6,7 @@ import pytest
6
import torch
7
8
from vllm.platforms import current_platform
9
-from vllm.utils import cdiv, has_deep_gemm
9
+from vllm.utils import cdiv
10
from vllm.utils.deep_gemm import (
11
_ceil_to_ue8m0,
12
calc_diff,
@@ -15,6 +15,7 @@ from vllm.utils.deep_gemm import (
15
get_num_sms,
16
get_paged_mqa_logits_metadata,
17
)
18
+from vllm.utils.import_utils import has_deep_gemm
19
20
21
def kv_cache_cast_to_fp8(x: torch.Tensor) -> torch.Tensor:
tests/kernels/moe/modular_kernel_tools/common.py
+1
-1
@@ -23,7 +23,7 @@ from vllm.model_executor.layers.fused_moe.config import (
23
FusedMoEQuantConfig,
24
)
25
from vllm.model_executor.layers.fused_moe.fused_moe import fused_topk
26
-from vllm.utils import has_deep_ep, has_deep_gemm, has_pplx
26
+from vllm.utils.import_utils import has_deep_ep, has_deep_gemm, has_pplx
27
28
from .mk_objects import (
29
TestMoEQuantConfig,
tests/kernels/moe/modular_kernel_tools/mk_objects.py
+1
-1
@@ -35,9 +35,9 @@ from vllm.model_executor.layers.quantization.utils.w8a8_utils import (
35
cutlass_fp8_supported,
36
)
37
from vllm.platforms import current_platform
38
-from vllm.utils import has_deep_ep, has_deep_gemm, has_pplx
38
from vllm.utils.deep_gemm import is_deep_gemm_supported
39
from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe
40
+from vllm.utils.import_utils import has_deep_ep, has_deep_gemm, has_pplx
41
42
43
@dataclass
tests/kernels/moe/parallel_utils.py
+1
-1
@@ -15,7 +15,7 @@ from torch.distributed import ProcessGroup
15
from torch.multiprocessing import spawn # pyright: ignore[reportPrivateImportUsage]
16
from typing_extensions import ParamSpec
17
18
-from vllm.utils import has_deep_ep
18
+from vllm.utils.import_utils import has_deep_ep
19
from vllm.utils.network_utils import get_open_port
20
21
if has_deep_ep():
tests/kernels/moe/test_block_fp8.py
+1
-1
@@ -21,11 +21,11 @@ from vllm.model_executor.layers.fused_moe.fused_moe import (
21
modular_triton_fused_moe,
22
)
23
from vllm.platforms import current_platform
24
-from vllm.utils import has_deep_gemm
24
from vllm.utils.deep_gemm import (
25
get_mk_alignment_for_contiguous_layout,
26
is_deep_gemm_e8m0_used,
27
)
28
+from vllm.utils.import_utils import has_deep_gemm
29
30
dg_available = has_deep_gemm()
31
tests/kernels/moe/test_deepep_deepgemm_moe.py
+1
-1
@@ -21,8 +21,8 @@ from vllm.model_executor.layers.fused_moe.config import (
21
from vllm.model_executor.layers.fused_moe.fused_moe import fused_experts
22
from vllm.model_executor.layers.fused_moe.modular_kernel import FusedMoEModularKernel
23
from vllm.platforms import current_platform
24
-from vllm.utils import has_deep_ep, has_deep_gemm
24
from vllm.utils.deep_gemm import is_deep_gemm_e8m0_used, is_deep_gemm_supported
25
+from vllm.utils.import_utils import has_deep_ep, has_deep_gemm
26
27
from ...utils import multi_gpu_test
28
from .parallel_utils import ProcessGroupInfo, parallel_launch
tests/kernels/moe/test_deepep_moe.py
+1
-1
@@ -21,7 +21,7 @@ from vllm.model_executor.layers.quantization.utils.fp8_utils import (
21
per_token_group_quant_fp8,
22
)
23
from vllm.platforms import current_platform
24
-from vllm.utils import has_deep_ep
24
+from vllm.utils.import_utils import has_deep_ep
25
26
from ...utils import multi_gpu_test
27
from .parallel_utils import ProcessGroupInfo, parallel_launch
tests/kernels/moe/test_gpt_oss_triton_kernels.py
+1
-1
@@ -6,7 +6,7 @@ import pytest
6
import torch
7
import torch.nn.functional as F
8
9
-from vllm.utils import has_triton_kernels
9
+from vllm.utils.import_utils import has_triton_kernels
10
11
if not has_triton_kernels():
12
pytest.skip(
tests/kernels/moe/test_modular_kernel_combinations.py
+1
-1
@@ -13,8 +13,8 @@ import torch
13
import vllm.model_executor.layers.fused_moe.modular_kernel as mk
14
from vllm.config import VllmConfig, set_current_vllm_config
15
from vllm.platforms import current_platform
16
-from vllm.utils import has_deep_ep, has_deep_gemm, has_pplx
16
from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe
17
+from vllm.utils.import_utils import has_deep_ep, has_deep_gemm, has_pplx
18
from vllm.utils.torch_utils import cuda_device_count_stateless
19
20
from .modular_kernel_tools.common import (
tests/kernels/quantization/test_block_fp8.py
+1
-1
@@ -18,12 +18,12 @@ from vllm.model_executor.layers.quantization.utils.fp8_utils import (
18
w8a8_triton_block_scaled_mm,
19
)
20
from vllm.platforms import current_platform
21
-from vllm.utils import has_deep_gemm
21
from vllm.utils.deep_gemm import (
22
fp8_gemm_nt,
23
get_col_major_tma_aligned_tensor,
24
per_block_cast_to_fp8,
25
)
26
+from vllm.utils.import_utils import has_deep_gemm
27
28
if current_platform.get_device_capability() < (9, 0):
29
pytest.skip("FP8 Triton requires CUDA 9.0 or higher", allow_module_level=True)
tests/models/quantization/test_fp8.py
-1
@@ -12,7 +12,6 @@ from tests.quantization.utils import is_quant_method_supported
12
from vllm.attention.utils.fa_utils import flash_attn_supports_fp8
13
from vllm.platforms import current_platform
14
from vllm.utils import STR_BACKEND_ENV_VAR
15
-
15
from ..utils import check_logprobs_close
16
17
vllm/distributed/device_communicators/all2all.py
+1
-1
@@ -9,8 +9,8 @@ import vllm.envs as envs
9
from vllm.distributed import get_dp_group, get_ep_group
10
from vllm.forward_context import get_forward_context
11
from vllm.logger import init_logger
12
-from vllm.utils import has_deep_ep, has_pplx
12
from vllm.utils.flashinfer import has_flashinfer_all2all
13
+from vllm.utils.import_utils import has_deep_ep, has_pplx
14
15
from .base_device_communicator import All2AllManagerBase, Cache
16
vllm/model_executor/layers/fused_moe/config.py
+2
-1
@@ -14,8 +14,9 @@ from vllm.model_executor.layers.quantization.utils.ocp_mx_utils import (
14
OCP_MX_Scheme,
15
)
16
from vllm.model_executor.layers.quantization.utils.quant_utils import GroupShape
17
-from vllm.utils import cdiv, has_triton_kernels
17
+from vllm.utils import cdiv
18
from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe
19
+from vllm.utils.import_utils import has_triton_kernels
20
21
logger = init_logger(__name__)
22
vllm/model_executor/layers/fused_moe/deep_gemm_moe.py
+1
-1
@@ -26,12 +26,12 @@ from vllm.model_executor.layers.fused_moe.utils import _resize_cache
26
from vllm.model_executor.layers.quantization.utils.fp8_utils import (
27
per_token_group_quant_fp8,
28
)
29
-from vllm.utils import has_deep_gemm
29
from vllm.utils.deep_gemm import (
30
get_mk_alignment_for_contiguous_layout,
31
m_grouped_fp8_gemm_nt_contiguous,
32
)
33
from vllm.utils.func_utils import run_once
34
+from vllm.utils.import_utils import has_deep_gemm
35
36
logger = init_logger(__name__)
37
vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
+1
-1
@@ -13,7 +13,7 @@ from vllm.model_executor.layers.fused_moe.topk_weight_and_reduce import (
13
TopKWeightAndReduceNoOP,
14
)
15
from vllm.triton_utils import tl, triton
16
-from vllm.utils import has_triton_kernels
16
+from vllm.utils.import_utils import has_triton_kernels
17
18
logger = init_logger(__name__)
19
vllm/model_executor/layers/fused_moe/layer.py
+2
-1
@@ -55,8 +55,9 @@ from vllm.model_executor.layers.quantization.utils.flashinfer_utils import (
55
from vllm.model_executor.utils import set_weight_attrs
56
from vllm.platforms import current_platform
57
from vllm.platforms.interface import CpuArchEnum
58
-from vllm.utils import cdiv, has_deep_ep, has_pplx, round_up
58
+from vllm.utils import cdiv, round_up
59
from vllm.utils.flashinfer import has_flashinfer_cutlass_fused_moe
60
+from vllm.utils.import_utils import has_deep_ep, has_pplx
61
from vllm.utils.torch_utils import current_stream, direct_register_custom_op
62
from vllm.v1.worker.ubatching import dbo_current_ubatch_id
63
vllm/model_executor/layers/quantization/fp8.py
+1
-1
@@ -93,7 +93,6 @@ from vllm.model_executor.parameter import (
93
from vllm.model_executor.utils import set_weight_attrs
94
from vllm.platforms import current_platform
95
from vllm.scalar_type import scalar_types
96
-from vllm.utils import has_deep_gemm
96
from vllm.utils.deep_gemm import (
97
fp8_gemm_nt,
98
get_col_major_tma_aligned_tensor,
@@ -102,6 +101,7 @@ from vllm.utils.deep_gemm import (
101
should_use_deepgemm_for_fp8_linear,
102
)
103
from vllm.utils.flashinfer import has_flashinfer_moe
104
+from vllm.utils.import_utils import has_deep_gemm
105
106
if TYPE_CHECKING:
107
from vllm.model_executor.models.utils import WeightsMapper
vllm/model_executor/layers/quantization/mxfp4.py
+2
-4
@@ -48,11 +48,9 @@ from vllm.model_executor.layers.quantization.utils.quant_utils import is_layer_s
48
from vllm.model_executor.utils import set_weight_attrs
49
from vllm.platforms import current_platform
50
from vllm.scalar_type import scalar_types
51
-from vllm.utils import (
52
- has_triton_kernels,
53
- round_up,
54
-)
51
+from vllm.utils import round_up
52
from vllm.utils.flashinfer import has_flashinfer
53
+from vllm.utils.import_utils import has_triton_kernels
54
from vllm.utils.torch_utils import is_torch_equal_or_newer
55
56
logger = init_logger(__name__)
vllm/utils/__init__.py
-41
@@ -5,7 +5,6 @@ import contextlib
5
import datetime
6
import enum
7
import getpass
8
-import importlib
8
import inspect
9
import json
10
import multiprocessing
@@ -1062,46 +1061,6 @@ def check_use_alibi(model_config: ModelConfig) -> bool:
1061
)
1062
1063
1065
-@cache
1066
-def _has_module(module_name: str) -> bool:
1067
- """Return True if *module_name* can be found in the current environment.
1068
-
1069
- The result is cached so that subsequent queries for the same module incur
1070
- no additional overhead.
1071
- """
1072
- return importlib.util.find_spec(module_name) is not None
1073
-
1074
-
1075
-def has_pplx() -> bool:
1076
- """Whether the optional `pplx_kernels` package is available."""
1077
-
1078
- return _has_module("pplx_kernels")
1079
-
1080
-
1081
-def has_deep_ep() -> bool:
1082
- """Whether the optional `deep_ep` package is available."""
1083
-
1084
- return _has_module("deep_ep")
1085
-
1086
-
1087
-def has_deep_gemm() -> bool:
1088
- """Whether the optional `deep_gemm` package is available."""
1089
-
1090
- return _has_module("deep_gemm")
1091
-
1092
-
1093
-def has_triton_kernels() -> bool:
1094
- """Whether the optional `triton_kernels` package is available."""
1095
-
1096
- return _has_module("triton_kernels")
1097
-
1098
-
1099
-def has_tilelang() -> bool:
1100
- """Whether the optional `tilelang` package is available."""
1101
-
1102
- return _has_module("tilelang")
1103
-
1104
-
1064
def set_process_title(
1065
name: str, suffix: str = "", prefix: str = envs.VLLM_PROCESS_NAME_PREFIX
1066
) -> None:
vllm/utils/deep_gemm.py
+2
-1
@@ -16,7 +16,8 @@ import torch
16
import vllm.envs as envs
17
from vllm.logger import logger
18
from vllm.platforms import current_platform
19
-from vllm.utils import cdiv, has_deep_gemm
19
+from vllm.utils import cdiv
20
+from vllm.utils.import_utils import has_deep_gemm
21
22
23
@functools.cache
vllm/utils/import_utils.py
+36
@@ -324,3 +324,39 @@ class LazyLoader(ModuleType):
324
if self._module is None:
325
self._module = self._load()
326
return dir(self._module)
327
+
328
+
329
+# Optional dependency detection utilities
330
+@cache
331
+def _has_module(module_name: str) -> bool:
332
+ """Return True if *module_name* can be found in the current environment.
333
+
334
+ The result is cached so that subsequent queries for the same module incur
335
+ no additional overhead.
336
+ """
337
+ return importlib.util.find_spec(module_name) is not None
338
+
339
+
340
+def has_pplx() -> bool:
341
+ """Whether the optional `pplx_kernels` package is available."""
342
+ return _has_module("pplx_kernels")
343
+
344
+
345
+def has_deep_ep() -> bool:
346
+ """Whether the optional `deep_ep` package is available."""
347
+ return _has_module("deep_ep")
348
+
349
+
350
+def has_deep_gemm() -> bool:
351
+ """Whether the optional `deep_gemm` package is available."""
352
+ return _has_module("deep_gemm")
353
+
354
+
355
+def has_triton_kernels() -> bool:
356
+ """Whether the optional `triton_kernels` package is available."""
357
+ return _has_module("triton_kernels")
358
+
359
+
360
+def has_tilelang() -> bool:
361
+ """Whether the optional `tilelang` package is available."""
362
+ return _has_module("tilelang")
vllm/v1/worker/gpu_ubatch_wrapper.py
+1
-1
@@ -22,7 +22,7 @@ from vllm.forward_context import (
22
from vllm.logger import init_logger
23
from vllm.platforms import current_platform
24
from vllm.sequence import IntermediateTensors
25
-from vllm.utils import has_deep_gemm
25
+from vllm.utils.import_utils import has_deep_gemm
26
from vllm.v1.worker.ubatching import UBatchContext, make_ubatch_contexts
27
28
logger = init_logger(__name__)