34
34
torch .backends .cuda .enable_cudnn_sdp (False )
35
35
36
36
37
- def device_id_to_physical_device_id (device_id : int ) -> int :
38
- if "CUDA_VISIBLE_DEVICES" in os .environ :
39
- device_ids = os .environ ["CUDA_VISIBLE_DEVICES" ].split ("," )
40
- if device_ids == ["" ]:
41
- msg = (
42
- "CUDA_VISIBLE_DEVICES is set to empty string, which means"
43
- " GPU support is disabled. If you are using ray, please unset"
44
- " the environment variable `CUDA_VISIBLE_DEVICES` inside the"
45
- " worker/actor. "
46
- "Check https://github.com/vllm-project/vllm/issues/8402 for"
47
- " more information." )
48
- raise RuntimeError (msg )
49
- physical_device_id = device_ids [device_id ]
50
- return int (physical_device_id )
51
- else :
52
- return device_id
53
-
54
-
55
37
def with_nvml_context (fn : Callable [_P , _R ]) -> Callable [_P , _R ]:
56
38
57
39
@wraps (fn )
@@ -338,7 +320,7 @@ def get_device_capability(cls,
338
320
device_id : int = 0
339
321
) -> Optional [DeviceCapability ]:
340
322
try :
341
- physical_device_id = device_id_to_physical_device_id (device_id )
323
+ physical_device_id = cls . device_id_to_physical_device_id (device_id )
342
324
handle = pynvml .nvmlDeviceGetHandleByIndex (physical_device_id )
343
325
major , minor = pynvml .nvmlDeviceGetCudaComputeCapability (handle )
344
326
return DeviceCapability (major = major , minor = minor )
@@ -360,20 +342,20 @@ def has_device_capability(
360
342
@classmethod
361
343
@with_nvml_context
362
344
def get_device_name (cls , device_id : int = 0 ) -> str :
363
- physical_device_id = device_id_to_physical_device_id (device_id )
345
+ physical_device_id = cls . device_id_to_physical_device_id (device_id )
364
346
return cls ._get_physical_device_name (physical_device_id )
365
347
366
348
@classmethod
367
349
@with_nvml_context
368
350
def get_device_uuid (cls , device_id : int = 0 ) -> str :
369
- physical_device_id = device_id_to_physical_device_id (device_id )
351
+ physical_device_id = cls . device_id_to_physical_device_id (device_id )
370
352
handle = pynvml .nvmlDeviceGetHandleByIndex (physical_device_id )
371
353
return pynvml .nvmlDeviceGetUUID (handle )
372
354
373
355
@classmethod
374
356
@with_nvml_context
375
357
def get_device_total_memory (cls , device_id : int = 0 ) -> int :
376
- physical_device_id = device_id_to_physical_device_id (device_id )
358
+ physical_device_id = cls . device_id_to_physical_device_id (device_id )
377
359
handle = pynvml .nvmlDeviceGetHandleByIndex (physical_device_id )
378
360
return int (pynvml .nvmlDeviceGetMemoryInfo (handle ).total )
379
361
0 commit comments