zeromodels/stable-diffusion-v1-5
See [our collection](https://huggingface.co/zeromodels) for all Stable Diffusion 1.x checkpoints.
Run Stable Diffusion 1.x with Keras 3: JAX, PyTorch, or TensorFlow
  [](https://huggingface.co/zeromodels)
zeromodels/stable-diffusion-v1-5
Paper: High-Resolution Image Synthesis with Latent Diffusion Models (arXiv:2112.10752) | HF Papers
Pure-Keras 3 conversion of `stable-diffusion-v1-5/stable-diffusion-v1-5` 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 text encoder in model.weights.h5 (1.07B parameters, 3.97 GB), plus zm_config.json (the three component configs, the checkpoint's PNDMScheduler schedule with its epsilon objective and the default generation settings) and the tokenizer as tokenizer.json. Weights are stored in float32, exactly as released. 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 import StableDiffusionTextToImage, StableDiffusionTokenizer
model = StableDiffusionTextToImage.from_weights("zeromodels/stable-diffusion-v1-5")
tokenizer = StableDiffusionTokenizer.from_weights("zeromodels/stable-diffusion-v1-5")
inputs = tokenizer("a photograph of an astronaut riding a horse")
images = model.generate(**inputs, num_inference_steps=50, guidance_scale=7.5, 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 1.x 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). StableDiffusionModel.from_weights(...)loads the same repo as the bare container (UNet / VAE / text encoder as.unet/.vae/.text_encoder) without the generation loop.
- 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 1.x docs.
License
The weights are redistributed under the CreativeML OpenRAIL-M License of the upstream checkpoint, including its use-based restrictions. By using them you agree to those terms.
Notice
Modifications by zeromodels (https://github.com/IMvision12/ZeroModels): the checkpoint released at https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5 was converted to the Keras 3 weights layout of zeromodels (model.weights.h5, zm_config.json, tokenizer.json), stored in float32 as released. The model architecture and the parameter values are unchanged; the weight names and the file format differ from the release.
Special Thanks
Thank you to the CompVis group at LMU Munich, Runway and Stability AI for training and releasing Stable Diffusion, and to the Hugging Face diffusers team, whose implementation this port was verified against.
