Skip to main content

Utility functions for working with GPUs.

Project description

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.run for kill and lsof)
    • Everything except kill_interrupted_processes should work on any OS

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 pynvml instead of parsing nvidia-smi with regular expressions made this library a bit faster and much more robust than my previous regex parsing of nivida-smi's output; thanks to gpustat for showing me this library and some ideas about the output format for the gpu script.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpu-utils-0.2.8.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

gpu_utils-0.2.8-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file gpu-utils-0.2.8.tar.gz.

File metadata

  • Download URL: gpu-utils-0.2.8.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for gpu-utils-0.2.8.tar.gz
Algorithm Hash digest
SHA256 566dc2081c36cc98cce58fbd2bfb055ea17f2d6a15161fd64391d5db36b57327
MD5 91b38187aadbd75894e3c9f69699c059
BLAKE2b-256 6953af7d3d4b8e68a09e64e179be09dc39cfd8e3792a60341d4a0c9b1ef7056d

See more details on using hashes here.

File details

Details for the file gpu_utils-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: gpu_utils-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for gpu_utils-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 194f9bef98919cc5b172d6cb4bcd2ead4d4046100ac163a04b45d5f18371cd5c
MD5 5bbdebeaca18d2a55e1883ec28de5e58
BLAKE2b-256 f5c9cc5472bfff07838247f242d1971e8cf44a564424164449138a70636a1ba1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page