Home > Backend Development > Python Tutorial > How to Run stable-diffusion--large-turbo on Google Colab

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

Patricia Arquette
Release: 2024-12-09 21:01:13
Original
266 people have browsed it

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.

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

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:

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

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:

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

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
Copy after login

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
Copy after 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")
Copy after login

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]
Copy after login

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

Save and display the generated image:

image.save(save_filename)
image
Copy after login

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

The above is the detailed content of How to Run stable-diffusion--large-turbo on Google Colab. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template