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

ow 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.

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:

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:

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

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

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")

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]

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

Save and display the generated image:

image.save(save_filename)
image

コメント

このブログの人気の投稿

OpenAI Realtime API Python Code: Understanding the Low-Level Sample Code for Azure's Realtime Audio Python Code

OpnAI Realtime API: Conversing via Local Microphone and Speaker

Prompt Caching: Comparing OpenAI, Anthropic, and Gemini