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 的代码...
Metadata
Release files for vllm-cleaner 0.1.0
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 | |
|---|---|---|---|---|
| vllm_cleaner-0.1.0.tar.gz | 3.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vllm_cleaner-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.6 kB
Release files / vllm_cleaner-0.1.0.tar.gz
| Download URL | vllm_cleaner-0.1.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01f9e44bebaef3995ed9907588504c4dc7e166a48be69ec9fa5674b2380e95a2
|
|
BLAKE2b-256 checksum How to use checksums |
e0876f629bcd555c77bba5c90244fa429ce9d8d7fc929b7cb301d5d679a7d347
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / vllm_cleaner-0.1.0-py3-none-any.whl
| Download URL | vllm_cleaner-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b78eb0416824dfeb268ca5b7ecca25438fe142449ffdee4c6683137b50c2e776
|
|
BLAKE2b-256 checksum How to use checksums |
d1d4a5107c3409e3c0e78678103e5d371c81ed481b0600541ddbcc23216cef25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Security for vllm-cleaner 0.1.0
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.