A utility to automatically kill vLLM processes and release GPU memory.
Project description
vLLM Cleaner 🧹
一个轻量级的 Python 实用工具,用于在 LLM 评测或训练任务结束后,自动清理 vLLM 进程并彻底释放 GPU 显存。
💡 为什么需要这个工具?
在使用 vLLM 框架进行大模型推理、评测或训练时,经常会遇到以下痛点:
- 脚本执行完毕或因代码报错崩溃后,vLLM 进程依然在后台残留(僵尸进程)。
- GPU 显存被持续占用,导致后续的实验抛出
CUDA Out of Memory错误。 - 每次都需要手动运行
lsof或netstat查端口,再kill -9,费时费力。
vLLM Cleaner 通过一行代码(装饰器)完美解决这个问题。无论是程序正常结束、异常报错,还是被手动 Ctrl+C 中断,它都能顺藤摸瓜找到占用端口的进程树,并将其彻底连根拔起。
✨ 特性
- 极简接入:只需在主函数加上
@auto_kill_vllm(port=...)装饰器即可。port参数是vllm服务的端口。 - 全场景覆盖:基于
try...finally和系统信号(SIGINT/SIGTERM)监听,防崩溃、防中断。 - 斩草除根:自动解析占用指定端口的父进程 PID,并递归杀掉所有子进程,确保显存 100% 释放。
- 自动安装依赖:通过 pip 安装时,会自动配置所需的
psutil库。
📦 安装
你可以直接通过 GitHub 源码一键安装(已包含自动处理依赖):
pip install git+[https://github.com/](https://github.com/)<你的GitHub用户名>/vllm-cleaner.git
🚀 快速开始 (Quick Start)
from vllm_cleaner import auto_kill_vllm
# 在此处传入你的 vLLM 服务实际占用的端口号
@auto_kill_vllm(port=30338)
def main():
print("🚀 开始执行大模型评测/训练任务...")
# 这里是你的业务逻辑,比如启动 vLLM 服务、跑数据等
# ...
print("✅ 任务执行完毕!")
if __name__ == "__main__":
main()
print("🧹 此时 main 函数已结束,vLLM 进程已被全自动清理,显存已清空!")
# 后续可以继续执行不需要 GPU 的代码...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
vllm_cleaner-0.1.0.tar.gz
(3.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vllm_cleaner-0.1.0.tar.gz.
File metadata
- Download URL: vllm_cleaner-0.1.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01f9e44bebaef3995ed9907588504c4dc7e166a48be69ec9fa5674b2380e95a2
|
|
| MD5 |
42ca42e7b7064febafc6d90f2d2a3aaa
|
|
| BLAKE2b-256 |
e0876f629bcd555c77bba5c90244fa429ce9d8d7fc929b7cb301d5d679a7d347
|
File details
Details for the file vllm_cleaner-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vllm_cleaner-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b78eb0416824dfeb268ca5b7ecca25438fe142449ffdee4c6683137b50c2e776
|
|
| MD5 |
7e4b62f1aa472f662eb4efd82ac0a93d
|
|
| BLAKE2b-256 |
d1d4a5107c3409e3c0e78678103e5d371c81ed481b0600541ddbcc23216cef25
|