Skip to content

Commit 7033d82

Browse files
youkaichaoUbuntu
authored and
Ubuntu
committed
[platform] add device_control env var (vllm-project#12009)
Signed-off-by: youkaichao <[email protected]>
1 parent c9747bc commit 7033d82

File tree

7 files changed

+17
-0
lines changed

7 files changed

+17
-0
lines changed

vllm/platforms/cuda.py

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class CudaPlatformBase(Platform):
7878
device_type: str = "cuda"
7979
dispatch_key: str = "CUDA"
8080
ray_device_key: str = "GPU"
81+
device_control_env_var: str = "CUDA_VISIBLE_DEVICES"
8182

8283
@classmethod
8384
def get_device_capability(cls,

vllm/platforms/hpu.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class HpuPlatform(Platform):
2020
device_type: str = "hpu"
2121
dispatch_key: str = "HPU"
2222
ray_device_key: str = "HPU"
23+
device_control_env_var: str = "HABANA_VISIBLE_MODULES"
2324

2425
@classmethod
2526
def get_attn_backend_cls(cls, selected_backend: _Backend, head_size: int,

vllm/platforms/interface.py

+10
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,30 @@ class Platform:
7878
_enum: PlatformEnum
7979
device_name: str
8080
device_type: str
81+
8182
# available dispatch keys:
8283
# check https://github.com/pytorch/pytorch/blob/313dac6c1ca0fa0cde32477509cce32089f8532a/torchgen/model.py#L134 # noqa
8384
# use "CPU" as a fallback for platforms not registered in PyTorch
8485
dispatch_key: str = "CPU"
86+
8587
# available ray device keys:
8688
# https://github.com/ray-project/ray/blob/10ba5adadcc49c60af2c358a33bb943fb491a171/python/ray/_private/ray_constants.py#L438 # noqa
8789
# empty string means the device does not support ray
8890
ray_device_key: str = ""
91+
92+
# platform-agnostic way to specify the device control environment variable,
93+
# .e.g. CUDA_VISIBLE_DEVICES for CUDA.
94+
# hint: search for "get_visible_accelerator_ids_env_var" in
95+
# https://github.com/ray-project/ray/tree/master/python/ray/_private/accelerators # noqa
96+
device_control_env_var: str = "VLLM_DEVICE_CONTROL_ENV_VAR_PLACEHOLDER"
97+
8998
# The torch.compile backend for compiling simple and
9099
# standalone functions. The default value is "inductor" to keep
91100
# the same behavior as PyTorch.
92101
# NOTE: for the forward part of the model, vLLM has another separate
93102
# compilation strategy.
94103
simple_compile_backend: str = "inductor"
104+
95105
supported_quantization: list[str] = []
96106

97107
def is_cuda(self) -> bool:

vllm/platforms/neuron.py

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class NeuronPlatform(Platform):
1818
device_type: str = "neuron"
1919
ray_device_key: str = "neuron_cores"
2020
supported_quantization: list[str] = ["neuron_quant"]
21+
device_control_env_var: str = "NEURON_RT_VISIBLE_CORES"
2122

2223
@classmethod
2324
def get_device_name(cls, device_id: int = 0) -> str:

vllm/platforms/rocm.py

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class RocmPlatform(Platform):
6565
device_type: str = "cuda"
6666
dispatch_key: str = "CUDA"
6767
ray_device_key: str = "GPU"
68+
# rocm shares the same device control env var as CUDA
69+
device_control_env_var: str = "CUDA_VISIBLE_DEVICES"
6870

6971
supported_quantization: list[str] = [
7072
"awq", "gptq", "fp8", "compressed_tensors", "compressed-tensors",

vllm/platforms/tpu.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class TpuPlatform(Platform):
2020
device_type: str = "tpu"
2121
dispatch_key: str = "XLA"
2222
ray_device_key: str = "TPU"
23+
device_control_env_var: str = "TPU_VISIBLE_CHIPS"
2324

2425
supported_quantization: list[str] = [
2526
"tpu_int8", "compressed-tensors", "compressed_tensors"

vllm/platforms/xpu.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class XPUPlatform(Platform):
2222
# Intel XPU's device key is "GPU" for Ray.
2323
# see https://github.com/ray-project/ray/blob/6a5eb5865eeb9ccf058a79b44f107e327e360673/python/ray/_private/accelerators/intel_gpu.py#L20 # noqa: E501
2424
ray_device_key: str = "GPU"
25+
device_control_env_var: str = "ONEAPI_DEVICE_SELECTOR"
2526

2627
@classmethod
2728
def get_attn_backend_cls(cls, selected_backend: _Backend, head_size: int,

0 commit comments

Comments
 (0)