Skip to content

SDXL-Turbo (Image Generation)

Overview

Stable Diffusion XL Turbo (SDXL-Turbo) is a high-speed, high-quality text-to-image generation model from StabilityAI. Unlike many other diffusion models, SDXL-Turbo can generate high-quality images in a single inference step, offering a significant speed improvement. This tutorial demonstrates how to compile the sdxl-turbo model and generate images using optimum-rbln.

Setup & Installation

Before you begin, ensure that your system environment is properly configured and that all required packages are installed. This includes:

Note

  • rebel-compiler requires an RBLN Portal account.
  • The commands above are intended for a default pip install on Debian-based Linux such as Ubuntu. For all other configurations, refer to the Installation Guide for the supported install matrix and the applicable commands.

Using RBLN Optimum

Model Compilation

Compile the SDXL-Turbo model using the RBLNStableDiffusionXLPipeline class provided by the optimum-rbln library. To compile the model, you must set the export argument to True. This instructs the pipeline to download the original model from the HuggingFace Hub and then compile it using the RBLN Compiler. Pass torch_dtype=torch.float16 to compile the pipeline in half precision. When no dtype is given, the pipeline falls back to torch.float32. After compilation, save the model artifacts to disk using the save_pretrained() method. This creates a directory (e.g., rbln-sdxl-turbo) containing the compiled model.

import torch
from optimum.rbln import RBLNStableDiffusionXLPipeline

model_id = "stabilityai/sdxl-turbo"
pipe = RBLNStableDiffusionXLPipeline.from_pretrained(
    model_id=model_id,
    torch_dtype=torch.float16,
    rbln_guidance_scale=0.0,
    export=True,
)

pipe.save_pretrained("rbln-sdxl-turbo")

Load the Compiled Model

To generate an image, first load the compiled model you saved in the previous step. This time, set the export argument to False to indicate that you are loading a precompiled model from a local path. SDXL-Turbo is designed to run without classifier-free guidance, so the compilation step sets rbln_guidance_scale=0.0. Use the same value for guidance_scale at inference.

1
2
3
4
5
6
from optimum.rbln import RBLNStableDiffusionXLPipeline

pipe = RBLNStableDiffusionXLPipeline.from_pretrained(
    model_id="rbln-sdxl-turbo",
    export=False,
)

Image Generation

After loading the compiled pipeline, call it with your prompt and standard arguments such as num_inference_steps. Set guidance_scale to the rbln_guidance_scale value used at compilation (0.0 in this example).

1
2
3
prompt = "A cinematic shot of a baby racoon wearing an intricate italian priest robe."
image = pipe(prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
image.save("generated_image.png")

Example Output:

References