GPU Utils
A few small functions/scripts for working with GPUs.
Requirements
- Python 3.6+
- Linux OS for full functionality (only tested on Ubuntu; I use
subprocess.runforkillandlsof)- Everything except
kill_interrupted_processesshould work on any OS
- Everything except
Installation
pip install gpu-utils
The PyPI page is here.
Usage
from gpu_utils import gpu_init
# sets GPU ids to use nvidia-smi ordering (CUDA_DEVICE_ORDER = PCI_BUS_ID)
# finds the gpu with the most free utilization or memory
# hides all other GPUs so you only use this one (CUDA_VISIBLE_DEVICES = <gpu_id>)
gpu_id = gpu_init(best_gpu_metric="util") # could also use "mem"
If you use TensorFlow or PyTorch, gpu_init can take care of another couple of steps for you:
# a torch.device for the selected GPU
device = gpu_init(ml_library="torch")
import tensorflow as tf
# a tf.ConfigProto to allow soft placement + GPU memory growth
config = gpu_init(ml_library="tensorflow")
session = tf.Session(config=config)
Command Line Scripts
gpu is a more concise and prettier version of nvidia-smi. It is similar to gpustat but with more control over the color configuration and the ability to show the full processes running on each GPU.
kill_interrupted_processes is useful if you interrupt a process using a GPU but find that, even though nvidia-smi no longer shows the process, the memory is still being held. It will send kill -9 to all such processes so you can reclaim your GPU memory.
tmux_gpu_info.py just prints a list of the percent utilization of each GPU; you can, e.g., show this in the status bar of tmux to keep an eye on your GPUs.
Acknowledgements
- Using
pynvmlinstead of parsingnvidia-smiwith regular expressions made this library a bit faster and much more robust than my previous regex parsing ofnivida-smi's output; thanks togpustatfor showing me this library and some ideas about the output format for thegpuscript.
Metadata
Release files for gpu-utils 0.2.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| gpu-utils-0.2.8.tar.gz | 8.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gpu_utils-0.2.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.5 kB
Release files / gpu-utils-0.2.8.tar.gz
| Download URL | gpu-utils-0.2.8.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
566dc2081c36cc98cce58fbd2bfb055ea17f2d6a15161fd64391d5db36b57327
|
|
BLAKE2b-256 checksum How to use checksums |
6953af7d3d4b8e68a09e64e179be09dc39cfd8e3792a60341d4a0c9b1ef7056d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
|
Release files / gpu_utils-0.2.8-py3-none-any.whl
| Download URL | gpu_utils-0.2.8-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
194f9bef98919cc5b172d6cb4bcd2ead4d4046100ac163a04b45d5f18371cd5c
|
|
BLAKE2b-256 checksum How to use checksums |
f5c9cc5472bfff07838247f242d1971e8cf44a564424164449138a70636a1ba1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
|
Security for gpu-utils 0.2.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.