GCStream commited on
Commit
307b9eb
·
verified ·
1 Parent(s): c65c86f

Upload Z-Image-Turbo Fuliji LoRA adapter (rank=32, 3000 steps, 8 artists)

Browse files
Files changed (3) hide show
  1. README.md +240 -0
  2. adapter_config.json +48 -0
  3. adapter_model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Tongyi-MAI/Z-Image-Turbo
3
+ library_name: peft
4
+ tags:
5
+ - lora
6
+ - diffusers
7
+ - text-to-image
8
+ - anime
9
+ - art-style
10
+ - z-image
11
+ - fuliji
12
+ license: apache-2.0
13
+ language:
14
+ - zh
15
+ - en
16
+ ---
17
+
18
+ # Z-Image-Turbo × Fuliji — LoRA Adapter
19
+
20
+ A **PEFT LoRA adapter** trained on top of [Tongyi-MAI/Z-Image-Turbo](https://huggingface.co/Tongyi-MAI/Z-Image-Turbo) to learn the visual identity of 8 Chinese anime/illustration artists from the Fuliji dataset.
21
+
22
+ > **Looking for the ready-to-run merged model?**
23
+ > Use [DownFlow/Z-Image-Turbo-Fuli](https://huggingface.co/DownFlow/Z-Image-Turbo-Fuli) — the LoRA weights have been baked into the base model and can be served directly.
24
+
25
+ ---
26
+
27
+ ## Adapter Details
28
+
29
+ | Property | Value |
30
+ |---|---|
31
+ | Base model | `Tongyi-MAI/Z-Image-Turbo` |
32
+ | LoRA rank | 32 |
33
+ | LoRA alpha | 32 |
34
+ | Target modules | `to_q`, `to_k`, `to_v`, `w1`, `w2`, `w3` |
35
+ | Trainable params | ~39 M |
36
+ | Adapter size | ~271 MB |
37
+ | Training steps | 3 000 |
38
+ | Training resolution | 512 × 512 |
39
+ | Dataset | [DownFlow/fuliji](https://huggingface.co/datasets/DownFlow/fuliji) (8 artists, ~200 images) |
40
+
41
+ ---
42
+
43
+ ## Quick Start (Python + Diffusers + PEFT)
44
+
45
+ ### 1 — Install dependencies
46
+
47
+ ```bash
48
+ pip install diffusers transformers peft accelerate safetensors
49
+ ```
50
+
51
+ ### 2 — Generate with artist trigger token
52
+
53
+ ```python
54
+ import torch
55
+ from diffusers import DiffusionPipeline
56
+ from peft import PeftModel
57
+
58
+ DEVICE = "cuda"
59
+ BASE_MODEL = "Tongyi-MAI/Z-Image-Turbo"
60
+ ADAPTER = "DownFlow/Z-Image-Turbo-Fuli-LoRA"
61
+
62
+ # Load base pipeline
63
+ pipe = DiffusionPipeline.from_pretrained(
64
+ BASE_MODEL,
65
+ torch_dtype=torch.bfloat16,
66
+ ).to(DEVICE)
67
+
68
+ # Attach LoRA adapter to the transformer
69
+ pipe.transformer = PeftModel.from_pretrained(pipe.transformer, ADAPTER)
70
+
71
+ # Generate — prepend the artist's trigger token
72
+ # Trained artists: 萌芽儿o0, 年年, 封疆疆v, 焖焖碳, 星之迟迟, 蠢沫沫, 雨波HaneAme, 清水由乃
73
+ image = pipe(
74
+ prompt="by 蠢沫沫, 1girl, solo, smile, looking at viewer, soft lighting",
75
+ num_inference_steps=8,
76
+ guidance_scale=0.0, # Z-Image Turbo uses CFG=0
77
+ height=512,
78
+ width=512,
79
+ ).images[0]
80
+
81
+ image.save("output.png")
82
+ ```
83
+
84
+ ### 3 — Adjust LoRA influence at runtime
85
+
86
+ PEFT exposes a scaling multiplier per adapter. Increase it to push the style harder:
87
+
88
+ ```python
89
+ # After PeftModel.from_pretrained ...
90
+ for module in pipe.transformer.modules():
91
+ if hasattr(module, "scaling"):
92
+ module.scaling = {k: v * 1.5 for k, v in module.scaling.items()}
93
+ ```
94
+
95
+ Recommended range: **1.0 – 2.0**. Values above 3.0 may cause colour artefacts.
96
+
97
+ ---
98
+
99
+ ## Merge and Unload (for maximum inference speed)
100
+
101
+ Baking the LoRA into the base weights eliminates PEFT overhead entirely:
102
+
103
+ ```python
104
+ import torch
105
+ from diffusers import DiffusionPipeline
106
+ from peft import PeftModel
107
+
108
+ pipe = DiffusionPipeline.from_pretrained(
109
+ "Tongyi-MAI/Z-Image-Turbo",
110
+ torch_dtype=torch.bfloat16,
111
+ )
112
+
113
+ pipe.transformer = PeftModel.from_pretrained(
114
+ pipe.transformer,
115
+ "DownFlow/Z-Image-Turbo-Fuli-LoRA",
116
+ )
117
+ pipe.transformer = pipe.transformer.merge_and_unload()
118
+
119
+ pipe.to("cuda")
120
+
121
+ image = pipe(
122
+ prompt="by 年年, 1girl, white dress, cherry blossoms",
123
+ num_inference_steps=8,
124
+ guidance_scale=0.0,
125
+ ).images[0]
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Serving with vLLM
131
+
132
+ vLLM (≥ 0.8) supports serving diffusion pipelines via an OpenAI-compatible `/v1/images/generations` endpoint.
133
+
134
+ > **Recommended flow for vLLM**: use the pre-merged model so no PEFT dependency is needed at serve time.
135
+
136
+ ### Option A — Serve the merged model (recommended)
137
+
138
+ ```bash
139
+ pip install "vllm>=0.8.0"
140
+
141
+ vllm serve DownFlow/Z-Image-Turbo-Fuli \
142
+ --task generate \
143
+ --dtype bfloat16 \
144
+ --max-model-len 512 \
145
+ --port 8000
146
+ ```
147
+
148
+ Then call the endpoint:
149
+
150
+ ```bash
151
+ curl http://localhost:8000/v1/images/generations \
152
+ -H "Content-Type: application/json" \
153
+ -d '{
154
+ "model": "DownFlow/Z-Image-Turbo-Fuli",
155
+ "prompt": "by 蠢沫沫, 1girl, smile, soft watercolour style",
156
+ "n": 1,
157
+ "size": "512x512"
158
+ }'
159
+ ```
160
+
161
+ Or via the OpenAI Python SDK:
162
+
163
+ ```python
164
+ from openai import OpenAI
165
+
166
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")
167
+
168
+ response = client.images.generate(
169
+ model="DownFlow/Z-Image-Turbo-Fuli",
170
+ prompt="by 年年, 1girl, white dress, cherry blossoms",
171
+ n=1,
172
+ size="512x512",
173
+ )
174
+ print(response.data[0].url)
175
+ ```
176
+
177
+ ### Option B — Serve with dynamic LoRA (experimental)
178
+
179
+ vLLM supports dynamic LoRA module loading for LLMs; diffusion pipeline LoRA support is still experimental. If your vLLM build supports `--enable-lora` for image models:
180
+
181
+ ```bash
182
+ vllm serve Tongyi-MAI/Z-Image-Turbo \
183
+ --task generate \
184
+ --dtype bfloat16 \
185
+ --enable-lora \
186
+ --lora-modules "fuliji=DownFlow/Z-Image-Turbo-Fuli-LoRA" \
187
+ --port 8000
188
+ ```
189
+
190
+ Request with the LoRA active:
191
+
192
+ ```bash
193
+ curl http://localhost:8000/v1/images/generations \
194
+ -H "Content-Type: application/json" \
195
+ -d '{
196
+ "model": "fuliji",
197
+ "prompt": "by 雨波HaneAme, 1girl, beach, summer",
198
+ "n": 1,
199
+ "size": "512x512"
200
+ }'
201
+ ```
202
+
203
+ ---
204
+
205
+ ## Trained Artist Trigger Tokens
206
+
207
+ Prepend `by <artist>, ` at the start of your prompt.
208
+
209
+ | Token | Approx. images in training set |
210
+ |---|---|
211
+ | `萌芽儿o0` | 30 |
212
+ | `年年` | 26 |
213
+ | `封疆疆v` | 26 |
214
+ | `焖焖碳` | 26 |
215
+ | `星之迟迟` | 25 |
216
+ | `蠢沫沫` | 23 |
217
+ | `雨波HaneAme` | 23 |
218
+ | `清水由乃` | 21 |
219
+
220
+ ---
221
+
222
+ ## Training Details
223
+
224
+ - **Base model**: `Tongyi-MAI/Z-Image-Turbo` (8-step flow matching, CFG-free)
225
+ - **Method**: PEFT LoRA, rank=32, alpha=32, dropout=0.05
226
+ - **Dataset**: `DownFlow/fuliji` filtered to artists with ≥ 21 images
227
+ - **Steps**: 3 000 with EMA (decay=0.9999)
228
+ - **Optimizer**: AdamW, lr=1e-4, warmup=100 steps
229
+ - **Batch**: 1 × 4 gradient accumulation = effective batch 4
230
+ - **Augmentation**: horizontal flip, caption dropout 5%, timestep bias 1.2
231
+ - **Regularisation**: 25% of batches sample from a 277-image generic dataset
232
+ - **Hardware**: AMD MI300X, ROCm 6.2, bf16
233
+
234
+ ---
235
+
236
+ ## Related
237
+
238
+ - [DownFlow/Z-Image-Turbo-Fuli](https://huggingface.co/DownFlow/Z-Image-Turbo-Fuli) — merged model (LoRA baked in, ready for `vllm serve`)
239
+ - [DownFlow/fuliji](https://huggingface.co/datasets/DownFlow/fuliji) — training dataset
240
+ - [Tongyi-MAI/Z-Image-Turbo](https://huggingface.co/Tongyi-MAI/Z-Image-Turbo) — base model
adapter_config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": {
6
+ "base_model_class": "ZImageTransformer2DModel",
7
+ "parent_library": "diffusers.models.transformers.transformer_z_image"
8
+ },
9
+ "base_model_name_or_path": "Tongyi-MAI/Z-Image-Turbo",
10
+ "bias": "none",
11
+ "corda_config": null,
12
+ "ensure_weight_tying": false,
13
+ "eva_config": null,
14
+ "exclude_modules": null,
15
+ "fan_in_fan_out": false,
16
+ "inference_mode": true,
17
+ "init_lora_weights": true,
18
+ "layer_replication": null,
19
+ "layers_pattern": null,
20
+ "layers_to_transform": null,
21
+ "loftq_config": {},
22
+ "lora_alpha": 32.0,
23
+ "lora_bias": false,
24
+ "lora_dropout": 0.05,
25
+ "megatron_config": null,
26
+ "megatron_core": "megatron.core",
27
+ "modules_to_save": null,
28
+ "peft_type": "LORA",
29
+ "peft_version": "0.18.1",
30
+ "qalora_group_size": 16,
31
+ "r": 32,
32
+ "rank_pattern": {},
33
+ "revision": null,
34
+ "target_modules": [
35
+ "to_v",
36
+ "w2",
37
+ "w1",
38
+ "w3",
39
+ "to_q",
40
+ "to_k"
41
+ ],
42
+ "target_parameters": null,
43
+ "task_type": null,
44
+ "trainable_token_indices": null,
45
+ "use_dora": false,
46
+ "use_qalora": false,
47
+ "use_rslora": false
48
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:75c8f4c3c5e11f4f0782d4d472a24bfb5954dc1744150c3eace4297f88b8e78d
3
+ size 284151432