comfyanonymous / ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.
https://www.comfy.org/
GNU General Public License v3.0
58.94k stars 6.25k forks source link

RAM issue #3257

Open BornSaint opened 7 months ago

BornSaint commented 7 months ago

I gave up to implement a way to free the memory. I tried use /free, but nothing happens, tried calll the functions manually, nothing happens again.

Comfy already have implementations to unload models, but don't work like i would like.

The situation is that: --normalvram: the model unload from VRAM but still in RAM and /free don't unload the model from RAM. --highvram: the model unload from RAM, but still in VRAM and /free don't unload the model from VRAM.

I want to totally unload the models even if it make the next run slower. the scenario is: i have a workflow to make animations, and i want to run SDXL once, then unload it totally, then play animateDIff with the generated image.

There's another problem: When loading to RAM, it don't use my SWAP, fulfilling all my RAM and then freezing my system. I already made stress tests in my RAM, the system looks fine to manage it and don't let it full, also already set vm.swappiness=100

The problem seems to be comfyui implementations.

torch.cuda.empty_cache() does nothing when --highvram the functions from ComfyUI API to unload models called in the custom node "VRAM Debug" from "KJNodes for Comfy" does nothing at all. The same happens to ComfyUI Manager "unload models" button.

When i start the ComfyUI there's no RAM or VRAM allocated, but after the first run, it stay allocated in RAM or VRAM until kill the UI in terminal.

I want the /free working properly to make the RAM and VRAM come back to the statement before the first run.

J-Cott commented 7 months ago

How much Ram and Vram do you have? I have never had these issues.

BornSaint commented 7 months ago

How much Ram and Vram do you have? I have never had these issues.

16gb RAM and 12gb VRAM

GeLi1989 commented 7 months ago

I get same problem here.

ZeroYuJie commented 6 months ago

I have also encountered this problem, and I used efficiency-nodes-comfyui to load model,I don't know if the two are related.

molkemon commented 4 months ago

Can confirm, starting comfy with <1gb vram usage. My workflow then fills up almost all of the available 24gb. After generation (when doing vae decode), some models are clearly unloaded because vram usage drops, and then drops again after vae decode is finished, but ~8gb of vram remain used.

Using KJs VRAM Debug node does nothing, the usage will remain the same. Only killing comfy in terminal frees up the VRAM completely. This is in WSL Ubuntu with git pulled from like yesterday and using torch 2.5+cuda 2.4 nightly.