Skip to content

Commit 042c341

Browse files
authored
Introduce VLLM_CUDART_SO_PATH to allow users specify the .so path (#12998)
Signed-off-by: Lu Fang <[email protected]>
1 parent 82cabf5 commit 042c341

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

vllm/distributed/device_communicators/cuda_wrapper.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"""
66

77
import ctypes
8+
import glob
89
from dataclasses import dataclass
910
from typing import Any, Dict, List, Optional
1011

1112
# this line makes it possible to directly load `libcudart.so` using `ctypes`
1213
import torch # noqa
1314

15+
import vllm.envs as envs
1416
from vllm.logger import init_logger
1517

1618
logger = init_logger(__name__)
@@ -60,6 +62,29 @@ def find_loaded_library(lib_name) -> Optional[str]:
6062
return path
6163

6264

65+
def get_cudart_lib_path_from_env() -> Optional[str]:
66+
"""
67+
In some system, find_loaded_library() may not work. So we allow users to
68+
specify the path through environment variable VLLM_CUDART_SO_PATH.
69+
"""
70+
cudart_so_env = envs.VLLM_CUDART_SO_PATH
71+
if cudart_so_env is not None:
72+
cudart_paths = [
73+
cudart_so_env,
74+
]
75+
for path in cudart_paths:
76+
file_paths = glob.glob(path)
77+
if len(file_paths) > 0:
78+
logger.info(
79+
"Found cudart library at %s through env var"
80+
"VLLM_CUDART_SO_PATH=%s",
81+
file_paths[0],
82+
cudart_so_env,
83+
)
84+
return file_paths[0]
85+
return None
86+
87+
6388
class CudaRTLibrary:
6489
exported_functions = [
6590
# ​cudaError_t cudaSetDevice ( int device )
@@ -105,8 +130,13 @@ class CudaRTLibrary:
105130
def __init__(self, so_file: Optional[str] = None):
106131
if so_file is None:
107132
so_file = find_loaded_library("libcudart")
133+
if so_file is None:
134+
so_file = get_cudart_lib_path_from_env()
108135
assert so_file is not None, \
109-
"libcudart is not loaded in the current process"
136+
(
137+
"libcudart is not loaded in the current process, "
138+
"try setting VLLM_CUDART_SO_PATH"
139+
)
110140
if so_file not in CudaRTLibrary.path_to_library_cache:
111141
lib = ctypes.CDLL(so_file)
112142
CudaRTLibrary.path_to_library_cache[so_file] = lib

vllm/envs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
VLLM_ENABLE_MOE_ALIGN_BLOCK_SIZE_TRITON: bool = False
8888
VLLM_RAY_PER_WORKER_GPUS: float = 1.0
8989
VLLM_RAY_BUNDLE_INDICES: str = ""
90+
VLLM_CUDART_SO_PATH: Optional[str] = None
9091

9192

9293
def get_default_cache_root():
@@ -572,6 +573,11 @@ def maybe_convert_int(value: Optional[str]) -> Optional[int]:
572573
# models the alignment is already naturally aligned to 256 bytes.
573574
"VLLM_CUDA_MEM_ALIGN_KV_CACHE":
574575
lambda: bool(int(os.getenv("VLLM_CUDA_MEM_ALIGN_KV_CACHE", "1"))),
576+
577+
# In some system, find_loaded_library() may not work. So we allow users to
578+
# specify the path through environment variable VLLM_CUDART_SO_PATH.
579+
"VLLM_CUDART_SO_PATH":
580+
lambda: os.getenv("VLLM_CUDART_SO_PATH", None),
575581
}
576582

577583
# end-env-vars-definition

0 commit comments

Comments
 (0)