Skip to content

Commit 470272c

Browse files
authored
[SWDEV-477447] Set _HAS_PYNVML to false if amdsmi not installed (#1535)
Fix from pytorch#132990 cherry picked into 6.2 to be resolved for 6.2.1 """ This is a bugfix that was recently encountered in ROCm/Deepspeed. Currently if a library installs pynvml and runs on ROCm pytorch will break as _HAS_PYNVML is set to true and it will attempt to use amdsmi library for the device_count call which will not be installed. This fix will set _HAS_PYNVML to false on ROCm if amdsmi is not installed. """ Will need to be cherry picked to release/2.3 and rocm6.3_internal_testing also
1 parent fbdea91 commit 470272c

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

torch/cuda/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@
5454
_PYNVML_ERR = None
5555
try:
5656
try:
57-
import pynvml # type: ignore[import]
58-
59-
_HAS_PYNVML = True
60-
except ModuleNotFoundError:
61-
pass
62-
try:
63-
import amdsmi # type: ignore[import]
57+
if not torch.version.hip:
58+
import pynvml # type: ignore[import]
59+
else:
60+
import amdsmi # type: ignore[import]
6461

6562
_HAS_PYNVML = True
6663
except ModuleNotFoundError:

0 commit comments

Comments
 (0)