Using Google Colab to run a Stable Diffusion pipeline
Here are the detailed steps to start using Google Colab:
- Create a new instance from https://colab.research.google.com/.
- Click Runtime | Change runtime type and select T4 GPU, as shown in Figure 2.4:
Figure 2.4: Selecting GPU in the Google Colab notebook
- Create a new cell and use the following command to check whether the GPU and CUDA are working:
!nvidia-smi
- Install the packages for Hugging Face Diffusers:
!pip install diffusers
!pip install transformers scipy ftfy accelerate ipywidgets
- 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")
- Generate an image:
prompt = "a photo of an astronaut riding a horse on mars,blazing fast, wind and...