zeromodels/sdxl-turbo
See [our collection](https://huggingface.co/collections/zeromodels/stable-diffusion-xl-6aa7927bb25bd239b9f51292) 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
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) uint8generate 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>"):
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.
