Use NVML directly and cache nvidia-smi calls - #114
Open
Qubitium wants to merge 3 commits into
Open
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
… cache TTL to 0, ensure GIL=0 thread safety
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eliminates repeated
nvidia-smiprocess spawns by adding a zero-dependency NVML ctypes binding and a TTL/LRU cache fornvidia-smifallback. Caching is now disabled by default and exposed throughDevice.config.Changes
device_smi/nvidia.pyloadslibnvidia-ml.so.1/nvml.dll/libnvidia-ml.dylibviactypes.CDLLand binds a minimal NVML API (nvmlInit_v2,nvmlDeviceGetCount_v2,nvmlDeviceGetHandleByIndex_v2,nvmlDeviceGetName,nvmlDeviceGetPciInfo_v3,nvmlDeviceGetMemoryInfo,nvmlDeviceGetUtilizationRates, etc.).NvidiaDeviceinitializes from NVML first and falls back tonvidia-smiif NVML is absent or returns an error.metrics()also prefers NVML and only falls back tonvidia-smi.nvidia-smicalls go through_run_nvidia_smiand a thread-safe_NvidiaSmiCache. All cache mutations are protected bythreading.Lock, so the cache is safe under free-threaded (GIL=0) builds. A TTL of0disables the cache; a positive value enables stale-within-TTL caching and LRU eviction.device_smi/config.pyexposesnvidia_smi_cache_ttl(default0.0) andnvidia_smi_cache_maxsize(default16), available asdevice_smi.configandDevice.config.nvidia-smipath.README.mdwith the newDevice.configAPI and the default-disabled caching behavior.Usage
No new runtime dependencies are introduced.
Link to Devin session: https://app.devin.ai/sessions/35c36bf93a05479a9d150d6c3b1f10d5
Requested by: @Qubitium