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
51.24k stars 5.39k forks source link

Generate an image using SDXL takes 58 times longer when I restart Comfyui #2046

Open TheMoye opened 10 months ago

TheMoye commented 10 months ago

Hello everyone,

For the past few days, when I restart Comfyui after stopping it, generating an image with an SDXL-based checkpoint takes an incredibly long time. If I restart my computer, the initial launch of Comfyui does not have this issue. Generating an image from a model based on SD 1.5 does not have this problem either.

Here is the normal result in my console:

100%|██████████████████████████████████████████████████████████████████████████████████| 25/25 [00:14<00:00, 1.76it/s]

And here is the same generation after cutting and restarting Comfyui:

100%|██████████████████████████████████████████████████████████████████████████████████| 25/25 [14:15<00:00, 34.23s/it]

When Comfyui runs for the first time after a restart, at the time of initiating an image generation, I see the following lines in the console:

model_type EPS
adm 2816
Using pytorch attention in VAE
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
Using pytorch attention in VAE
missing {'cond_stage_model.clip_l.text_projection', 'cond_stage_model.clip_l.logit_scale', 'cond_stage_model.clip_g.transformer.text_model.embeddings.position_ids'}
Requested to load SDXLClipModel
Loading 1 new model
Requested to load SDXL
Loading 1 new model

But after cutting and restarting Comfyui, I only see the following lines:

Requested to load SDXLClipModel
Loading 1 new model
Requested to load SDXL
Loading 1 new model

Does this indicate any particular issue? I updated Comfyui today, but the problem persists.

Thank you for your help!

NeedsMoar commented 10 months ago

It sounds exactly like the mmap issue someone hit last week, lemme find it:

https://github.com/comfyanonymous/ComfyUI/issues/1992#issuecomment-1817797912

That might help. I'd suggest leaving this bug open even if changing the file open line fixes it. If it does fix it, maybe change the bug title to "Issue with slow loading and MMAP'd files" since it's suddenly started popping up for some reason. Otherwise it's something different and maybe somebody else will have ideas.

TheMoye commented 10 months ago

Hello NeedsMoar and thank you for this response,

I went through the linked discussion, but I don't think my issue is similar: The checkpoints I'm using are on my SSD. Loading the checkpoint doesn't seem to take longer than usual. At least in the console, the messages "Requested to load SDXLClipModel" and "Loading 1 new model" don't take more time to appear. It's really during the image generation, for example, when a "KSampler" node is executed, that everything is much slower. In fact, I'm experiencing the slowness of A1111 with an SDXL checkpoint. _ Creating several images while the checkpoint is already loaded remains equally slow.

That being said, I made a discovery. I don't need to restart my computer to resolve this slowness issue. I just need to disable and then re-enable the Python virtual environment.

To summarize:

Does this resonate with anyone?

TheMoye commented 9 months ago

Hello everyone,

I'm facing this problem again today, and it seems that disabling and then re-enabling the Python virtual environment no longer has any effect. 😫 I updated ComfyUI a few minutes ago (using git pull, is there anything else to do afterward?), but it's still unusable. Nevertheless, I attempted @NeedsMoar's solution, but it didn't change anything.

TheMoye commented 9 months ago

It's me again! I'm not sure about what I'm going to propose, but perhaps it's a memory release issue?

I just stopped the ComfyUI server, and in my "Task Manager", I see that "Dedicated GPU Memory" has dropped to 1GB out of 8GB. I think I've noticed that sometimes when stopping the server, the VRAM isn't released below 3GB: those are the times when I need to restart to use ComfyUI again.

ltdrdata commented 9 months ago

It's me again! I'm not sure about what I'm going to propose, but perhaps it's a memory release issue?

I just stopped the ComfyUI server, and in my "Task Manager", I see that "Dedicated GPU Memory" has dropped to 1GB out of 8GB. I think I've noticed that sometimes when stopping the server, the VRAM isn't released below 3GB: those are the times when I need to restart to use ComfyUI again.

Are you using a custom node's detection model by any chance? For the detection model, it might be outside the memory management scope of ComfyUI, so VRAM release may not work properly. Especially for models like SAM, which tend to be relatively large and may not release well from VRAM, Impact Pack provides a separate CPU mode.

TheMoye commented 9 months ago

Are you using a custom node's detection model by any chance? For the detection model, it might be outside the memory management scope of ComfyUI, so VRAM release may not work properly. Especially for models like SAM, which tend to be relatively large and may not release well from VRAM, Impact Pack provides a separate CPU mode.

Hello ltdrdata,

I sometimes use custom nodes like CLIP Vision, SEGS, or Crop Face, but my issue doesn't seem to be related to them. In fact, I've encountered it even while using a very basic workflow that only involves ComfyUI nodes, without any custom ones. However, I haven't tried disabling the loading of all custom nodes yet.

jaywuYJ commented 9 months ago

I've got the same issue here, comfyUI keeps requesting to load model for each image generation which doesn't make much sense. Requested to load SDXLClipModel Loading 1 new model Requested to load SDXL Loading 1 new model

TheMoye commented 9 months ago

I've got the same issue here, comfyUI keeps requesting to load model for each image generation which doesn't make much sense. Requested to load SDXLClipModel Loading 1 new model Requested to load SDXL Loading 1 new model

Hello jaywuYJ,

I don't think the two are related. I also have multiple model loadings, probably related to the workflow I use, without it affecting the generation time:

Capture d'écran 2023-12-19 092319

Here I am using two SDXL Turbo and two SD 1.5, and the generation times are what I expect with my 2080. When I encounter my issue within the same workflow, the generation via SDXL Turbo sometimes runs at 50s/it instead of 1.2it/s, causing the generation time to go from 30 seconds to over 5 minutes.

MisterReally commented 5 months ago

I am also experiencing this issue. ComfyUI portable. I have it pointed to A1111 model folder.