Skip to content

Commit 4039815

Browse files
open muse (#5437)
amused rename Update docs/source/en/api/pipelines/amused.md Co-authored-by: Patrick von Platen <[email protected]> AdaLayerNormContinuous default values custom micro conditioning micro conditioning docs put lookup from codebook in constructor fix conversion script remove manual fused flash attn kernel add training script temp remove training script add dummy gradient checkpointing func clarify temperatures is an instance variable by setting it remove additional SkipFF block args hardcode norm args rename tests folder fix paths and samples fix tests add training script training readme lora saving and loading non-lora saving/loading some readme fixes guards Update docs/source/en/api/pipelines/amused.md Co-authored-by: Suraj Patil <[email protected]> Update examples/amused/README.md Co-authored-by: Suraj Patil <[email protected]> Update examples/amused/train_amused.py Co-authored-by: Suraj Patil <[email protected]> vae upcasting add fp16 integration tests use tuple for micro cond copyrights remove casts delegate to torch.nn.LayerNorm move temperature to pipeline call upsampling/downsampling changes
1 parent 5b186b7 commit 4039815

30 files changed

+4789
-24
lines changed

docs/source/en/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@
244244
- sections:
245245
- local: api/pipelines/overview
246246
title: Overview
247+
- local: api/pipelines/amused
248+
title: aMUSEd
247249
- local: api/pipelines/animatediff
248250
title: AnimateDiff
249251
- local: api/pipelines/attend_and_excite
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# aMUSEd
14+
15+
Amused is a lightweight text to image model based off of the [muse](https://arxiv.org/pdf/2301.00704.pdf) architecture. Amused is particularly useful in applications that require a lightweight and fast model such as generating many images quickly at once.
16+
17+
Amused is a vqvae token based transformer that can generate an image in fewer forward passes than many diffusion models. In contrast with muse, it uses the smaller text encoder CLIP-L/14 instead of t5-xxl. Due to its small parameter count and few forward pass generation process, amused can generate many images quickly. This benefit is seen particularly at larger batch sizes.
18+
19+
| Model | Params |
20+
|-------|--------|
21+
| [amused-256](https://huggingface.co/huggingface/amused-256) | 603M |
22+
| [amused-512](https://huggingface.co/huggingface/amused-512) | 608M |
23+
24+
## AmusedPipeline
25+
26+
[[autodoc]] AmusedPipeline
27+
- __call__
28+
- all
29+
- enable_xformers_memory_efficient_attention
30+
- disable_xformers_memory_efficient_attention

examples/amused/README.md

Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,326 @@
1+
## Amused training
2+
3+
Amused can be finetuned on simple datasets relatively cheaply and quickly. Using 8bit optimizers, lora, and gradient accumulation, amused can be finetuned with as little as 5.5 GB. Here are a set of examples for finetuning amused on some relatively simple datasets. These training recipies are aggressively oriented towards minimal resources and fast verification -- i.e. the batch sizes are quite low and the learning rates are quite high. For optimal quality, you will probably want to increase the batch sizes and decrease learning rates.
4+
5+
All training examples use fp16 mixed precision and gradient checkpointing. We don't show 8 bit adam + lora as its about the same memory use as just using lora (bitsandbytes uses full precision optimizer states for weights below a minimum size).
6+
7+
### Finetuning the 256 checkpoint
8+
9+
These examples finetune on this [nouns](https://huggingface.co/datasets/m1guelpf/nouns) dataset.
10+
11+
Example results:
12+
13+
![noun1](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/noun1.png) ![noun2](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/noun2.png) ![noun3](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/noun3.png)
14+
15+
16+
#### Full finetuning
17+
18+
Batch size: 8, Learning rate: 1e-4, Gives decent results in 750-1000 steps
19+
20+
| Batch Size | Gradient Accumulation Steps | Effective Total Batch Size | Memory Used |
21+
|------------|-----------------------------|------------------|-------------|
22+
| 8 | 1 | 8 | 19.7 GB |
23+
| 4 | 2 | 8 | 18.3 GB |
24+
| 1 | 8 | 8 | 17.9 GB |
25+
26+
```sh
27+
accelerate launch train_amused.py \
28+
--output_dir <output path> \
29+
--train_batch_size <batch size> \
30+
--gradient_accumulation_steps <gradient accumulation steps> \
31+
--learning_rate 1e-4 \
32+
--pretrained_model_name_or_path huggingface/amused-256 \
33+
--instance_data_dataset 'm1guelpf/nouns' \
34+
--image_key image \
35+
--prompt_key text \
36+
--resolution 256 \
37+
--mixed_precision fp16 \
38+
--lr_scheduler constant \
39+
--validation_prompts \
40+
'a pixel art character with square red glasses, a baseball-shaped head and a orange-colored body on a dark background' \
41+
'a pixel art character with square orange glasses, a lips-shaped head and a red-colored body on a light background' \
42+
'a pixel art character with square blue glasses, a microwave-shaped head and a purple-colored body on a sunny background' \
43+
'a pixel art character with square red glasses, a baseball-shaped head and a blue-colored body on an orange background' \
44+
'a pixel art character with square red glasses' \
45+
'a pixel art character' \
46+
'square red glasses on a pixel art character' \
47+
'square red glasses on a pixel art character with a baseball-shaped head' \
48+
--max_train_steps 10000 \
49+
--checkpointing_steps 500 \
50+
--validation_steps 250 \
51+
--gradient_checkpointing
52+
```
53+
54+
#### Full finetuning + 8 bit adam
55+
56+
Note that this training config keeps the batch size low and the learning rate high to get results fast with low resources. However, due to 8 bit adam, it will diverge eventually. If you want to train for longer, you will have to up the batch size and lower the learning rate.
57+
58+
Batch size: 16, Learning rate: 2e-5, Gives decent results in ~750 steps
59+
60+
| Batch Size | Gradient Accumulation Steps | Effective Total Batch Size | Memory Used |
61+
|------------|-----------------------------|------------------|-------------|
62+
| 16 | 1 | 16 | 20.1 GB |
63+
| 8 | 2 | 16 | 15.6 GB |
64+
| 1 | 16 | 16 | 10.7 GB |
65+
66+
```sh
67+
accelerate launch train_amused.py \
68+
--output_dir <output path> \
69+
--train_batch_size <batch size> \
70+
--gradient_accumulation_steps <gradient accumulation steps> \
71+
--learning_rate 2e-5 \
72+
--use_8bit_adam \
73+
--pretrained_model_name_or_path huggingface/amused-256 \
74+
--instance_data_dataset 'm1guelpf/nouns' \
75+
--image_key image \
76+
--prompt_key text \
77+
--resolution 256 \
78+
--mixed_precision fp16 \
79+
--lr_scheduler constant \
80+
--validation_prompts \
81+
'a pixel art character with square red glasses, a baseball-shaped head and a orange-colored body on a dark background' \
82+
'a pixel art character with square orange glasses, a lips-shaped head and a red-colored body on a light background' \
83+
'a pixel art character with square blue glasses, a microwave-shaped head and a purple-colored body on a sunny background' \
84+
'a pixel art character with square red glasses, a baseball-shaped head and a blue-colored body on an orange background' \
85+
'a pixel art character with square red glasses' \
86+
'a pixel art character' \
87+
'square red glasses on a pixel art character' \
88+
'square red glasses on a pixel art character with a baseball-shaped head' \
89+
--max_train_steps 10000 \
90+
--checkpointing_steps 500 \
91+
--validation_steps 250 \
92+
--gradient_checkpointing
93+
```
94+
95+
#### Full finetuning + lora
96+
97+
Batch size: 16, Learning rate: 8e-4, Gives decent results in 1000-1250 steps
98+
99+
| Batch Size | Gradient Accumulation Steps | Effective Total Batch Size | Memory Used |
100+
|------------|-----------------------------|------------------|-------------|
101+
| 16 | 1 | 16 | 14.1 GB |
102+
| 8 | 2 | 16 | 10.1 GB |
103+
| 1 | 16 | 16 | 6.5 GB |
104+
105+
```sh
106+
accelerate launch train_amused.py \
107+
--output_dir <output path> \
108+
--train_batch_size <batch size> \
109+
--gradient_accumulation_steps <gradient accumulation steps> \
110+
--learning_rate 8e-4 \
111+
--use_lora \
112+
--pretrained_model_name_or_path huggingface/amused-256 \
113+
--instance_data_dataset 'm1guelpf/nouns' \
114+
--image_key image \
115+
--prompt_key text \
116+
--resolution 256 \
117+
--mixed_precision fp16 \
118+
--lr_scheduler constant \
119+
--validation_prompts \
120+
'a pixel art character with square red glasses, a baseball-shaped head and a orange-colored body on a dark background' \
121+
'a pixel art character with square orange glasses, a lips-shaped head and a red-colored body on a light background' \
122+
'a pixel art character with square blue glasses, a microwave-shaped head and a purple-colored body on a sunny background' \
123+
'a pixel art character with square red glasses, a baseball-shaped head and a blue-colored body on an orange background' \
124+
'a pixel art character with square red glasses' \
125+
'a pixel art character' \
126+
'square red glasses on a pixel art character' \
127+
'square red glasses on a pixel art character with a baseball-shaped head' \
128+
--max_train_steps 10000 \
129+
--checkpointing_steps 500 \
130+
--validation_steps 250 \
131+
--gradient_checkpointing
132+
```
133+
134+
### Finetuning the 512 checkpoint
135+
136+
These examples finetune on this [minecraft](https://huggingface.co/monadical-labs/minecraft-preview) dataset.
137+
138+
Example results:
139+
140+
![minecraft1](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/minecraft1.png) ![minecraft2](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/minecraft2.png) ![minecraft3](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/minecraft3.png)
141+
142+
#### Full finetuning
143+
144+
Batch size: 8, Learning rate: 8e-5, Gives decent results in 500-1000 steps
145+
146+
| Batch Size | Gradient Accumulation Steps | Effective Total Batch Size | Memory Used |
147+
|------------|-----------------------------|------------------|-------------|
148+
| 8 | 1 | 8 | 24.2 GB |
149+
| 4 | 2 | 8 | 19.7 GB |
150+
| 1 | 8 | 8 | 16.99 GB |
151+
152+
```sh
153+
accelerate launch train_amused.py \
154+
--output_dir <output path> \
155+
--train_batch_size <batch size> \
156+
--gradient_accumulation_steps <gradient accumulation steps> \
157+
--learning_rate 8e-5 \
158+
--pretrained_model_name_or_path huggingface/amused-512 \
159+
--instance_data_dataset 'monadical-labs/minecraft-preview' \
160+
--prompt_prefix 'minecraft ' \
161+
--image_key image \
162+
--prompt_key text \
163+
--resolution 512 \
164+
--mixed_precision fp16 \
165+
--lr_scheduler constant \
166+
--validation_prompts \
167+
'minecraft Avatar' \
168+
'minecraft character' \
169+
'minecraft' \
170+
'minecraft president' \
171+
'minecraft pig' \
172+
--max_train_steps 10000 \
173+
--checkpointing_steps 500 \
174+
--validation_steps 250 \
175+
--gradient_checkpointing
176+
```
177+
178+
#### Full finetuning + 8 bit adam
179+
180+
Batch size: 8, Learning rate: 5e-6, Gives decent results in 500-1000 steps
181+
182+
| Batch Size | Gradient Accumulation Steps | Effective Total Batch Size | Memory Used |
183+
|------------|-----------------------------|------------------|-------------|
184+
| 8 | 1 | 8 | 21.2 GB |
185+
| 4 | 2 | 8 | 13.3 GB |
186+
| 1 | 8 | 8 | 9.9 GB |
187+
188+
```sh
189+
accelerate launch train_amused.py \
190+
--output_dir <output path> \
191+
--train_batch_size <batch size> \
192+
--gradient_accumulation_steps <gradient accumulation steps> \
193+
--learning_rate 5e-6 \
194+
--pretrained_model_name_or_path huggingface/amused-512 \
195+
--instance_data_dataset 'monadical-labs/minecraft-preview' \
196+
--prompt_prefix 'minecraft ' \
197+
--image_key image \
198+
--prompt_key text \
199+
--resolution 512 \
200+
--mixed_precision fp16 \
201+
--lr_scheduler constant \
202+
--validation_prompts \
203+
'minecraft Avatar' \
204+
'minecraft character' \
205+
'minecraft' \
206+
'minecraft president' \
207+
'minecraft pig' \
208+
--max_train_steps 10000 \
209+
--checkpointing_steps 500 \
210+
--validation_steps 250 \
211+
--gradient_checkpointing
212+
```
213+
214+
#### Full finetuning + lora
215+
216+
Batch size: 8, Learning rate: 1e-4, Gives decent results in 500-1000 steps
217+
218+
| Batch Size | Gradient Accumulation Steps | Effective Total Batch Size | Memory Used |
219+
|------------|-----------------------------|------------------|-------------|
220+
| 8 | 1 | 8 | 12.7 GB |
221+
| 4 | 2 | 8 | 9.0 GB |
222+
| 1 | 8 | 8 | 5.6 GB |
223+
224+
```sh
225+
accelerate launch train_amused.py \
226+
--output_dir <output path> \
227+
--train_batch_size <batch size> \
228+
--gradient_accumulation_steps <gradient accumulation steps> \
229+
--learning_rate 1e-4 \
230+
--use_lora \
231+
--pretrained_model_name_or_path huggingface/amused-512 \
232+
--instance_data_dataset 'monadical-labs/minecraft-preview' \
233+
--prompt_prefix 'minecraft ' \
234+
--image_key image \
235+
--prompt_key text \
236+
--resolution 512 \
237+
--mixed_precision fp16 \
238+
--lr_scheduler constant \
239+
--validation_prompts \
240+
'minecraft Avatar' \
241+
'minecraft character' \
242+
'minecraft' \
243+
'minecraft president' \
244+
'minecraft pig' \
245+
--max_train_steps 10000 \
246+
--checkpointing_steps 500 \
247+
--validation_steps 250 \
248+
--gradient_checkpointing
249+
```
250+
251+
### Styledrop
252+
253+
[Styledrop](https://arxiv.org/abs/2306.00983) is an efficient finetuning method for learning a new style from just one or very few images. It has an optional first stage to generate human picked additional training samples. The additional training samples can be used to augment the initial images. Our examples exclude the optional additional image selection stage and instead we just finetune on a single image.
254+
255+
This is our example style image:
256+
![example](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/A%20mushroom%20in%20%5BV%5D%20style.png)
257+
258+
Download it to your local directory with
259+
```sh
260+
wget https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/A%20mushroom%20in%20%5BV%5D%20style.png
261+
```
262+
263+
#### 256
264+
265+
Example results:
266+
267+
![glowing_256_1](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/glowing_256_1.png) ![glowing_256_2](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/glowing_256_2.png) ![glowing_256_3](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/glowing_256_3.png)
268+
269+
Learning rate: 4e-4, Gives decent results in 1500-2000 steps
270+
271+
Memory used: 6.5 GB
272+
273+
```sh
274+
accelerate launch train_amused.py \
275+
--output_dir <output path> \
276+
--mixed_precision fp16 \
277+
--report_to wandb \
278+
--use_lora \
279+
--pretrained_model_name_or_path huggingface/amused-256 \
280+
--train_batch_size 1 \
281+
--lr_scheduler constant \
282+
--learning_rate 4e-4 \
283+
--validation_prompts \
284+
'A chihuahua walking on the street in [V] style' \
285+
'A banana on the table in [V] style' \
286+
'A church on the street in [V] style' \
287+
'A tabby cat walking in the forest in [V] style' \
288+
--instance_data_image 'A mushroom in [V] style.png' \
289+
--max_train_steps 10000 \
290+
--checkpointing_steps 500 \
291+
--validation_steps 100 \
292+
--resolution 256
293+
```
294+
295+
#### 512
296+
297+
Example results:
298+
299+
![glowing_512_1](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/glowing_512_1.png) ![glowing_512_2](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/glowing_512_2.png) ![glowing_512_3](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/glowing_512_3.png)
300+
301+
Learning rate: 1e-3, Lora alpha 1, Gives decent results in 1500-2000 steps
302+
303+
Memory used: 5.6 GB
304+
305+
```
306+
accelerate launch train_amused.py \
307+
--output_dir <output path> \
308+
--mixed_precision fp16 \
309+
--report_to wandb \
310+
--use_lora \
311+
--pretrained_model_name_or_path huggingface/amused-512 \
312+
--train_batch_size 1 \
313+
--lr_scheduler constant \
314+
--learning_rate 1e-3 \
315+
--validation_prompts \
316+
'A chihuahua walking on the street in [V] style' \
317+
'A banana on the table in [V] style' \
318+
'A church on the street in [V] style' \
319+
'A tabby cat walking in the forest in [V] style' \
320+
--instance_data_image 'A mushroom in [V] style.png' \
321+
--max_train_steps 100000 \
322+
--checkpointing_steps 500 \
323+
--validation_steps 100 \
324+
--resolution 512 \
325+
--lora_alpha 1
326+
```

0 commit comments

Comments
 (0)