Instructions to use mingyi456/Z-Image-Distilled-DF11 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use mingyi456/Z-Image-Distilled-DF11 with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("mingyi456/Z-Image-Distilled-DF11", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Diffusion Single File
How to use mingyi456/Z-Image-Distilled-DF11 with Diffusion Single File:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Update README.md
Browse files
README.md
CHANGED
|
@@ -10,4 +10,120 @@ pipeline_tag: text-to-image
|
|
| 10 |
library_name: diffusers
|
| 11 |
tags:
|
| 12 |
- diffusion-single-file
|
| 13 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
library_name: diffusers
|
| 11 |
tags:
|
| 12 |
- diffusion-single-file
|
| 13 |
+
---
|
| 14 |
+
For more information (including how to compress models yourself), check out https://huggingface.co/DFloat11 and https://github.com/LeanModels/DFloat11
|
| 15 |
+
|
| 16 |
+
Feel free to request for other models for compression as well (for either the `diffusers` library, ComfyUI, or any other model), although models that use architectures which are unfamiliar to me might be more difficult.
|
| 17 |
+
|
| 18 |
+
### How to Use
|
| 19 |
+
|
| 20 |
+
#### `diffusers`
|
| 21 |
+
|
| 22 |
+
```python
|
| 23 |
+
import torch
|
| 24 |
+
from diffusers import ZImagePipeline, ZImageTransformer2DModel
|
| 25 |
+
from dfloat11 import DFloat11Model
|
| 26 |
+
# from transformers.modeling_utils import no_init_weights # for transformers<5.0.0
|
| 27 |
+
from transformers.initialization import no_init_weights # for transformers>=5.0.0
|
| 28 |
+
pattern_dict = {
|
| 29 |
+
r"noise_refiner\.\d+": (
|
| 30 |
+
"attention.to_q",
|
| 31 |
+
"attention.to_k",
|
| 32 |
+
"attention.to_v",
|
| 33 |
+
"attention.to_out.0",
|
| 34 |
+
"feed_forward.w1",
|
| 35 |
+
"feed_forward.w2",
|
| 36 |
+
"feed_forward.w3",
|
| 37 |
+
"adaLN_modulation.0"
|
| 38 |
+
),
|
| 39 |
+
r"context_refiner\.\d+": (
|
| 40 |
+
"attention.to_q",
|
| 41 |
+
"attention.to_k",
|
| 42 |
+
"attention.to_v",
|
| 43 |
+
"attention.to_out.0",
|
| 44 |
+
"feed_forward.w1",
|
| 45 |
+
"feed_forward.w2",
|
| 46 |
+
"feed_forward.w3",
|
| 47 |
+
),
|
| 48 |
+
r"layers\.\d+": (
|
| 49 |
+
"attention.to_q",
|
| 50 |
+
"attention.to_k",
|
| 51 |
+
"attention.to_v",
|
| 52 |
+
"attention.to_out.0",
|
| 53 |
+
"feed_forward.w1",
|
| 54 |
+
"feed_forward.w2",
|
| 55 |
+
"feed_forward.w3",
|
| 56 |
+
"adaLN_modulation.0"
|
| 57 |
+
),
|
| 58 |
+
r"cap_embedder": (
|
| 59 |
+
"1",
|
| 60 |
+
)
|
| 61 |
+
}
|
| 62 |
+
text_encoder = DFloat11Model.from_pretrained("DFloat11/Qwen3-4B-DF11", device="cpu")
|
| 63 |
+
with no_init_weights():
|
| 64 |
+
transformer = ZImageTransformer2DModel.from_config(
|
| 65 |
+
ZImageTransformer2DModel.load_config(
|
| 66 |
+
"Tongyi-MAI/Z-Image-Turbo", subfolder="transformer"
|
| 67 |
+
),
|
| 68 |
+
torch_dtype=torch.bfloat16
|
| 69 |
+
).to(torch.bfloat16)
|
| 70 |
+
# Make sure to download the file first, and edit the filepath accordingly
|
| 71 |
+
DFloat11Model.from_single_file(
|
| 72 |
+
r".\RedZFUN-v6-ZIB-Distilled-AGILE-8steps-BF16-ComfyUI-DF11.safetensors",
|
| 73 |
+
device='cpu',
|
| 74 |
+
bfloat16_model=transformer,
|
| 75 |
+
pattern_dict=pattern_dict
|
| 76 |
+
)
|
| 77 |
+
pipe = ZImagePipeline.from_pretrained(
|
| 78 |
+
"Tongyi-MAI/Z-Image-Turbo",
|
| 79 |
+
text_encoder=text_encoder,
|
| 80 |
+
transformer=transformer,
|
| 81 |
+
torch_dtype=torch.bfloat16,
|
| 82 |
+
low_cpu_mem_usage=False,
|
| 83 |
+
)
|
| 84 |
+
pipe.to("cuda")
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
#### ComfyUI
|
| 88 |
+
Refer to this [model](https://huggingface.co/mingyi456/Z-Image-Distilled-DF11-ComfyUI) instead.
|
| 89 |
+
|
| 90 |
+
### Compression details
|
| 91 |
+
|
| 92 |
+
This is the `pattern_dict` for compression:
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
pattern_dict = {
|
| 96 |
+
r"noise_refiner\.\d+": (
|
| 97 |
+
"attention.to_q",
|
| 98 |
+
"attention.to_k",
|
| 99 |
+
"attention.to_v",
|
| 100 |
+
"attention.to_out.0",
|
| 101 |
+
"feed_forward.w1",
|
| 102 |
+
"feed_forward.w2",
|
| 103 |
+
"feed_forward.w3",
|
| 104 |
+
"adaLN_modulation.0"
|
| 105 |
+
),
|
| 106 |
+
r"context_refiner\.\d+": (
|
| 107 |
+
"attention.to_q",
|
| 108 |
+
"attention.to_k",
|
| 109 |
+
"attention.to_v",
|
| 110 |
+
"attention.to_out.0",
|
| 111 |
+
"feed_forward.w1",
|
| 112 |
+
"feed_forward.w2",
|
| 113 |
+
"feed_forward.w3",
|
| 114 |
+
),
|
| 115 |
+
r"layers\.\d+": (
|
| 116 |
+
"attention.to_q",
|
| 117 |
+
"attention.to_k",
|
| 118 |
+
"attention.to_v",
|
| 119 |
+
"attention.to_out.0",
|
| 120 |
+
"feed_forward.w1",
|
| 121 |
+
"feed_forward.w2",
|
| 122 |
+
"feed_forward.w3",
|
| 123 |
+
"adaLN_modulation.0"
|
| 124 |
+
),
|
| 125 |
+
r"cap_embedder": (
|
| 126 |
+
"1",
|
| 127 |
+
)
|
| 128 |
+
}
|
| 129 |
+
```
|