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

2

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

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay