Text-to-Image
Diffusers
Safetensors
English
ZImagePipeline
z-image
nf4
bitsandbytes
lora-training
academiasd
Instructions to use AcademiaSD/Z-Image-NF4-for-LoRA-Training with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use AcademiaSD/Z-Image-NF4-for-LoRA-Training with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("AcademiaSD/Z-Image-NF4-for-LoRA-Training", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Upload 3 files
Browse files- .gitattributes +4 -0
- README.md +57 -0
- model_index.json +24 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
Z-Image/tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
assets/z-image.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
teaser.jpg filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Tongyi-MAI/Z-Image
|
| 4 |
+
base_model_relation: quantized
|
| 5 |
+
pipeline_tag: text-to-image
|
| 6 |
+
library_name: diffusers
|
| 7 |
+
language:
|
| 8 |
+
- en
|
| 9 |
+
tags:
|
| 10 |
+
- z-image
|
| 11 |
+
- nf4
|
| 12 |
+
- bitsandbytes
|
| 13 |
+
- lora-training
|
| 14 |
+
- academiasd
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Z-Image NF4 for LoRA Training
|
| 18 |
+
|
| 19 |
+
**[Z-Image](https://huggingface.co/Tongyi-MAI/Z-Image)** (the undistilled base model by Tongyi-MAI) quantized to **4-bit NF4** for the Z-Image trainer of **[AcademiaSD LoRAlab Trainer Studio](https://github.com/AcademiaSD/AcademiaSD_LoRAlab-TrainerStudio)**: LoRA training on consumer NVIDIA GPUs from 8 GB of VRAM.
|
| 20 |
+
|
| 21 |
+
You do not need to download this repository by hand: the trainer downloads it on first use.
|
| 22 |
+
|
| 23 |
+
## Contents
|
| 24 |
+
|
| 25 |
+
| Folder | Content | Size |
|
| 26 |
+
| :--- | :--- | ---: |
|
| 27 |
+
| `transformer/` | 6B transformer: attention and MLP layers in NF4 (bitsandbytes, pre-quantized), embedders, final layer and adaLN modulation in BF16 | 3.4 GB |
|
| 28 |
+
| `text_encoder/` | Qwen3-4B text encoder in NF4 (`Qwen3Model`, without `lm_head`) | 2.7 GB |
|
| 29 |
+
| `vae/`, `tokenizer/`, `scheduler/` | Unchanged from the original model | 0.2 GB |
|
| 30 |
+
| **Total** | | **5.9 GB** (original: 20.5 GB) |
|
| 31 |
+
|
| 32 |
+
The text encoder, tokenizer and VAE are byte-identical in Z-Image and Z-Image-Turbo.
|
| 33 |
+
|
| 34 |
+
## Format
|
| 35 |
+
|
| 36 |
+
- `text_encoder/` loads with `transformers`: `Qwen3Model.from_pretrained(".../text_encoder")`.
|
| 37 |
+
- `transformer/` is **not** a standard diffusers checkpoint. It is a pre-quantized cache: one `.safetensors` file per layer in `weights/` (NF4 weight plus its packed bitsandbytes `QuantState`, or BF16 for the excluded layers), `others.safetensors` with the norms and pad tokens, and `index.json`. The trainer builds an empty `ZImageTransformer2DModel` from `config.json` and fills it from this cache, so the BF16 transformer is never downloaded or loaded. `metadata.json` lists the layers kept in BF16.
|
| 38 |
+
- The converter that produced it is `tools/zimage/5_conversor_ZImage_NF4.py` in the Trainer Studio repository.
|
| 39 |
+
|
| 40 |
+
NF4 is meant for training. Images generated with this NF4 transformer are visually equivalent to BF16 (same subject, composition and legible text). For inference, use the original model in ComfyUI.
|
| 41 |
+
|
| 42 |
+
## LoRAs trained with it
|
| 43 |
+
|
| 44 |
+
The trainer exports LoRAs in diffusers format (`transformer.<layer>.lora_A / lora_B` plus `alpha`), which ComfyUI loads directly. Z-Image-Turbo has the same layers, so the LoRAs also load there.
|
| 45 |
+
|
| 46 |
+
Measured on an RTX 5080 at 512×512, rank 8: ~5.5 GB of VRAM and ~0.9 s per step.
|
| 47 |
+
|
| 48 |
+
## License
|
| 49 |
+
|
| 50 |
+
Apache 2.0, the same as the original [Tongyi-MAI/Z-Image](https://huggingface.co/Tongyi-MAI/Z-Image). All credit for the model goes to the Tongyi-MAI team; this repository only changes the storage precision.
|
| 51 |
+
|
| 52 |
+
## Links
|
| 53 |
+
|
| 54 |
+
- Trainer: [AcademiaSD LoRAlab Trainer Studio](https://github.com/AcademiaSD/AcademiaSD_LoRAlab-TrainerStudio)
|
| 55 |
+
- ▶ YouTube: [youtube.com/@Academia_SD](https://www.youtube.com/@Academia_SD)
|
| 56 |
+
- 💬 Discord: [discord.gg/Syuaduy678](https://discord.gg/Syuaduy678)
|
| 57 |
+
- ☕ Ko-Fi: [ko-fi.com/academiasd](https://ko-fi.com/academiasd)
|
model_index.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "ZImagePipeline",
|
| 3 |
+
"_diffusers_version": "0.37.0.dev0",
|
| 4 |
+
"scheduler": [
|
| 5 |
+
"diffusers",
|
| 6 |
+
"FlowMatchEulerDiscreteScheduler"
|
| 7 |
+
],
|
| 8 |
+
"text_encoder": [
|
| 9 |
+
"transformers",
|
| 10 |
+
"Qwen3Model"
|
| 11 |
+
],
|
| 12 |
+
"tokenizer": [
|
| 13 |
+
"transformers",
|
| 14 |
+
"Qwen2Tokenizer"
|
| 15 |
+
],
|
| 16 |
+
"transformer": [
|
| 17 |
+
"diffusers",
|
| 18 |
+
"ZImageTransformer2DModel"
|
| 19 |
+
],
|
| 20 |
+
"vae": [
|
| 21 |
+
"diffusers",
|
| 22 |
+
"AutoencoderKL"
|
| 23 |
+
]
|
| 24 |
+
}
|