Text-to-Image
ZeroModels
Keras
PyTorch
JAX
TensorFlow
English
stable-diffusion
stable-diffusion-3
sd3
mmdit
diffusion
rectified-flow
Instructions to use zeromodels/stable-diffusion-3.5-large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/stable-diffusion-3.5-large 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-3.5-large") - Keras
How to use zeromodels/stable-diffusion-3.5-large 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-3.5-large") - Notebooks
- Google Colab
- Kaggle
Load with ZMDiffusion / ZMDiffusionTokenizer (zeromodels.diffusers)
Browse files- README.md +10 -8
- zm_config.json +3 -3
- zm_preprocessor.json +11 -0
README.md
CHANGED
|
@@ -26,7 +26,7 @@ tags:
|
|
| 26 |
|
| 27 |
# Run Stable Diffusion 3.5 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 28 |
|
| 29 |
-
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/
|
| 30 |
|
| 31 |
**Powered by Stability AI**
|
| 32 |
|
|
@@ -73,13 +73,13 @@ import os
|
|
| 73 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 74 |
|
| 75 |
from PIL import Image
|
| 76 |
-
from zeromodels.
|
| 77 |
|
| 78 |
-
model =
|
| 79 |
"zeromodels/stable-diffusion-3.5-large",
|
| 80 |
text_encoder_3="zeromodels/t5-v1_1-xxl-encoder", # optional: omit to zero the T5 features
|
| 81 |
)
|
| 82 |
-
tokenizer =
|
| 83 |
|
| 84 |
inputs = tokenizer("a photograph of an astronaut riding a horse")
|
| 85 |
images = model.generate(**inputs, num_inference_steps=28, guidance_scale=3.5, seed=0)
|
|
@@ -103,18 +103,20 @@ Load any Stable Diffusion 3.5 checkpoint the same way with `from_weights("zeromo
|
|
| 103 |
## Tips
|
| 104 |
|
| 105 |
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
|
|
|
|
|
|
| 106 |
- The graphs are built for 1024px. Pass `transformer_sample_size=<px / 8>, vae_sample_size=<px>` to
|
| 107 |
`from_weights` to build for another multiple of 16px (the weights are resolution-independent
|
| 108 |
up to the 3072px position grid).
|
| 109 |
-
-
|
| 110 |
-
(`.transformer` / `.vae` / `.text_encoder` / `.text_encoder_2`)
|
| 111 |
- `model.text_encoder_3` can be any `SD3T5EncoderModel` (for example one loaded with
|
| 112 |
-
`quantization="int8"`); it is not part of
|
| 113 |
- Both `channels_last` and `channels_first` are supported (`keras.config.set_image_data_format`
|
| 114 |
before loading); `generate` always returns `(batch, H, W, 3)` uint8.
|
| 115 |
- On-the-fly `hf:` conversion is not supported for diffusion models; the checkpoints are
|
| 116 |
hosted here, converted once.
|
| 117 |
-
- See the [Stable Diffusion 3.5 docs](https://imvision12.github.io/ZeroModels/
|
| 118 |
|
| 119 |
## License
|
| 120 |
|
|
|
|
| 26 |
|
| 27 |
# Run Stable Diffusion 3.5 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 28 |
|
| 29 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/diffusers/#stable-diffusion-3-5) [](https://huggingface.co/collections/zeromodels/stable-diffusion-v35-6aa7963880e76656e5646ffc)
|
| 30 |
|
| 31 |
**Powered by Stability AI**
|
| 32 |
|
|
|
|
| 73 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 74 |
|
| 75 |
from PIL import Image
|
| 76 |
+
from zeromodels.diffusers import ZMDiffusion, ZMDiffusionTokenizer
|
| 77 |
|
| 78 |
+
model = ZMDiffusion.from_weights(
|
| 79 |
"zeromodels/stable-diffusion-3.5-large",
|
| 80 |
text_encoder_3="zeromodels/t5-v1_1-xxl-encoder", # optional: omit to zero the T5 features
|
| 81 |
)
|
| 82 |
+
tokenizer = ZMDiffusionTokenizer.from_weights("zeromodels/stable-diffusion-3.5-large")
|
| 83 |
|
| 84 |
inputs = tokenizer("a photograph of an astronaut riding a horse")
|
| 85 |
images = model.generate(**inputs, num_inference_steps=28, guidance_scale=3.5, seed=0)
|
|
|
|
| 103 |
## Tips
|
| 104 |
|
| 105 |
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 106 |
+
- `AutoZModel` / `AutoZMTokenizer` (`from zeromodels import ...`) load this repo too;
|
| 107 |
+
they resolve to `ZMDiffusion` / `ZMDiffusionTokenizer` from its `model_type`.
|
| 108 |
- The graphs are built for 1024px. Pass `transformer_sample_size=<px / 8>, vae_sample_size=<px>` to
|
| 109 |
`from_weights` to build for another multiple of 16px (the weights are resolution-independent
|
| 110 |
up to the 3072px position grid).
|
| 111 |
+
- The trained components are attributes of the loaded `ZMDiffusion`
|
| 112 |
+
(`.transformer` / `.vae` / `.text_encoder` / `.text_encoder_2`), each callable on its own.
|
| 113 |
- `model.text_encoder_3` can be any `SD3T5EncoderModel` (for example one loaded with
|
| 114 |
+
`quantization="int8"`); it is not part of this checkpoint's weights.
|
| 115 |
- Both `channels_last` and `channels_first` are supported (`keras.config.set_image_data_format`
|
| 116 |
before loading); `generate` always returns `(batch, H, W, 3)` uint8.
|
| 117 |
- On-the-fly `hf:` conversion is not supported for diffusion models; the checkpoints are
|
| 118 |
hosted here, converted once.
|
| 119 |
+
- See the [Stable Diffusion 3.5 docs](https://imvision12.github.io/ZeroModels/diffusers/#stable-diffusion-3-5).
|
| 120 |
|
| 121 |
## License
|
| 122 |
|
zm_config.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
{
|
| 2 |
"library_name": "zeromodels",
|
| 3 |
"zeromodels_version": "1.3.3",
|
| 4 |
-
"model_module": "zeromodels.
|
| 5 |
-
"model_class": "
|
| 6 |
"variant": "stable-diffusion-3.5-large",
|
| 7 |
"weights": "model.weights.json",
|
| 8 |
"schema_version": 2,
|
|
@@ -85,4 +85,4 @@
|
|
| 85 |
"num_inference_steps": 28,
|
| 86 |
"guidance_scale": 3.5
|
| 87 |
}
|
| 88 |
-
}
|
|
|
|
| 1 |
{
|
| 2 |
"library_name": "zeromodels",
|
| 3 |
"zeromodels_version": "1.3.3",
|
| 4 |
+
"model_module": "zeromodels.diffusers",
|
| 5 |
+
"model_class": "ZMDiffusion",
|
| 6 |
"variant": "stable-diffusion-3.5-large",
|
| 7 |
"weights": "model.weights.json",
|
| 8 |
"schema_version": 2,
|
|
|
|
| 85 |
"num_inference_steps": 28,
|
| 86 |
"guidance_scale": 3.5
|
| 87 |
}
|
| 88 |
+
}
|
zm_preprocessor.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.3.3",
|
| 4 |
+
"preprocessor_module": "zeromodels.diffusers",
|
| 5 |
+
"preprocessor_class": "ZMDiffusionTokenizer",
|
| 6 |
+
"variant": "stable-diffusion-3.5-large",
|
| 7 |
+
"model_type": "stable_diffusion_3_5",
|
| 8 |
+
"max_seq_len": 77,
|
| 9 |
+
"pad_token": "<|endoftext|>",
|
| 10 |
+
"max_sequence_length": 256
|
| 11 |
+
}
|