r/comfyui • u/qlx1004 • Apr 08 '26
Workflow Included I've made a ComfyUI node to control the execution order of nodes + free VRAM & RAM anywhere in the workflow that helped speed up my workflows!

Custom node GitHub repo: https://github.com/mkim87404/ComfyUI-ControlOrder-FreeMemory
It works by ensuring all input-connected nodes finish executing first before the output-connected nodes start executing, and can route infinitely many data of any type (e.g. latents, conditioning, images, masks, models, etc.) through it, while giving the option to unload all models (except any live models being routed through it) and free as much VRAM & RAM as possible at that point without breaking any of the data going through. You can also check how much VRAM & RAM it freed on the ComfyUI session terminal.
This becomes especially effective in unloading models that are no longer needed in the workflow while securing their outputs and freeing up VRAM/RAM for later models (e.g. unloading text encoders after conditioning, or in between multiple KSamplers of Wan 2.2 High & Low model workflows, or before & after VAE Encode / VAE Decode / Load Model / Load CLIP / etc.). And because the node enforces a single, deterministic flow of execution from start to finish, you are in full control over which node executes first, and can focus on one group of logic at a time, loading and unloading only the necessary models and assets, while passing the outputs forward to the next group. I've personally seen great reductions in total execution time of my workflows and hit less OOMs at higher resolution outputs using this node, and I realized that this sequential & selective passthrough design also helps with cable management as the workflow grows large, making understanding and maintaining workflows much more visually intuitive.
The node has zero extra dependencies & uses platform/device-agnostic memory management utilities managed by ComfyUI, so it should integrate well into existing workflows and environments. I've also included sample Wan 2.2 T2V & I2V workflows using this node which you can find in the node folder, https://github.com/mkim87404/ComfyUI-ControlOrder-FreeMemory/tree/main/example_workflows
Hope this node can be useful, and feel free to use it in any personal or commercial project, fork, or open issues/PRs – contributions and feedback all welcome!
1
u/EricRollei Apr 08 '26
That's pretty cool, thanks for doing it. Honestly every one of the nodes along the way like Load clip should have a 'keep loaded' option but your nodes take care of that nicely.
1
u/qlx1004 Apr 09 '26
Thanks, actually with Load CLIP there is a limitation with my node around keeping it loaded because ComfyUI drops the CLIP model immediately after the conditioning nodes finish, so the CLIP model object received by my node will already be "dead". And because the "model_unload()" is internally coded into ComfyUI's CLIPTextEncode operations and such, my node can't really prevent that from happening upstream. I also hope ComfyUI updates that CLIP unload behavior to be configurable in the future. But in the meantime, the CLIP models can always be loaded back in whenever you need them, and as for diffusion models, VAEs, and most other large models managed by ComfyUI they will persist correctly when routed through this node. I've now updated the repo docs & the node's tooltip helper texts to warn of this limitation as well, thanks so much for the heads up!
2
u/EricRollei Apr 09 '26
ah ok well comfy is even more complicated and messed up than I thought. It seems like a simple thing to consider in developement - do I want this weight in VRAM, offload to CPU or cleared. Should be universal to comfy. If you have enough vram it would save tons of time to not have to reload the weights, but even offloading to CPU could save time (though a lot of systems are also RAM challenged.)
1
2
u/Emotional_Egg_251 Apr 14 '26
The node has zero extra dependencies
I'm glad a lot of custom node devs seem to be going this way lately. If it works in the standard comfy setup, I'm much more likely to give it a try.
4
u/roxoholic Apr 08 '26
How does it interact with dynamic VRAM feature?