Extraltodeus/ComfyUI-AutomaticCFG

Extreme Slowdown

Closed this issue ยท 10 comments

Since the most recent update only the first pass of my workflow runs sped up, the second pass already comes to a screeching halt at step one of the second pass due to capping my vram. No matter which auto-cfg node I tried the result was the exact same. Even with the new node and preset setting to "old auto-cfg" it did not change anything.
No error messages, nothing in the console, no difficulties installing/updating the nodes.
All I could observe was the vram getting overloaded by seemingly not being released as usual after the first pass. Deleting the node and starting the queue again does not solve the issue, as the vram retention seems to stay until restart. Even when manually using the "Cleanup Of GPU Usage" in the right-click context menu from the easyuse node to release the vram and starting a new queue without any auto-cfg node it still runs into the same issue at the second pass.

That is strange! I have no such issue so I need more elements in order to help you. Do you have the same problem if you do not use the node at all for example? Which UI do you use? Forge or Comfy? Are you all up to date?

I'm using comfyui and I'm all updated. When not using the node at all everything is fine. But as soon as I run it even once it will require a restart to get the vram overload issue handled. And no errors whatsoever, it just slows down as you'd expect from running out of vram and proceeds with absurd slowness where even canceling takes about a minute to actually happen. When you keep an eye on your vram during a multi-pass workflow, even in a setting without overloading the vram it does still go up higher with the node than without. I might be able to build a workflow that just about runs, but runs slower with the node than without to illustrate that, if it's helpful. Got 16gb vram with a 4080, everything up to date btw. if that's relevant.

I am also getting my VRAM maxed out when this is enabled. Just using this node
image

Enabled followed by disabled

image

Yep, same here. Narrowed it down to this node. Use my workflow here: https://civitai.com/models/423960
Disable the AutomaticCFG node before running, and use InstantID. Works fine. Enable AutomaticCFG, get OOM, or extreme slowdown. Something got borked from today's updates somehow, and it only seems to be affecting InstantID from my tests.

โš ๏ธ Edit: I just noticed this is happening when applying ControlNet models in general. You can see in the screenshot above that @djbielejeski was applying ControlNet as well.

I tried it again after replacing the "Automatic CFG" node with "Automatic CFG - Preset Loader" and had the same issue.

I use Automatic CFG in most of my workflows because it's indispensable. I'm sure you'll have this sorted in no time!

@Extraltodeus Can confirm the problem, it's a memory leak from all deepcopy(cond)/deepcopy(uncond) calls inside nodes.py.

Inside sampling_function_patched replacing

    cond_copy   = deepcopy(cond)
    uncond_copy = deepcopy(uncond)

with

    cond_copy   = cond
    uncond_copy = uncond

helps. Not sure if it breaks something. Also there are some deepcopy(cond_pred) calls, but I'm not sure if those are causing memory leakage too.

Should be fixed now, can you try?
@pamparamm Thank you :D

It's working for me now!

Awesome! I close the ticket! ๐Ÿ˜