# Generating an image is really slow

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerating-an-image-is-really-slow%2F101549%3E%5C
**Category:** Beginners\
**Created:** [August 8, 2024, 4:43pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerating-an-image-is-really-slow%2F101549 "2024-08-08T16:43:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jthulhu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jthulhu/32/30331_2.png) [@jthulhu](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjthulhu)%5C
**Post date:** [August 8, 2024, 4:43pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerating-an-image-is-really-slow%2F101549%2F1 "2024-08-08T16:43:54Z")

</div>

# Some context

I’m trying to generate an image from a textual prompt, and compare the various options available for this task, because I am very new to this, so I don’t know which one is most fit to my use case. I’d like to avoid having to train anything myself, and rather resort to a off-the-shelf solution. If I understood correctly, this is roughly what pretrained models available on the hugging face hub are for. I tried downloading one (chosen more or less at random, I picked [alvdansen/phantasma-anime · Hugging Face](https://huggingface.co/alvdansen/phantasma-anime)), but I didn’t manage to actually load it and run it with a prompt to get an image out of it (all the `from_pretrained` class methods I’ve tried want a JSON config file, not a safetensors file). So, I started with a simpler task, to simply run on my computer the example given [in the documentation of text-to-image diffusers](https://huggingface.co/docs/diffusers/en/api/pipelines/stable_diffusion/text2img):

```python
import torch
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
image = pipe("an image of an astronaut riding a horse on Mars").images[0]

```

# The problem

I’m doing this on a laptop that doesn’t have a (dedicated) GPU, so I knew that I wouldn’t have the results right away, but I expected a single iteration to be performed _at most_ in a couple of minutes. Yet, after ten minutes, a single iterations hasn’t finished.

I was wondering if it was normal that this task is _that_ long, considering that it defaults to 50 iterations, so that generating a single image at this rate would take _at least_ 9 hours.

# Specs

For information, my CPU’s model is i7-1260P. The environment, as spit out by `transformers-cli env`, is

- `transformers` version: 4.43.3
- Platform: Linux-6.6.43-x86\_64-with-glibc2.39
- Python version: 3.11.9
- Huggingface\_hub version: 0.24.2
- Safetensors version: 0.4.3
- Accelerate version: 0.32.0
- Accelerate config: not found
- PyTorch version (GPU?): 2.3.1 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed

Also, during the generation of the image, I noted that it mostly uses only two cores, although it occasionally uses all the 16 cores. I was wondering whether there was a way to make it use more aggressively the resources of my machine.
