IMvision12 commited on
Commit
af3da36
·
verified ·
1 Parent(s): c2e272b

Load with ZMDiffusion / ZMDiffusionTokenizer (zeromodels.diffusers)

Browse files
Files changed (3) hide show
  1. README.md +10 -8
  2. zm_config.json +3 -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
- [![GitHub](https://img.shields.io/badge/GitHub-ZeroModels-181717?logo=github)](https://github.com/IMvision12/ZeroModels) [![Docs](https://img.shields.io/badge/Docs-Stable_Diffusion_3.5-1f6feb)](https://imvision12.github.io/ZeroModels/stable_diffusion_3_5/) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Stable_Diffusion_3.5-ffd21e?logo=huggingface&logoColor=black)](https://huggingface.co/collections/zeromodels/stable-diffusion-v35-6aa7963880e76656e5646ffc)
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.models.stable_diffusion_3_5 import StableDiffusion3_5TextToImage, StableDiffusion3_5Tokenizer
77
 
78
- model = StableDiffusion3_5TextToImage.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 = StableDiffusion3_5Tokenizer.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,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
- - `StableDiffusion3_5Model.from_weights(...)` loads the same repo as the bare container
110
- (`.transformer` / `.vae` / `.text_encoder` / `.text_encoder_2`) without the generation loop.
111
  - `model.text_encoder_3` can be any `SD3T5EncoderModel` (for example one loaded with
112
- `quantization="int8"`); it is not part of the container's weights.
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/stable_diffusion_3_5/).
118
 
119
  ## License
120
 
 
26
 
27
  # Run Stable Diffusion 3.5 with Keras 3: JAX, PyTorch, or TensorFlow
28
 
29
+ [![GitHub](https://img.shields.io/badge/GitHub-ZeroModels-181717?logo=github)](https://github.com/IMvision12/ZeroModels) [![Docs](https://img.shields.io/badge/Docs-Stable_Diffusion_3.5-1f6feb)](https://imvision12.github.io/ZeroModels/diffusers/#stable-diffusion-3-5) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Stable_Diffusion_3.5-ffd21e?logo=huggingface&logoColor=black)](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.models.stable_diffusion_3_5",
5
- "model_class": "StableDiffusion3_5Model",
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
+ }