Text-to-Image
ZeroModels
Keras
PyTorch
JAX
TensorFlow
English
stable-diffusion
stable-diffusion-diffusers
diffusion
latent-diffusion
Run this model with HF Jobs
Run zeromodels/stable-diffusion-2 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/zeromodels/stable-diffusion-2. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/zeromodels/stable-diffusion-2 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use zeromodels/stable-diffusion-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/stable-diffusion-2 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/stable-diffusion-2") - Keras
How to use zeromodels/stable-diffusion-2 with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://zeromodels/stable-diffusion-2") - Notebooks
- Google Colab
- Kaggle
Load with ZMDiffusion / ZMDiffusionTokenizer (zeromodels.diffusers)
Browse filesFiles changed (3)
- README.md+9-7
- zm_config.json+3-3
- zm_preprocessor.jsonAdded+10
21 unmodified lines2223242526272827 unmodified lines5657585960616263646518 unmodified lines8485868788899091929394959697989910010121 unmodified lines# Run Stable Diffusion 2.x with Keras 3: JAX, PyTorch, or TensorFlow[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/stable_diffusion_2/) [](https://huggingface.co/collections/zeromodels/stable-diffusion-v2-6aa7906bed026a6b11f4e7be)# zeromodels/stable-diffusion-227 unmodified linesos.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"from PIL import Imagefrom zeromodels.models.stable_diffusion_2 import StableDiffusion2TextToImage, StableDiffusion2Tokenizermodel = StableDiffusion2TextToImage.from_weights("zeromodels/stable-diffusion-2")tokenizer = StableDiffusion2Tokenizer.from_weights("zeromodels/stable-diffusion-2")inputs = tokenizer("a photograph of an astronaut riding a horse")images = model.generate(**inputs, num_inference_steps=50, guidance_scale=7.5, seed=0)18 unmodified lines## Tips- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.- The graphs are built for 768px. Pass `unet_sample_size=<px / 8>, vae_sample_size=<px>` to`from_weights` to 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`).- `StableDiffusion2Model.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_last` and `channels_first` are supported (`keras.config.set_image_data_format`before loading); `generate` always returns `(batch, H, W, 3)` uint8.- On-the-fly `hf:` conversion is not supported for diffusion models; the checkpoints arehosted here, converted once.- See the [Stable Diffusion 2.x docs](https://imvision12.github.io/ZeroModels/stable_diffusion_2/).## License21 unmodified lines2223242526272827 unmodified lines5657585960616263646518 unmodified lines8485868788899091929394959697989910010110210321 unmodified lines# Run Stable Diffusion 2.x with Keras 3: JAX, PyTorch, or TensorFlow[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/diffusers/#stable-diffusion-2) [](https://huggingface.co/collections/zeromodels/stable-diffusion-v2-6aa7906bed026a6b11f4e7be)# zeromodels/stable-diffusion-227 unmodified linesos.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"from PIL import Imagefrom zeromodels.diffusers import ZMDiffusion, ZMDiffusionTokenizermodel = ZMDiffusion.from_weights("zeromodels/stable-diffusion-2")tokenizer = ZMDiffusionTokenizer.from_weights("zeromodels/stable-diffusion-2")inputs = tokenizer("a photograph of an astronaut riding a horse")images = model.generate(**inputs, num_inference_steps=50, guidance_scale=7.5, seed=0)18 unmodified lines## Tips- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.- `AutoZModel` / `AutoZMTokenizer` (`from zeromodels import ...`) load this repo too;they resolve to `ZMDiffusion` / `ZMDiffusionTokenizer` from its `model_type`.- The graphs are built for 768px. Pass `unet_sample_size=<px / 8>, vae_sample_size=<px>` to`from_weights` to 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`).- The trained components are attributes of the loaded `ZMDiffusion`(UNet / VAE / text encoder as `.unet` / `.vae` / `.text_encoder`), each callable on its own.- Both `channels_last` and `channels_first` are supported (`keras.config.set_image_data_format`before loading); `generate` always returns `(batch, H, W, 3)` uint8.- On-the-fly `hf:` conversion is not supported for diffusion models; the checkpoints arehosted here, converted once.- See the [Stable Diffusion 2.x docs](https://imvision12.github.io/ZeroModels/diffusers/#stable-diffusion-2).## License
1234567887 unmodified lines96979899{"library_name": "zeromodels","zeromodels_version": "1.3.3","model_module": "zeromodels.models.stable_diffusion_2","model_class": "StableDiffusion2Model","variant": "stable-diffusion-2","weights": "model.weights.h5","schema_version": 2,87 unmodified lines"num_inference_steps": 50,"guidance_scale": 7.5}}1234567887 unmodified lines96979899{"library_name": "zeromodels","zeromodels_version": "1.3.3","model_module": "zeromodels.diffusers","model_class": "ZMDiffusion","variant": "stable-diffusion-2","weights": "model.weights.h5","schema_version": 2,87 unmodified lines"num_inference_steps": 50,"guidance_scale": 7.5}}
12345678910{ "library_name": "zeromodels", "zeromodels_version": "1.3.3", "preprocessor_module": "zeromodels.diffusers", "preprocessor_class": "ZMDiffusionTokenizer", "variant": "stable-diffusion-2", "model_type": "stable_diffusion_2", "max_seq_len": 77, "pad_token": "!"}README.md+9-7
zm_config.json+3-3
zm_preprocessor.jsonAdded+10