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

  • Please note that 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 Optimum RBLN library

Model Compilation

We will start by compiling 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. After compilation, save the model artifacts to disk using the save_pretrained() method. This will create a directory (e.g., rbln-sdxl-turbo) containing the compiled model.

from optimum.rbln import RBLNStableDiffusionXLPipeline

model_id = "stabilityai/sdxl-turbo"
pipe = RBLNStableDiffusionXLPipeline.from_pretrained(
    model_id=model_id,
    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 pre-compiled model from a local path. Since SDXL-Turbo is designed to run without classifier-free guidance, we set rbln_guidance_scale=0.0 during compilation. It is important that this value matches the guidance_scale parameter used during inference for optimal performance.

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

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

Image Generation

With the compiled pipeline loaded, you are now ready to generate an image. Call the pipeline with your prompt and use standard arguments like num_inference_steps. For optimal results, ensure the guidance_scale matches the rbln_guidance_scale set during compilation (in this case, 0.0).

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