Instructions to use zeromodels/sdxl-turbo with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/sdxl-turbo with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/sdxl-turbo") - Keras
How to use zeromodels/sdxl-turbo with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/sdxl-turbo") - Notebooks
- Google Colab
- Kaggle
See our collection for all Stable Diffusion XL checkpoints.
Run Stable Diffusion XL with Keras 3: JAX, PyTorch, or TensorFlow
Powered by Stability AI
zeromodels/sdxl-turbo
Paper: SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis (arXiv:2307.01952) | HF Papers
Pure-Keras 3 conversion of stabilityai/sdxl-turbo for
zeromodels. One implementation runs unmodified on
TensorFlow / Torch / JAX. The whole text-to-image model ships as one container:
the UNet denoiser, the VAE and the CLIP ViT-L/14 and OpenCLIP ViT-bigG/14 text encoders (penultimate layers) in model.weights.json shards
(3.47B parameters, 6.62 GB), plus zm_config.json (the four
component configs, the checkpoint's EulerAncestralDiscreteScheduler schedule with its epsilon objective
and the default generation settings) and the tokenizer as tokenizer.json. Weights are stored in float16, the checkpoint's native precision (the VAE in float32: it overflows in float16), and load in float16 by default; pass load_dtype="float32" to from_weights for a float32 model.
This checkpoint generates 512x512 images (a 64x64 latent).
For model details, intended use and limitations, see the upstream model card.
Architecture
| Component | zeromodels class | Details |
|---|---|---|
| Denoiser | UNet2DConditionModel |
(320, 640, 1280) channels, 2 ResNet blocks per level, (5, 10, 20) attention heads on the 2048-d text context, linear token projection, (1, 2, 10) transformer blocks per level, text_time micro-conditioning (pooled text embedding + size / crop ids), 64x64x4 latent |
| Autoencoder | AutoencoderKL |
(128, 256, 512, 512) channels, x8 spatial compression to 4 latent channels, scaling_factor 0.13025, float32 (force_upcast) |
| Text encoder | functional CLIP text tower | CLIP ViT-L/14: 768-d, 12 layers, 12 heads, 77 tokens, quick_gelu; penultimate hidden state |
| Text encoder 2 | functional CLIP text tower | OpenCLIP ViT-bigG/14: 1280-d, 32 layers, 20 heads, gelu, 1280-d projection; penultimate hidden state + projected pooled state |
| Scheduler | EulerAncestralDiscreteScheduler |
scaled_linear betas 0.00085 to 0.012 over 1000 steps, epsilon, trailing timestep spacing; DDIM / PNDM / Euler / Euler-ancestral are drop-in |
Quick start
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from PIL import Image
from zeromodels.models.stable_diffusion_xl import StableDiffusionXLTextToImage, StableDiffusionXLTokenizer
model = StableDiffusionXLTextToImage.from_weights("zeromodels/sdxl-turbo")
tokenizer = StableDiffusionXLTokenizer.from_weights("zeromodels/sdxl-turbo")
inputs = tokenizer("a photograph of an astronaut riding a horse")
images = model.generate(**inputs, num_inference_steps=1, guidance_scale=0.0, seed=0)
Image.fromarray(images[0]).save("astronaut.png") # (512, 512, 3) uint8
generate takes the tokenizer's input_ids (batch them for several prompts), an optional
negative_input_ids (tokenize the negative prompt), num_inference_steps, guidance_scale,
a seed, or explicit latents of shape (batch, 64, 64, 4) for results that are
identical across backends.
Load any Stable Diffusion XL checkpoint the same way with from_weights("zeromodels/<variant>"):
| Variant | Hub | Training |
|---|---|---|
stable-diffusion-xl-base-1.0 |
zeromodels/stable-diffusion-xl-base-1.0 | 1024px, epsilon, Euler (leading spacing): the SDXL 1.0 base model, multi-aspect training with size / crop micro-conditioning |
stable-diffusion-xl-refiner-1.0 |
zeromodels/stable-diffusion-xl-refiner-1.0 | image-to-image refiner of SDXL 1.0: refines the base's latents (denoising_start 0.8) or an image (strength 0.3); one text tower, aesthetic-score conditioning |
sdxl-turbo |
zeromodels/sdxl-turbo | 512px, epsilon, ancestral Euler (trailing spacing), 1 to 4 steps, no guidance: SDXL 1.0 distilled with Adversarial Diffusion Distillation (Stability AI Community License) |
Tips
- Set
KERAS_BACKENDbefore importing Keras / zeromodels. - The graphs are built for 512px. Pass
unet_sample_size=<px / 8>, vae_sample_size=<px>tofrom_weightsto build for another multiple of 64px (the weights are resolution-independent). - Swap the sampler any time:
model.scheduler = EulerDiscreteScheduler.from_config(model.config.scheduler_config)(zeromodels.base.base_scheduler). StableDiffusionXLModel.from_weights(...)loads the same repo as the bare container (UNet / VAE / text encoders as.unet/.vae/.text_encoder/.text_encoder_2) without the generation loop.- SDXL micro-conditioning:
generate(..., original_size=(h, w), crops_coords_top_left=(top, left), target_size=(h, w)), plusnegative_*variants; the sizes default to the image size. Without a negative prompt the unconditional branch is zero embeddings (force_zeros_for_empty_prompt), as in diffusers. - Both
channels_lastandchannels_firstare supported (keras.config.set_image_data_formatbefore loading);generatealways returns(batch, H, W, 3)uint8. - On-the-fly
hf:conversion is not supported for diffusion models; the checkpoints are hosted here, converted once. - See the Stable Diffusion XL docs.
License
The weights are redistributed under the Stability AI Community License of the upstream checkpoint, including its use-based restrictions. By using them you agree to those terms.
Notice
This Stability AI Model is licensed under the Stability AI Community License, Copyright © Stability AI Ltd. All Rights Reserved
Modifications by zeromodels (https://github.com/IMvision12/ZeroModels): the checkpoint
released at https://huggingface.co/stabilityai/sdxl-turbo was converted to the Keras 3
weights layout of zeromodels (model.weights.json, model_00000.weights.h5, model_00001.weights.h5, zm_config.json, tokenizer.json), stored in float16, the upstream
fp16 files, with the VAE in float32. The model architecture and the parameter values are
unchanged; the weight names and the file format differ from the release.
Powered by Stability AI
Special Thanks
Thank you to Stability AI and the LAION / OpenCLIP teams for training and releasing Stable Diffusion, and to the Hugging Face diffusers team, whose implementation this port was verified against.
- Downloads last month
- -
Model tree for zeromodels/sdxl-turbo
Base model
stabilityai/sdxl-turbo