Skip to main content

自动维持 GPU SM 利用率守护进程,防止任务被强杀

Project description

gpu-keepalive

自动维持 GPU SM 利用率 ≥ 40%,防止任务被集群强杀。
任务真正运行时自动让路,支持混卡环境(V100 / A100 / H100 / B200 …)。

安装

pip install gpu-keepalive

或直接从 Git 仓库安装:

pip install "git+https://github.com/mmmwhy/gpu-keepalive.git"

本地开发:

git clone https://github.com/mmmwhy/gpu-keepalive.git
cd gpu_keepalive
pip install -e .

快速使用

# 守护所有 GPU,默认阈值 40%
gpu_keepalive go

# 只守护 GPU 0 和 1
gpu_keepalive go --gpus 0,1

# 守护 GPU 0~3,自定义阈值
gpu_keepalive go --gpus 0-3 --min 40 --target 50

# 查看当前各卡利用率
gpu_keepalive status

# 列出系统所有 GPU 信息
gpu_keepalive list

参数说明

参数 默认 说明
--gpus all GPU 编号,支持 0,1,30-3all
--min 40 SM 利用率低于此值时启动占位 kernel
--target 50 占位 kernel 的目标利用率
--interval 2.0 采样间隔(秒)

工作原理

  1. interval 秒查询一次各卡 SM 利用率
  2. 利用率 < --min 时,启动占位 kernel(fp16 矩阵乘法),通过 PI 控制器将利用率稳定在 --target
  3. 检测到真实负载(利用率 ≥ --min)时,立刻停止占位 kernel,彻底让路
  4. 自动识别 GPU 型号,按 V100 / H100 / B200 等选择合适的矩阵规模

依赖

  • Python ≥ 3.10
  • PyTorch ≥ 2.0(需要 CUDA 版本)
  • pynvml ≥ 11.0

推荐使用方式

# 放入 tmux / screen,挂在后台
tmux new -s keepalive
gpu_keepalive go --gpus all
# Ctrl-B D 分离,自由 debug

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_keepalive-0.1.2.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpu_keepalive-0.1.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file gpu_keepalive-0.1.2.tar.gz.

File metadata

  • Download URL: gpu_keepalive-0.1.2.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gpu_keepalive-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4f62cfa0dd8b8d45656eb6d23c1f3ae0fa7d4befd977869ab0fd2291f91bf253
MD5 5ca7cb3d25be0f4398580a67a0022814
BLAKE2b-256 f525fdae8094c4cb84c894743c7bef84860b5c4cd8198d71ce8a6f9a705fb975

See more details on using hashes here.

File details

Details for the file gpu_keepalive-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: gpu_keepalive-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gpu_keepalive-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 96ee103536e5a9b9a0153dd29c57cfbad4a2082a9925272330d6d4cb65c721e0
MD5 7093b641cd9765eb7aaf5fe2447e00b8
BLAKE2b-256 af567f7aaeea5344fb184f8525527deed9a9424c2c58df826e0e4311c8c342e0

See more details on using hashes here.

Supported by

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