Skip to content

Commit

Permalink
Detect and reject unofficial pynvml bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywonchung committed May 8, 2024
1 parent 8c4675c commit 6c97b4b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions zeus/device/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,14 +910,26 @@ def nvml_is_available() -> bool:
try:
import pynvml
except ImportError:
logger.info("PyNVML is not available.")
logger.info("pynvml is not available.")
return False

# Detect unofficial pynvml packages.
# If detected, this should be a critical error.
if not hasattr(pynvml, "_nvmlGetFunctionPointer"):
logger.error("Unoffical pynvml package detected!")
raise ImportError(
"Unofficial pynvml package detected! "
"This causes conflicts with the official NVIDIA bindings. "
"Please remove with `pip uninstall pynvml` and instead use the official "
"bindings from NVIDIA: `nvidia-ml-py`. "
)

try:
pynvml.nvmlInit()
logger.info("PyNVML is available and initialized.")
logger.info("pynvml is available and initialized.")
return True
except pynvml.NVMLError:
logger.info("PyNVML is available but could not initialize.")
logger.info("pynvml is available but could not initialize.")
return False


Expand Down

0 comments on commit 6c97b4b

Please sign in to comment.