Skip to content

Commit b72220a

Browse files
committed
fix ci
Signed-off-by: YunLiu <[email protected]>
1 parent 46e9bce commit b72220a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

monai/utils/module.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from types import FunctionType, ModuleType
2828
from typing import Any, cast
2929

30-
import pynvml
3130
import torch
3231

3332
# bundle config system flags
@@ -653,11 +652,19 @@ def compute_capabilities_after(major: int, minor: int = 0, current_ver_string: s
653652
True if the current system GPU CUDA compute capability is greater than or equal to the specified version.
654653
"""
655654
if current_ver_string is None:
656-
pynvml.nvmlInit()
657-
handle = pynvml.nvmlDeviceGetHandleByIndex(0) # get the first GPU
658-
major_c, minor_c = pynvml.nvmlDeviceGetCudaComputeCapability(handle)
659-
pynvml.nvmlShutdown()
660-
current_ver_string = f"{major_c}.{minor_c}"
655+
pynvml, has_pynvml = optional_import("pynvml")
656+
if not has_pynvml: # assuming that the user has Ampere and later GPU
657+
return True
658+
659+
try:
660+
pynvml.nvmlInit()
661+
handle = pynvml.nvmlDeviceGetHandleByIndex(0) # get the first GPU
662+
major_c, minor_c = pynvml.nvmlDeviceGetCudaComputeCapability(handle)
663+
current_ver_string = f"{major_c}.{minor_c}"
664+
except BaseException:
665+
pass
666+
finally:
667+
pynvml.nvmlShutdown()
661668

662669
ver, has_ver = optional_import("packaging.version", name="parse")
663670
if has_ver:

0 commit comments

Comments
 (0)