Nodes/Mickmumpitz-Nodes/Free VRAM Unless Loaded
ComfyUI Node

Free VRAM Unless Loaded

Stop reloading Flux every time you switch models

By mickmumpitz·Created 8 months ago·Updated 9 days ago· 47
Free VRAM Unless Loaded
      unless_loadedflux

      If you bounce between video models and image models on the same card, you know the routine: queue a Flux job, watch it purge your LTX weights, then OOM anyway because a stray sampler still had something pinned. Free VRAM Unless Loaded is the pickier half of a two-node VRAM management pair in Mickmumpitz-Nodes that fixes exactly that.

      Here's the trick that makes it interesting: it runs at queue time, not execution time. When you hit Queue, a hidden prompt handler walks your graph, checks what's actually in VRAM right now, and if the thing you asked about isn't there, it unloads every model and empties the CUDA caches before your prompt starts. The name says it all - it frees VRAM unless the model you name is already loaded.

      How it works

      You give it one input: unless_loaded, a string that defaults to flux. At submit time the handler matches that pattern against the class names of every model currently loaded (comfy.model_management.current_loaded_models). If it finds nothing containing flux, it runs unload_all_models(), soft-empties the cache, runs a garbage collect, and calls torch.cuda.empty_cache().

      Two details are worth knowing. First, it's a config marker, not a dataflow node - it has no outputs and needs no wires. You just drop it on the graph and set the string. Second, because cleanup happens in the prompt handler rather than during node execution, the node never appears in any downstream node's cache key. Your cached generation outputs don't get invalidated when the cleanup state flips between runs. That's the whole point of the design and it's a nice piece of engineering.

      Why you'd reach for it

      This is the "image side" of a model-swap workflow. Say you generate video with LTX, then want a Flux image. Leave unless_loaded set to flux:

      • First run: Flux isn't loaded yet → everything is freed → the Flux loader has room.
      • Next run: Flux is already resident → the node no-ops → no pointless unload/reload churn.

      Its sibling Free VRAM If Loaded is the mirror image: it frees when the pattern is present, so you'd use it with something like ltx after the video pass finishes. People typically use both in the same workflow.

      Inputs

      • unless_loaded (STRING) - a substring to match against loaded model class names. flux is the default and a good starting point. Keep it short: wan or ltx works for video families. This is the only setting.

      Installing

      The whole pack installs at once via ComfyUI Manager - search for "Mickmumpitz" and hit install, then restart. Or manually:

      cd ComfyUI/custom_nodes
      git clone https://github.com/mickmumpitz/ComfyUI-Mickmumpitz-Nodes
      

      The pack's real dependencies are just numpy, Pillow, and opencv-python, which you almost certainly already have. Nothing to download.

      Gotchas

      The matching is substring-based on class names, so if you run a quantized GGUF wrapper whose class name doesn't contain "flux", the pattern won't match and you'll get more purging than you bargained for. Also remember the node only frees - it never loads. Your model loader still does the work of bringing the next model in. One light aside: if nothing seems to happen at all, check you actually typed the pattern into this node's widget and not the sibling's - they're one letter apart and I've confused myself exactly once.

      CategoryMickmumpitz/Utils

      Inputs (1)

      NameTypeDefaultDescription
      unless_loadedSTRINGflux

      Outputs (0)

      No outputs