GPUStat: NVIDIA GPU Monitoring Utility
GPStat is a command-line utility for monitoring NVIDIA GPU status and usage, offering a more concise and user-friendly alternative to `nvidia-smi`. It provides essential GPU information including temperature, utilization, memory usage, and running processes. The library, currently at version 1.1.1, maintains an active development cycle with regular updates.
Warnings
- breaking Python 2 support was retired in `gpustat` v1.0. For versions 1.1 and higher, the minimum Python version required is 3.6.
- breaking `gpustat` v1.0 and later utilize NVIDIA's official Python bindings (`nvidia-ml-py`) for NVML. This requires an NVIDIA driver version R450.00 or higher for correct display of process information. Older drivers may result in incomplete data.
- gotcha It is explicitly advised *not* to install `pynvml` directly, as this will not work correctly with `gpustat`. Instead, the official NVIDIA bindings (`nvidia-ml-py`) should be used.
- gotcha GPU indexing in `gpustat` (and `nvidia-smi`) uses PCI Bus ID, which may differ from CUDA's default ordering. For consistent indexing between `gpustat` and CUDA applications, set the `CUDA_DEVICE_ORDER` environment variable.
Install
-
pip install gpustat
Imports
- new_query
import gpustat gpus = gpustat.new_query()
- GPUStat
from gpustat.core import GPUStat
Quickstart
import gpustat
try:
# Query GPU status
gpus = gpustat.new_query()
# Print formatted output for each GPU
for gpu in gpus:
print(f"GPU ID: {gpu.index}")
print(f" Name: {gpu.name}")
print(f" Temperature: {gpu.temperature}°C")
print(f" Utilization: {gpu.utilization}% ")
print(f" Memory Used: {gpu.memory_used}MB / {gpu.memory_total}MB")
if gpu.processes:
print(" Processes:")
for p in gpu.processes:
print(f" - PID: {p.pid}, Command: {p.command}, Memory: {p.gpu_memory_usage}MB")
print("-" * 20)
# Example: Get JSON output
# import json
# json_output = gpustat.new_query().jsonify()
# print(json.dumps(json_output, indent=2))
except Exception as e:
print(f"Could not query GPU status: {e}")
print("Ensure NVIDIA drivers are installed and `nvidia-ml-py` is correctly configured.")