-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_sid.sh
196 lines (159 loc) · 5.41 KB
/
run_sid.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
model=$1
# Uncomment to set CUDA visible devices and run specific script
# export CUDA_VISIBLE_DEVICES=0,1,2,3
#sh run_sid.sh 'sd1.5'
#sh run_sid.sh 'sd2.1_base'
#sh run_sid.sh 'sd1.5_fp16'
#sh run_sid.sh 'sd2.1_base_fp16'
# Modify --duration to reproduce the reported results
# kappa1 = cfg_train_fake
# kappa2=kappa3 = cfg_eval_fake
# kappa4 = cfg_eval_real
# To resume from a saved checkpoint, add the following option:
# --resume 'image_experiment/sid-lsg-train-runs/*.pt'
# If your system has sufficient memory, you can choose to evaluate both FID and CLIP scores during training by adding:
# --metrics 'fid_clip_30k_full'
# otherwise, you can compute FID only:
# --metrics 'fid30k_full'
# or don't specify `metrics` so it will take the default value of None.
# To reproduce the results reported in the paper, choose `--enable_xformers 0' and then run
# sh run_sid.sh 'sd1.5'
# sh run_sid.sh 'sd2.1-base'
# As mentioned in the paper, our computing infrastracture used for SiD-LSG does not support xformers but it is highly recommeded to enable it if your computing platform allows it; see `https://huggingface.co/docs/diffusers/v0.21.0/en/optimization/xformers` for more details
# If memory constraints are a concern, consider training the model using 16-bit floating point precision (fp16):
# sh run_sid.sh 'sd1.5-fp16'
# sh run_sid.sh 'sd2.1-base-fp16'
# While this approach significantly reduces memory and is also found to lead to faster convergence, it will require gradient clipping to prevent suddern divergence and result in inferior model performance. See Figure 7 of https://arxiv.org/abs/2406.01561 for more details.
# You can save memory by disabling the Exponential Moving Average (EMA) feature. To do this, add:
# --ema 0
# You can also consider enableing gradient_checkpointing to save memory:
# --gradient_checkpointing 1
if [ "$model" = 'sd1.5' ]; then
# Command to run torch with specific parameters
torchrun --standalone --nproc_per_node=4 sid_train.py \
--outdir 'image_experiment/sid-lsg-train-runs/' \
--data '/data/datasets/MS-COCO-256/val' \
--train_mode 1 \
--cfg_train_fake 2 \
--cfg_eval_fake 2 \
--cfg_eval_real 2 \
--optimizer 'adam' \
--data_prompt_text '/data/datasets/aesthetics_6_plus' \
--resolution 512 \
--alpha 1 \
--init_timestep 625 \
--batch 512 \
--fp16 0 \
--batch-gpu 1 \
--sd_model "runwayml/stable-diffusion-v1-5" \
--tick 2 \
--snap 50 \
--dump 100 \
--lr 0.000001 \
--glr 0.000001 \
--duration 10 \
--enable_xformers 1 \
--gradient_checkpointing 0 \
--metrics 'fid30k_full' \
--ema 0.05
#--nosubdir \
#--metrics 'fid_30k_full' \
#--metrics 'fid_clip_30k_full' \
#--ema 0.05
elif [ "$model" = 'sd2.1_base' ]; then
torchrun --standalone --nproc_per_node=4 sid_train.py \
--outdir 'image_experiment/sid-lsg-train-runs/' \
--data '/data/datasets/MS-COCO-256/val' \
--train_mode 1 \
--cfg_train_fake 2 \
--cfg_eval_fake 2 \
--cfg_eval_real 2 \
--optimizer 'adam' \
--data_prompt_text '/data/datasets/aesthetics_6_plus' \
--resolution 512 \
--alpha 1 \
--init_timestep 625 \
--batch 512 \
--fp16 0 \
--batch-gpu 1 \
--sd_model "stabilityai/stable-diffusion-2-1-base" \
--tick 2 \
--snap 50 \
--dump 100 \
--lr 0.000001 \
--glr 0.000001 \
--duration 10 \
--enable_xformers 1 \
--gradient_checkpointing 0 \
--ema 0.05
#--nosubdir \
#--metrics 'fid_30k_full' \
#--metrics 'fid_clip_30k_full' \
#--ema 0.05
elif [ "$model" = 'sd1.5_fp16' ]; then
# Command to run torch with specific parameters
torchrun --standalone --nproc_per_node=4 sid_train.py \
--outdir 'image_experiment/sid-lsg-train-runs/' \
--data '/data/datasets/MS-COCO-256/val' \
--train_mode 1 \
--cfg_train_fake 2 \
--cfg_eval_fake 2 \
--cfg_eval_real 2 \
--optimizer 'adam' \
--data_prompt_text '/data/datasets/aesthetics_6_plus' \
--resolution 512 \
--alpha 1 \
--init_timestep 625 \
--batch 512 \
--fp16 1 \
--batch-gpu 1 \
--sd_model "runwayml/stable-diffusion-v1-5" \
--tick 2 \
--snap 50 \
--dump 100 \
--lr 0.000001 \
--glr 0.000001 \
--duration 10 \
--enable_xformers 1 \
--gradient_checkpointing 0 \
--metrics 'fid30k_full' \
--ema 0 #0.05
#--nosubdir \
#--metrics 'fid_30k_full' \
#--metrics 'fid_clip_30k_full' \
#--ema 0.05
elif [ "$model" = 'sd2.1_base_fp16' ]; then
torchrun --standalone --nproc_per_node=4 sid_train.py \
--outdir 'image_experiment/sid-lsg-train-runs/' \
--data '/data/datasets/MS-COCO-256/val' \
--train_mode 1 \
--cfg_train_fake 2 \
--cfg_eval_fake 2 \
--cfg_eval_real 2 \
--optimizer 'adam' \
--data_prompt_text '/data/datasets/aesthetics_6_plus' \
--resolution 512 \
--alpha 1 \
--init_timestep 625 \
--batch 512 \
--fp16 1 \
--batch-gpu 1 \
--sd_model "stabilityai/stable-diffusion-2-1-base" \
--tick 2 \
--snap 50 \
--dump 100 \
--lr 0.000001 \
--glr 0.000001 \
--duration 10 \
--enable_xformers 1 \
--gradient_checkpointing 0 \
--ema 0 #0.05
#--nosubdir \
#--metrics 'fid_30k_full' \
#--metrics 'fid_clip_30k_full' \
#--ema 0.05
else
echo "Invalid dataset specified"
exit 1
fi