IMvision12 commited on
Commit
d770b9d
·
verified ·
1 Parent(s): f31f3fc

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 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-1f6feb)](https://imvision12.github.io/ZeroModels/stable_diffusion_3/) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Stable_Diffusion_3-ffd21e?logo=huggingface&logoColor=black)](https://huggingface.co/collections/zeromodels/stable-diffusion-v3-6aa7941443a0c5ca085ebcc9)
30
 
31
  # zeromodels/stable-diffusion-3-medium
32
 
@@ -71,13 +71,13 @@ import os
71
  os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
72
 
73
  from PIL import Image
74
- from zeromodels.models.stable_diffusion_3 import StableDiffusion3TextToImage, StableDiffusion3Tokenizer
75
 
76
- model = StableDiffusion3TextToImage.from_weights(
77
  "zeromodels/stable-diffusion-3-medium",
78
  text_encoder_3="zeromodels/t5-v1_1-xxl-encoder", # optional: omit to zero the T5 features
79
  )
80
- tokenizer = StableDiffusion3Tokenizer.from_weights("zeromodels/stable-diffusion-3-medium")
81
 
82
  inputs = tokenizer("a photograph of an astronaut riding a horse")
83
  images = model.generate(**inputs, num_inference_steps=28, guidance_scale=7.0, seed=0)
@@ -99,18 +99,20 @@ Load any Stable Diffusion 3 checkpoint the same way with `from_weights("zeromode
99
  ## Tips
100
 
101
  - Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
 
 
102
  - The graphs are built for 1024px. Pass `transformer_sample_size=<px / 8>, vae_sample_size=<px>` to
103
  `from_weights` to build for another multiple of 16px (the weights are resolution-independent
104
  up to the 3072px position grid).
105
- - `StableDiffusion3Model.from_weights(...)` loads the same repo as the bare container
106
- (`.transformer` / `.vae` / `.text_encoder` / `.text_encoder_2`) without the generation loop.
107
  - `model.text_encoder_3` can be any `SD3T5EncoderModel` (for example one loaded with
108
- `quantization="int8"`); it is not part of the container's weights.
109
  - Both `channels_last` and `channels_first` are supported (`keras.config.set_image_data_format`
110
  before loading); `generate` always returns `(batch, H, W, 3)` uint8.
111
  - On-the-fly `hf:` conversion is not supported for diffusion models; the checkpoints are
112
  hosted here, converted once.
113
- - See the [Stable Diffusion 3 docs](https://imvision12.github.io/ZeroModels/stable_diffusion_3/).
114
 
115
  ## License
116
 
 
26
 
27
  # Run Stable Diffusion 3 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-1f6feb)](https://imvision12.github.io/ZeroModels/diffusers/#stable-diffusion-3) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Stable_Diffusion_3-ffd21e?logo=huggingface&logoColor=black)](https://huggingface.co/collections/zeromodels/stable-diffusion-v3-6aa7941443a0c5ca085ebcc9)
30
 
31
  # zeromodels/stable-diffusion-3-medium
32
 
 
71
  os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
72
 
73
  from PIL import Image
74
+ from zeromodels.diffusers import ZMDiffusion, ZMDiffusionTokenizer
75
 
76
+ model = ZMDiffusion.from_weights(
77
  "zeromodels/stable-diffusion-3-medium",
78
  text_encoder_3="zeromodels/t5-v1_1-xxl-encoder", # optional: omit to zero the T5 features
79
  )
80
+ tokenizer = ZMDiffusionTokenizer.from_weights("zeromodels/stable-diffusion-3-medium")
81
 
82
  inputs = tokenizer("a photograph of an astronaut riding a horse")
83
  images = model.generate(**inputs, num_inference_steps=28, guidance_scale=7.0, seed=0)
 
99
  ## Tips
100
 
101
  - Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
102
+ - `AutoZModel` / `AutoZMTokenizer` (`from zeromodels import ...`) load this repo too;
103
+ they resolve to `ZMDiffusion` / `ZMDiffusionTokenizer` from its `model_type`.
104
  - The graphs are built for 1024px. Pass `transformer_sample_size=<px / 8>, vae_sample_size=<px>` to
105
  `from_weights` to build for another multiple of 16px (the weights are resolution-independent
106
  up to the 3072px position grid).
107
+ - The trained components are attributes of the loaded `ZMDiffusion`
108
+ (`.transformer` / `.vae` / `.text_encoder` / `.text_encoder_2`), each callable on its own.
109
  - `model.text_encoder_3` can be any `SD3T5EncoderModel` (for example one loaded with
110
+ `quantization="int8"`); it is not part of this checkpoint's weights.
111
  - Both `channels_last` and `channels_first` are supported (`keras.config.set_image_data_format`
112
  before loading); `generate` always returns `(batch, H, W, 3)` uint8.
113
  - On-the-fly `hf:` conversion is not supported for diffusion models; the checkpoints are
114
  hosted here, converted once.
115
+ - See the [Stable Diffusion 3 docs](https://imvision12.github.io/ZeroModels/diffusers/#stable-diffusion-3).
116
 
117
  ## License
118
 
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
- "model_class": "StableDiffusion3Model",
6
  "variant": "stable-diffusion-3-medium",
7
  "weights": "model.weights.json",
8
  "schema_version": 2,
@@ -85,4 +85,4 @@
85
  "num_inference_steps": 28,
86
  "guidance_scale": 7.0
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-medium",
7
  "weights": "model.weights.json",
8
  "schema_version": 2,
 
85
  "num_inference_steps": 28,
86
  "guidance_scale": 7.0
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-medium",
7
+ "model_type": "stable_diffusion_3",
8
+ "max_seq_len": 77,
9
+ "pad_token": "<|endoftext|>",
10
+ "max_sequence_length": 256
11
+ }