Skip to main content

Monitor idle GPU usage.

Project description

GPU Sentinel

A Moonshine Labs tool

Overview

If you're automating training your large models in the cloud, cost control is critial. How many times have you accidentally left an expensive GPU instance running when the underlying job had crashed, costing you money or capacity with no benefit?

GPU Sentinel is a simple tool that will watch your instance and automatically trigger when GPU utilization drops below a certain amount for a period of time. GPU Sentinel can automatically shutdown or reboot the instance, or simply end its own process so you can do an action yourself.

Installation

$ pip install gpu_sentinel
$ gpu_sentinel --help

Usage

The GPU sentinel has two states, IDLE and ARMED.

When you start the program, it will wait for the GPU to be above a certain utilization for a set amount of time. Once this condition is met, the sentinel will be ARMED. This will let you set the sentinel at any point, and it will only trigger once the GPU has been running for a while.

Once ARMED, the sentinel will wait for the GPU utilization to drop below a certain threshold for a set amount of time. Once this condition is met, the kill_action will occur immediately.

Options:

arm_duration: How many seconds of activity to wait before arming the sentinel.
arm_threshold: What level of utilization is considered activity
kill_duration: How many seconds of inactivity to wait before running the kill function.
kill_threshold: What level of utilization is considered inactivity
kill_action: What to do when the kill trigger is hit {end_process,shutdown,reboot}
gpu_devices: Which GPU devices to average (empty for all)

API

If you would prefer to use integrate this package into your own code, we provide a straightforward API to do so.

from gpu_sentinel import Sentinel, get_gpu_usage

def my_callback_fn():
    print("Triggered!")
    exit()

# Create the sentinel that watches the values.
sentinel = Sentinel(
    arm_duration=10,
    arm_threshold=0.7,
    kill_duration=60,
    kill_threshold=0.7,
    kill_fn=my_callback_fn,
)

while True:
    # This is the averaged GPU usage of the devices.
    gpu_usage = get_gpu_usage(device_ids=[0, 1, 2, 3])
    # Add the GPU usage to the sentinel's next state.
    sentinel.tick(gpu_usage)
    # The sentinel operates on ticks, not seconds, so if we want to check every second
    # we must do the timer ourselves.
    time.sleep(1)

Current Limitations

  • To shutdown/reboot the machine, GPU Sentinel requires sudo permissions or sudo-less shutdown.
  • Currently only working on Linux, can add Windows support if there's interest.

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_sentinel-0.1.4.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

gpu_sentinel-0.1.4-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file gpu_sentinel-0.1.4.tar.gz.

File metadata

  • Download URL: gpu_sentinel-0.1.4.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for gpu_sentinel-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c25eb6c75fd538f2b60fa9b95ad77abfa1227da452b51e91b943ea04a7ecc946
MD5 b99577ac5e86e250cfc2201c0fc39bfb
BLAKE2b-256 eec4c6bf93bd41397ce7a10ca9e9b18c9f69f355ad1a4b666c1eba09b8ea95b7

See more details on using hashes here.

File details

Details for the file gpu_sentinel-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for gpu_sentinel-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 615abff10bc5769e506f72d1653753c910b3251001293d9892de84772f6ac5a5
MD5 5da8fb671bf77f90d851f34484804c63
BLAKE2b-256 a810f1bf2b11227ed2a5632ecda66df2495dfbb7c546d73113c87bfff548be08

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