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:
- System Requirements:
- Python: 3.9–3.12
- RBLN Driver
- Packages Requirements:
- Installation Command:
Note
Please note that rebel-compiler
requires an RBLN Portal account.
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
. When export
is set to False
, the pipeline loads a pre-compiled model for inference.
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.
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.
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
).
The results will look like this:
Summary and References¶
This tutorial demonstrated how to compile the stabilityai/sdxl-turbo
model using optimum-rbln
and then generate an image with the compiled pipeline. By setting export=True
, the model is compiled for the RBLN NPU. By subsequently loading the saved artifacts with export=False
, you can perform fast, single-step image generation.