A "Plug-and-Play" VRAM Optimizer for Any AI Application 一个即插即用的 AI 显存优化神器
"Don't let OOM (Out Of Memory) stop your creation." “别让显存不足阻挡你的创造力。”
Universal GPU Offloader is a lightweight, non-invasive launcher script designed to fix CUDA out of memory errors for almost ANY AI application (Stable Diffusion WebUI, ComfyUI, LLM WebUI, etc.).
It acts as a "wrapper" or "injector". You don't need to modify your existing AI software. Just run this launcher, select your target start.bat, and it will magically inject optimized environment variables to prevent crashes.
它是一个通用的“外挂式”显存优化启动器。 不管你在用什么 AI 软件(如 SD WebUI, ComfyUI, LLM 等),只要它报显存不足(OOM),你就用这个启动器来打开它。它会自动注入“显存碎片整理”、“模型卸载到内存”等救命指令,让 8G 甚至 6G 显卡也能跑大模型。
- Universal Compatibility (全能兼容): Works with A1111 WebUI, ComfyUI, Fooocus, Oobabooga, and standalone Python scripts.
- 支持市面上绝大多数 AI 整合包。
- Zero-Config (零配置): No code changes required. Just click and run.
- 无需修改代码,点击即用。
- Two Powerful Modes (两大核心模式):
- 🚀 Smart Offload Mode (
Select_And_Run.bat- 智能流式模式):- Enables PyTorch memory fragmentation fix (
expandable_segments).- 开启显存碎片整理,最大限度利用显存空隙。
- Enables CUDA Lazy Loading (saves ~1GB VRAM on start).
- 开启 CUDA 懒加载,启动时立省约 1GB 显存。
- Forces
fp16precision to halve VRAM usage.- 强制半精度计算,显存占用直接减半。
- Injects
--lowvram/--medvramarguments automatically.- 自动注入低显存参数,强迫程序将数据卸载到内存。
- Enables PyTorch memory fragmentation fix (
- 🛡️ CPU Only Mode (
CPU_Only_Mode.bat- 纯 CPU 保底模式):- The "Nuclear Option". Completely hides your GPU.
- “核弹级”保底方案。彻底禁用显卡。
- Forces the app to run on System RAM (24GB+) + Virtual Memory.
- 强制程序在 24GB+ 内存和 100GB+ 虚拟内存上运行。
- Guaranteed to run (eventually) without crashing, even for 70B+ models.
- 绝对不会崩(只要硬盘够大),哪怕是 70B 超大模型也能跑(虽然会很慢)。
- The "Nuclear Option". Completely hides your GPU.
- 🚀 Smart Offload Mode (
- Download this repository. (下载本项目)
- Double-click
Select_And_Run.bat. (双击运行) - A file selection window will pop up. (弹出文件选择窗口)
- Navigate to your AI software folder and select its startup file (e.g.,
webui-user.bat,run_nvidia_gpu.bat). (找到你的 AI 软件启动文件并选中) - Sit back and watch it run without OOM errors! (享受不爆显存的体验!)
- Double-click
CPU_Only_Mode.bat. (双击运行 CPU 模式脚本) - Select your target file. (选择目标启动文件)
- The app will run in pure CPU mode. It will be slow, but it will never crash due to VRAM. (程序将以纯 CPU 模式运行。速度慢,但永不崩溃。)
To fully utilize the CPU Only Mode or handle extremely large models, you MUST configure your Windows Virtual Memory (Pagefile) correctly. 为了让 CPU 模式 发挥最大威力,或者运行超大模型,你 必须 正确设置 Windows 的虚拟内存(分页文件)。
Step-by-Step Guide (设置步骤):
- Right-click "This PC" -> Properties.
- 对着桌面上的 “此电脑” 图标点右键 -> 选择 “属性”。
- Click "Advanced system settings".
- 点击 “高级系统设置”。
- Go to the "Advanced" tab -> Click "Settings" under Performance.
- 切换到 “高级” 选项卡 -> 点击 “性能” 栏目下的 “设置” 按钮。
- Go to the "Advanced" tab (again) -> Click "Change..." under Virtual memory.
- 在弹出的窗口中再次切换到 “高级” 选项卡 -> 点击 “虚拟内存” 栏目下的 “更改...” 按钮。
- Uncheck "Automatically manage paging file size for all drives".
- 取消勾选 “自动管理所有驱动器的分页文件大小”。
- Select a drive with plenty of space (e.g., D: or E:).
- 选中一个空间充足的硬盘分区(建议 D 盘或 E 盘,最好是 SSD)。
- Select "Custom size".
- 选择 “自定义大小”。
- Enter the values (1GB = 1024MB):
- 输入数值(注意:1GB = 1024MB):
- Initial size (初始大小):
32768(32GB) or more. - Maximum size (最大值):
102400(100GB) or more (Depend on your disk space).- 建议填入
100000(约 100GB) 以确保万无一失。
- 建议填入
- Click "Set" -> "OK". Restart your computer.
- 务必点击“设置”按钮 -> 然后点“确定”。最后重启电脑生效。
This launcher injects the following Environment Variables before starting the child process: 本启动器在启动子进程前注入了以下环境变量:
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True,max_split_size_mb:128- Fixes memory fragmentation (解决显存碎片化)
CUDA_MODULE_LOADING=LAZY- Reduces startup VRAM overhead (开启懒加载,减少启动开销)
ACCELERATE_MIXED_PRECISION=fp16- Forces lower precision for memory savings (强制半精度)
COMMANDLINE_ARGS=--lowvram --medvram- Tells WebUI apps to be gentle (告诉 WebUI 开启低显存模式)
CUDA_VISIBLE_DEVICES=-1- (CPU Mode Only) Hides the GPU (仅 CPU 模式:隐藏显卡)
MIT License. Free to use, modify, and distribute.
Made with ❤️ for the AI Community.