# Why is diffusers so much slower than ComfyUI?

**URL:** <https://discuss.huggingface.co/t/why-is-diffusers-so-much-slower-than-comfyui/51145>\
**Category:** 🧨 Diffusers\
**Created:** [August 17, 2023, 7:13pm UTC](https://discuss.huggingface.co/t/why-is-diffusers-so-much-slower-than-comfyui/51145 "2023-08-17T19:13:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlfaPapa](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@AlfaPapa](https://discuss.huggingface.co/u/AlfaPapa)\
**Post date:** [August 17, 2023, 7:13pm UTC](https://discuss.huggingface.co/t/why-is-diffusers-so-much-slower-than-comfyui/51145/1 "2023-08-17T19:13:17Z")

</div>

Hi,

I’m new to Stable Diffusion and currently try to gain some understanding by using diffusers and ComfyUi. What puzzles me is the performance difference between diffusers and ComfyUI. Running the example code below, one iteration takes about 15s. Using ComfyUI one iteration takes about 1s. (In both pipelines I’m using 1024x1024 as resolution.)

Any idea why there might be such a huge difference?

I tried some of the hints given in the [OPTIMIZATION/SPECIAL HARDWARE chapter in the Docs](https://huggingface.co/docs/diffusers/optimization/opt_overview)

torch.compile does not work under Windows  
xFormers also does not give the expected boost  
Means, there is no difference between using

> enable\_xformers\_memory\_efficient\_attention()

and not doing so.

```auto
from diffusers import StableDiffusionXLPipeline
import torch

pipe = StableDiffusionXLPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
)
pipe.to("cuda")
pipe.enable_xformers_memory_efficient_attention()

prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
image = pipe(prompt=prompt).images[0]

```

So any hint is appreciated.

AlfaPapa

---

<div class="post-metadata">

**Author:** ![AlfaPapa](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@AlfaPapa](https://discuss.huggingface.co/u/AlfaPapa)\
**Post date:** [August 18, 2023, 7:33pm UTC](https://discuss.huggingface.co/t/why-is-diffusers-so-much-slower-than-comfyui/51145/2 "2023-08-18T19:33:40Z")

</div>

Got it 😀

> enable\_model\_cpu\_offload()

really boosts it! In my case from 15s/it to 1s/it

See [Speed up inference](https://huggingface.co/docs/diffusers/optimization/fp16#model-offloading-for-fast-inference-and-memory-savings)

---

<div class="post-metadata">

**Author:** ![Grasho](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@Grasho](https://discuss.huggingface.co/u/Grasho)\
**Post date:** [October 12, 2023, 7:40pm UTC](https://discuss.huggingface.co/t/why-is-diffusers-so-much-slower-than-comfyui/51145/3 "2023-10-12T19:40:13Z")

</div>

Im on a laptop 3060 and its incredibly slow. Is anybody still here , can I get some help with how to do this please

---

<div class="post-metadata">

**Author:** ![Fidika](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@Fidika](https://discuss.huggingface.co/u/Fidika)\
**Post date:** [May 3, 2024, 1:54am UTC](https://discuss.huggingface.co/t/why-is-diffusers-so-much-slower-than-comfyui/51145/4 "2024-05-03T01:54:17Z")

</div>

Xformers really makes the difference here. On my local machine with only 8 GBs of VRAM this one line:

pipe.enable\_vae\_tiling()

reduced inference time from 117 seconds to 40 seconds.
