DEV Community

Cover image for How to Run stable-diffusion-3.5-large-turbo on Google Colab
M Sea Bass
M Sea Bass

Posted on

How to Run stable-diffusion-3.5-large-turbo on Google Colab

stable-diffusion-3.5-large-turbo is a high-precision text-to-image model.

This guide will explain how to set up and run the model on Google Colab.


Prerequisites

Visit Huggingface.

Image description

To use stable-diffusion-3.5-large-turbo, you need a Huggingface account.

If you don’t already have one, please create an account.

Once signed up, you’ll see the following screen:

Image description

Enter the required information, and you’ll gain access to the model immediately.

If you wish to download and use the model, you’ll need an access token. Create one from your account page:

Image description

Navigate to your account page via the profile icon in the upper-right corner, go to the Access Token tab, and create a token by selecting Create new token.


Running the Code

Install Required Libraries

First, install the necessary libraries in Google Colab:

!pip install --quiet -U transformers
Enter fullscreen mode Exit fullscreen mode

The -U option updates the library to its latest version, and --quiet suppresses download messages.

Authenticate Your Account

Authenticate your Huggingface account by running the following command and entering the token you created earlier:

!huggingface-cli login
Enter fullscreen mode Exit fullscreen mode

Download the Model

Load and set up the model using the following Python code:

import torch
from diffusers import StableDiffusion3Pipeline

pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large-turbo", torch_dtype=torch.bfloat16)
pipe = pipe.to("cuda")
Enter fullscreen mode Exit fullscreen mode

Note: The model consumes approximately 27GB of memory.


Generate an Image

Test the setup by running this code to generate an image:

prompt = "A capybara holding a sign that reads Hello Fast World"
save_filename = "capybara.png"
image = pipe(
    prompt,
    num_inference_steps=4,
    guidance_scale=0.0,
).images[0]
Enter fullscreen mode Exit fullscreen mode

You can find explanations for these arguments in the Diffusers GitHub documentation.

Save and display the generated image:

image.save(save_filename)
image
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)