Skip to main content
Run an open image model on a GPU machine and generate pictures from your own prompts. This guide runs SD-Turbo with Diffusers on one l4 GPU. After the model is loaded, each 512 by 512 picture takes about a quarter of a second.
Three generated pictures side by side: an oil painting of a lighthouse on a rock at sunset, a photo-like red fox in snow, and an isometric drawing of a room of server racks.
1

Create a GPU machine

2

Install Diffusers

The GPU template already has PyTorch in /opt/venv, so you only add the image libraries.
3

Copy the script

Save this script as generate.py on your computer. It loads the model once, with a safety checker that blanks a picture it flags, and then draws one picture for each pair of a prompt and a file name.
generate.py
Make a folder for the pictures on the machine, and copy the script into it.
4

Generate the pictures

Run the script with three prompts. The first run downloads the model, which is about 2.5 GB, into the machine’s Hugging Face cache.
The script prints how long the model took to load and how long each picture took. This output is from a run with the model already on the machine’s disk.
The first picture of a run takes longer than the ones after it.
5

Copy the pictures to your computer

Repeat the command for gen2.png and gen3.png. The picture at the top of this page shows the three results of this run.
6

Stop or delete the machine

Stop the machine when you are done for now. The model and your pictures stay on its disk, and a stopped machine does not pay for its GPU.
Delete the machine when you no longer need it.

What it uses

SD-Turbo is a small model, so it leaves most of the 24 GiB of an l4 free. A larger model, such as SDXL or FLUX, needs more memory, so check its size before you pick a GPU type. To generate many pictures, pass all the prompts to one run, so that the model loads once.

Serve an open model

Keep a model loaded behind an HTTPS endpoint.

GPU machines

GPU types and counts, and what the template includes.