Running a Stable Diffusion pipeline
Now that you have installed all the dependencies, it is time to run a Stable Diffusion pipeline to test whether the environment is correctly set up. You can use any Python editing tool, such as VS Code or Jupyter Notebook, to edit and execute Python code. Follow these steps:
- Install the packages for Hugging Face Diffusers:
pip install diffusers
pip install transformers scipy ftfy accelerate
- Start a Stable Diffusion pipeline:
import torch
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
torch_dtype=torch.float16)
pipe.to("cuda") # mps for mac
If you are using a Mac, change
cuda
tomps
. Even though macOS is supported and can generate images using the Diffusers package, its performance is relatively slow. As a comparison, an NVIDIA RTX 3090 can achieve about 20 iterations per second to generate one 512x512...