2024-06-13 16:06:49 -07:00
|
|
|
import os
|
|
|
|
|
|
|
|
import ray
|
|
|
|
|
|
|
|
from vllm.utils import cuda_device_count_stateless
|
|
|
|
|
|
|
|
|
|
|
|
@ray.remote
|
2024-06-15 12:45:31 +08:00
|
|
|
class _CUDADeviceCountStatelessTestActor:
|
2024-06-13 16:06:49 -07:00
|
|
|
|
|
|
|
def get_count(self):
|
|
|
|
return cuda_device_count_stateless()
|
|
|
|
|
|
|
|
def set_cuda_visible_devices(self, cuda_visible_devices: str):
|
|
|
|
os.environ["CUDA_VISIBLE_DEVICES"] = cuda_visible_devices
|
|
|
|
|
|
|
|
def get_cuda_visible_devices(self):
|
|
|
|
return os.environ["CUDA_VISIBLE_DEVICES"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_cuda_device_count_stateless():
|
|
|
|
"""Test that cuda_device_count_stateless changes return value if
|
|
|
|
CUDA_VISIBLE_DEVICES is changed."""
|
|
|
|
|
2024-06-15 12:45:31 +08:00
|
|
|
actor = _CUDADeviceCountStatelessTestActor.options( # type: ignore
|
|
|
|
num_gpus=2).remote()
|
2024-06-14 10:02:23 -07:00
|
|
|
assert sorted(ray.get(
|
|
|
|
actor.get_cuda_visible_devices.remote()).split(",")) == ["0", "1"]
|
2024-06-13 16:06:49 -07:00
|
|
|
assert ray.get(actor.get_count.remote()) == 2
|
|
|
|
ray.get(actor.set_cuda_visible_devices.remote("0"))
|
|
|
|
assert ray.get(actor.get_count.remote()) == 1
|
|
|
|
ray.get(actor.set_cuda_visible_devices.remote(""))
|
|
|
|
assert ray.get(actor.get_count.remote()) == 0
|