From 265c50f65930c591f70103b79794124f46697377 Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Wed, 31 May 2023 21:33:14 -0400 Subject: [PATCH] Make gpustat.nvml compatible with a third-party fork of pynvml (#153) An un-official distribution of the pynvml package provided by @gpuopenanalytics/pynvml was causing an incompatibility issue, where gpustat.nvml fails to import. Although the official and correct pynvml packages should be installed, but wild users' python environments can be easily messed up by unawaringly installing the problematic, unofficial pynvml package. gpustat can support this third-party pynvml by directly importing the low-level pynvml.nvml package (which should be exactly the same as an official pynvml.py). This is a quickfix that relies on the implementation detail of a third-party package, but nevertheless it should be a good enough workaround solution for many users in practice. (cherry picked from commit 7c09a0fa467c23cba0d2dd0be820f5a82c58a283, backported to 1.1.x) --- gpustat/nvml.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gpustat/nvml.py b/gpustat/nvml.py index 0427bac..fcf684c 100644 --- a/gpustat/nvml.py +++ b/gpustat/nvml.py @@ -27,7 +27,8 @@ raise ImportError("pynvml library is outdated.") if not hasattr(pynvml, '_nvmlGetFunctionPointer'): - raise ImportError("pynvml appears to be a non-official package.") + # Unofficial pynvml from @gpuopenanalytics/pynvml, see #153 + import pynvml.nvml as pynvml except (ImportError, SyntaxError, RuntimeError) as e: _pynvml = sys.modules.get('pynvml', None)