Nodes/ComfyUI-MemoryManagement/VRAM Optimizer ⚡
ComfyUI Node

VRAM Optimizer ⚡

The 'make the GPU drop everything' button

By kaaskoek232·Created about a year ago·Updated 3 months ago· 7
VRAM Optimizer ⚡
    • optimization_report
    • memory_freed
    • success
    • recommendations
    trigger0
    optimization_levelModerate
    reset_peak_statstrue
    target_device-1

    You know that feeling when a big upscale or a video gen comes along and your 12GB card goes "nope," or the second image in a batch dies with a CUDA out-of-memory error? VRAM Optimizer is the pack's answer to that - a manual "please free up the GPU" button you can drop anywhere in your graph. It won't manufacture VRAM you don't have, but it gets you back to work without a full ComfyUI restart.

    It's one of seven nodes in the kaaskoek232/ComfyUI-MemoryManagement pack, and the whole pack is really one idea: ComfyUI already manages model offloading itself, but long sessions still accumulate garbage and cached models you don't need anymore. This node is the manual version of that housekeeping, with a report at the end so you know what you got back.

    How it works

    When you fire it, the node runs a cleanup pass on your GPU. The trick is that the level you pick changes how deep it goes:

    • Conservative - just torch.cuda.empty_cache() and a sync. The bare minimum.
    • Moderate (default) - adds a garbage collection pass, then clears the cache again.
    • Aggressive - also tells ComfyUI itself to unload its cached models via comfy.model_management.unload_all_models() and soft_empty_cache(), then does three cleanup passes. This is the one that actually hands VRAM back.

    That ComfyUI integration is the part worth knowing. A bare empty_cache() only releases PyTorch's cached blocks; it doesn't touch the models ComfyUI is holding in VRAM for reuse. If you want real headroom before a heavy step, you want at least Moderate, and honestly often Aggressive.

    The inputs that matter

    • trigger (INT) - bump this number to run the optimization. It's the "button."
    • optimization_level - Conservative / Moderate / Aggressive, default Moderate. This is the knob you'll actually turn.
    • reset_peak_stats (BOOLEAN, default true) - resets PyTorch's peak-memory accounting. Leave it on unless you're benchmarking; otherwise your "peak usage" numbers carry stale history.
    • target_device (INT, optional, default -1) - -1 means all GPUs; set 0–7 to target one. Only relevant on multi-GPU rigs.

    Outputs

    Four outputs, all just reporting: optimization_report and recommendations (STRING - wire them into a text display node if you like reading about your own GPU), memory_freed (INT, bytes freed), and success (BOOLEAN). success is the one you could conceivably wire into logic - gate the next step on whether the cleanup actually ran.

    Installing it

    This pack is light - no model downloads, and its only real dependency is psutil (it ships with requirements.txt that pins psutil>=5.9.0 and torch, and you already have torch). ComfyUI Manager → search "Memory Management" → Install → restart ComfyUI. Or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kaaskoek232/ComfyUI-MemoryManagement
    pip install -r ComfyUI-MemoryManagement/requirements.txt
    # restart ComfyUI
    

    One gotcha while you're at it: the pack's own README "Quick Deployment" block has a broken clone URL pointing at ComfyUI/ComfyUI-MemoryManagement, which doesn't exist. Use the kaaskoek232 URL above.

    Common issues

    • "CUDA not available - VRAM optimization skipped" - the node returns success: false and this message if your torch build has no CUDA. Fix is a CUDA-enabled PyTorch install (the README suggests pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118).
    • It didn't free as much as I expected - normal. The cache may already have been empty; the real release happens at Aggressive when ComfyUI unloads models. And whatever you unload, the next generation has to reload, so fire this between runs, not in the middle of one.
    • "Invalid target device" - you typed a device index that doesn't exist. Check nvidia-smi.

    Is it the one node you'd reach for? For most people it's a nice-to-have, not a fix for a fundamentally too-small card. But if you batch a lot of generations and dread the OOM wall, an Aggressive pass at the end of each run keeps things predictable.

    CategoryMemory Management

    Inputs (4)

    NameTypeDefaultDescription
    triggerINT00–1000000
    optimization_levelCOMBOModerate3 options: Conservative, Moderate, Aggressive
    reset_peak_statsBOOLEANtrue
    target_deviceoptINT-1-1–7

    Outputs (4)

    NameTypeDescription
    optimization_reportSTRING
    memory_freedINT
    successBOOLEAN
    recommendationsSTRING