IMvision12 commited on
Commit
f95eb1d
·
verified ·
1 Parent(s): 3eed046

Load with ZMDiffusion / ZMDiffusionTokenizer (zeromodels.diffusers)

Browse files
Files changed (3) hide show
  1. README.md +9 -7
  2. zm_config.json +3 -3
  3. zm_preprocessor.json +10 -0
README.md CHANGED
@@ -22,7 +22,7 @@ tags:
22
 
23
  # Run Stable Diffusion 2.x with Keras 3: JAX, PyTorch, or TensorFlow
24
 
25
- [![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_2.x-1f6feb)](https://imvision12.github.io/ZeroModels/stable_diffusion_2/) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Stable_Diffusion_2.x-ffd21e?logo=huggingface&logoColor=black)](https://huggingface.co/collections/zeromodels/stable-diffusion-v2-6aa7906bed026a6b11f4e7be)
26
 
27
  # zeromodels/stable-diffusion-2-base
28
 
@@ -56,10 +56,10 @@ import os
56
  os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
57
 
58
  from PIL import Image
59
- from zeromodels.models.stable_diffusion_2 import StableDiffusion2TextToImage, StableDiffusion2Tokenizer
60
 
61
- model = StableDiffusion2TextToImage.from_weights("zeromodels/stable-diffusion-2-base")
62
- tokenizer = StableDiffusion2Tokenizer.from_weights("zeromodels/stable-diffusion-2-base")
63
 
64
  inputs = tokenizer("a photograph of an astronaut riding a horse")
65
  images = model.generate(**inputs, num_inference_steps=50, guidance_scale=7.5, seed=0)
@@ -84,18 +84,20 @@ Load any Stable Diffusion 2.x checkpoint the same way with `from_weights("zeromo
84
  ## Tips
85
 
86
  - Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
 
 
87
  - The graphs are built for 512px. Pass `unet_sample_size=<px / 8>, vae_sample_size=<px>` to
88
  `from_weights` to build for another multiple of 64px (the weights are resolution-independent).
89
  - Swap the sampler any time: `model.scheduler = EulerDiscreteScheduler.from_config(model.config.scheduler_config)`
90
  (`zeromodels.base.base_scheduler`).
91
- - `StableDiffusion2Model.from_weights(...)` loads the same repo as the bare container
92
- (UNet / VAE / text encoder as `.unet` / `.vae` / `.text_encoder`) without the generation loop.
93
 
94
  - Both `channels_last` and `channels_first` are supported (`keras.config.set_image_data_format`
95
  before loading); `generate` always returns `(batch, H, W, 3)` uint8.
96
  - On-the-fly `hf:` conversion is not supported for diffusion models; the checkpoints are
97
  hosted here, converted once.
98
- - See the [Stable Diffusion 2.x docs](https://imvision12.github.io/ZeroModels/stable_diffusion_2/).
99
 
100
  ## License
101
 
 
22
 
23
  # Run Stable Diffusion 2.x with Keras 3: JAX, PyTorch, or TensorFlow
24
 
25
+ [![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_2.x-1f6feb)](https://imvision12.github.io/ZeroModels/diffusers/#stable-diffusion-2) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Stable_Diffusion_2.x-ffd21e?logo=huggingface&logoColor=black)](https://huggingface.co/collections/zeromodels/stable-diffusion-v2-6aa7906bed026a6b11f4e7be)
26
 
27
  # zeromodels/stable-diffusion-2-base
28
 
 
56
  os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
57
 
58
  from PIL import Image
59
+ from zeromodels.diffusers import ZMDiffusion, ZMDiffusionTokenizer
60
 
61
+ model = ZMDiffusion.from_weights("zeromodels/stable-diffusion-2-base")
62
+ tokenizer = ZMDiffusionTokenizer.from_weights("zeromodels/stable-diffusion-2-base")
63
 
64
  inputs = tokenizer("a photograph of an astronaut riding a horse")
65
  images = model.generate(**inputs, num_inference_steps=50, guidance_scale=7.5, seed=0)
 
84
  ## Tips
85
 
86
  - Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
87
+ - `AutoZModel` / `AutoZMTokenizer` (`from zeromodels import ...`) load this repo too;
88
+ they resolve to `ZMDiffusion` / `ZMDiffusionTokenizer` from its `model_type`.
89
  - The graphs are built for 512px. Pass `unet_sample_size=<px / 8>, vae_sample_size=<px>` to
90
  `from_weights` to build for another multiple of 64px (the weights are resolution-independent).
91
  - Swap the sampler any time: `model.scheduler = EulerDiscreteScheduler.from_config(model.config.scheduler_config)`
92
  (`zeromodels.base.base_scheduler`).
93
+ - The trained components are attributes of the loaded `ZMDiffusion`
94
+ (UNet / VAE / text encoder as `.unet` / `.vae` / `.text_encoder`), each callable on its own.
95
 
96
  - Both `channels_last` and `channels_first` are supported (`keras.config.set_image_data_format`
97
  before loading); `generate` always returns `(batch, H, W, 3)` uint8.
98
  - On-the-fly `hf:` conversion is not supported for diffusion models; the checkpoints are
99
  hosted here, converted once.
100
+ - See the [Stable Diffusion 2.x docs](https://imvision12.github.io/ZeroModels/diffusers/#stable-diffusion-2).
101
 
102
  ## License
103
 
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_2",
5
- "model_class": "StableDiffusion2Model",
6
  "variant": "stable-diffusion-2-base",
7
  "weights": "model.weights.h5",
8
  "schema_version": 2,
@@ -95,4 +95,4 @@
95
  "num_inference_steps": 50,
96
  "guidance_scale": 7.5
97
  }
98
- }
 
1
  {
2
  "library_name": "zeromodels",
3
  "zeromodels_version": "1.3.3",
4
+ "model_module": "zeromodels.diffusers",
5
+ "model_class": "ZMDiffusion",
6
  "variant": "stable-diffusion-2-base",
7
  "weights": "model.weights.h5",
8
  "schema_version": 2,
 
95
  "num_inference_steps": 50,
96
  "guidance_scale": 7.5
97
  }
98
+ }
zm_preprocessor.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "library_name": "zeromodels",
3
+ "zeromodels_version": "1.3.3",
4
+ "preprocessor_module": "zeromodels.diffusers",
5
+ "preprocessor_class": "ZMDiffusionTokenizer",
6
+ "variant": "stable-diffusion-2-base",
7
+ "model_type": "stable_diffusion_2",
8
+ "max_seq_len": 77,
9
+ "pad_token": "!"
10
+ }