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

Free VRAM If Loaded

Purge the video model so your image job actually fits

By mickmumpitz·Created 8 months ago·Updated 9 days ago· 47
Free VRAM If Loaded
      if_loadedltx

      The classic ComfyUI trap when you run video and image models on one GPU: the video model is huge, it stays resident after the last frame, and your next image prompt either reloads everything (slow) or dies with an OOM. Free VRAM If Loaded exists to make that swap explicit - it's the "video side" of the conditional VRAM pair in Mickmumpitz-Nodes, and it fires when a model you name is currently sitting in VRAM.

      Like its sibling Free VRAM Unless Loaded, this is a config marker: you drop it on the graph, type a pattern, and don't wire anything. Its single input is if_loaded, defaulting to ltx. When you queue a prompt and that pattern shows up in VRAM, the node unloads everything and empties the caches before execution starts. So if LTX is hogging the card after your video pass, this makes sure the next job starts with a clean slate.

      How it works

      The magic happens in a PromptServer handler registered at import time - the same queue-time mechanism the sibling uses, but with inverted logic:

      • FreeVRAMIfLoaded: unload all models when the pattern is present in VRAM.
      • FreeVRAMUnlessLoaded: unload all models when the pattern is not present.

      Matching is a lowercase substring check against the class names of every loaded model (current_loaded_models). Default is ltx, which matches LTX Video's model classes; you'd set wan for Wan. When it fires it runs unload_all_models(), soft-empties the cache, garbage-collects, and calls torch.cuda.empty_cache().

      The queue-time design has a real payoff: because the node never executes as part of the dataflow, it stays out of cache keys. Your cached video outputs are untouched, and cleanup still happens even when every downstream node cache-hits - which is exactly when a stuck VRAM blob would otherwise bite you.

      How to use it

      The pattern is two-sided. Put Free VRAM If Loaded (with ltx or wan) somewhere in your video workflow, and Free VRAM Unless Loaded (with flux) in your image workflow. After the video pass finishes, If Loaded purges the video weights; unless the image model is already resident, Unless Loaded purges whatever's left. Together they keep one card swapping between model families without you babysitting it.

      A couple of practical notes. Set the pattern to the model family, not a filename - substring matching works on class names, and GGUF wrappers can rename those, so verify with a quick test run if your quantized model doesn't seem to trigger it. And remember neither node loads anything; they only free. The loader downstream still does its job.

      Installing

      Install the whole pack once - ComfyUI Manager, search "Mickmumpitz", install, restart. Or clone it manually:

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

      Requirements are numpy, Pillow, and opencv-python - no model downloads, no heavy extras. This pack is the work of Mickmumpitz, a YouTuber who builds character-sheet and iterative-video workflows; his setups are powerful but fiddly, and these two VRAM nodes are the unglamorous bits that keep them running.

      CategoryMickmumpitz/Utils

      Inputs (1)

      NameTypeDefaultDescription
      if_loadedSTRINGltx

      Outputs (0)

      No outputs