Skip to content

Commit 9621667

Browse files
[Misc] Warn if the vLLM version can't be retrieved (#13501)
Signed-off-by: Alex-Brooks <[email protected]>
1 parent 8c755c3 commit 9621667

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

vllm/platforms/__init__.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44
import traceback
5+
from contextlib import suppress
56
from itertools import chain
67
from typing import TYPE_CHECKING, Optional
78

@@ -14,6 +15,21 @@
1415
logger = logging.getLogger(__name__)
1516

1617

18+
def vllm_version_matches_substr(substr: str) -> bool:
19+
"""
20+
Check to see if the vLLM version matches a substring.
21+
"""
22+
from importlib.metadata import PackageNotFoundError, version
23+
try:
24+
vllm_version = version("vllm")
25+
except PackageNotFoundError as e:
26+
logger.warning(
27+
"The vLLM package was not found, so its version could not be "
28+
"inspected. This may cause platform detection to fail.")
29+
raise e
30+
return substr in vllm_version
31+
32+
1733
def tpu_platform_plugin() -> Optional[str]:
1834
is_tpu = False
1935
try:
@@ -33,8 +49,6 @@ def cuda_platform_plugin() -> Optional[str]:
3349
is_cuda = False
3450

3551
try:
36-
from importlib.metadata import version
37-
3852
from vllm.utils import import_pynvml
3953
pynvml = import_pynvml()
4054
pynvml.nvmlInit()
@@ -45,7 +59,7 @@ def cuda_platform_plugin() -> Optional[str]:
4559
# Otherwise, vllm will always activate cuda plugin
4660
# on a GPU machine, even if in a cpu build.
4761
is_cuda = (pynvml.nvmlDeviceGetCount() > 0
48-
and "cpu" not in version("vllm"))
62+
and not vllm_version_matches_substr("cpu"))
4963
finally:
5064
pynvml.nvmlShutdown()
5165
except Exception as e:
@@ -113,8 +127,7 @@ def xpu_platform_plugin() -> Optional[str]:
113127
def cpu_platform_plugin() -> Optional[str]:
114128
is_cpu = False
115129
try:
116-
from importlib.metadata import version
117-
is_cpu = "cpu" in version("vllm")
130+
is_cpu = vllm_version_matches_substr("cpu")
118131
if not is_cpu:
119132
import platform
120133
is_cpu = platform.machine().lower().startswith("arm")
@@ -138,11 +151,8 @@ def neuron_platform_plugin() -> Optional[str]:
138151

139152
def openvino_platform_plugin() -> Optional[str]:
140153
is_openvino = False
141-
try:
142-
from importlib.metadata import version
143-
is_openvino = "openvino" in version("vllm")
144-
except Exception:
145-
pass
154+
with suppress(Exception):
155+
is_openvino = vllm_version_matches_substr("openvino")
146156

147157
return "vllm.platforms.openvino.OpenVinoPlatform" if is_openvino else None
148158

0 commit comments

Comments
 (0)