-
Notifications
You must be signed in to change notification settings - Fork 1
/
templates_latent.py
executable file
·202 lines (176 loc) · 6.57 KB
/
templates_latent.py
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
196
197
198
199
200
201
202
from templates import *
def latent_diffusion_config(conf: TrainConfig):
conf.batch_size = 128
conf.train_mode = TrainMode.latent_diffusion
conf.latent_gen_type = GenerativeType.ddim
conf.latent_loss_type = LossType.mse
conf.latent_model_mean_type = ModelMeanType.eps
conf.latent_model_var_type = ModelVarType.fixed_large
conf.latent_rescale_timesteps = False
conf.latent_clip_sample = False
conf.latent_T_eval = 20
conf.latent_znormalize = True
conf.total_samples = 96_000_000
conf.sample_every_samples = 400_000
conf.eval_every_samples = 20_000_000
conf.eval_ema_every_samples = 20_000_000
conf.save_every_samples = 2_000_000
return conf
def latent_diffusion128_config(conf: TrainConfig):
conf = latent_diffusion_config(conf)
conf.batch_size_eval = 32
return conf
def latent_mlp_2048_norm_10layers(conf: TrainConfig):
conf.net_latent_net_type = LatentNetType.skip
conf.net_latent_layers = 10
conf.net_latent_skip_layers = list(range(1, conf.net_latent_layers))
conf.net_latent_activation = Activation.silu
conf.net_latent_num_hid_channels = 2048
conf.net_latent_use_norm = True
conf.net_latent_condition_bias = 1
return conf
def latent_mlp_2048_norm_20layers(conf: TrainConfig):
conf = latent_mlp_2048_norm_10layers(conf)
conf.net_latent_layers = 20
conf.net_latent_skip_layers = list(range(1, conf.net_latent_layers))
return conf
def latent_256_batch_size(conf: TrainConfig):
conf.batch_size = 256
conf.eval_ema_every_samples = 100_000_000
conf.eval_every_samples = 100_000_000
conf.sample_every_samples = 1_000_000
conf.save_every_samples = 2_000_000
conf.total_samples = 301_000_000
return conf
def latent_512_batch_size(conf: TrainConfig):
conf.batch_size = 512
conf.eval_ema_every_samples = 100_000_000
conf.eval_every_samples = 100_000_000
conf.sample_every_samples = 1_000_000
conf.save_every_samples = 5_000_000
conf.total_samples = 501_000_000
return conf
def latent_2048_batch_size(conf: TrainConfig):
conf.batch_size = 2048
conf.eval_ema_every_samples = 200_000_000
conf.eval_every_samples = 200_000_000
conf.sample_every_samples = 4_000_000
conf.save_every_samples = 20_000_000
conf.total_samples = 1_501_000_000
return conf
def adamw_weight_decay(conf: TrainConfig):
conf.optimizer = OptimizerType.adamw
conf.weight_decay = 0.01
return conf
def ffhq128_autoenc_latent():
conf = pretrain_ffhq128_autoenc130M()
conf = latent_diffusion128_config(conf)
conf = latent_mlp_2048_norm_10layers(conf)
conf = latent_256_batch_size(conf)
conf = adamw_weight_decay(conf)
conf.total_samples = 101_000_000
conf.latent_loss_type = LossType.l1
conf.latent_beta_scheduler = 'const0.008'
conf.name = 'ffhq128_autoenc_latent'
return conf
def ffhq256_autoenc_latent():
conf = pretrain_ffhq256_autoenc()
conf = latent_diffusion_config(conf)
conf = latent_512_batch_size(conf)
conf = latent_mlp_2048_norm_10layers(conf)
conf = adamw_weight_decay(conf)
conf.name = 'ffhq256_autoenc_latent'
conf.continue_from = None
conf.postfix = '_500M'
conf.total_samples = 60_000_000
conf.sample_every_samples = 100_000_000
conf.latent_beta_scheduler = 'const0.008'
conf.latent_loss_type = LossType.l1
return conf
def church256_autoenc_latent():
conf = pretrain_church256_autoenc()
conf = latent_diffusion_config(conf)
conf = latent_512_batch_size(conf)
conf = latent_mlp_2048_norm_10layers(conf)
conf = adamw_weight_decay(conf)
conf.name = 'church256_autoenc_latent'
conf.continue_from = None
conf.postfix = '_500M'
conf.total_samples = 60_000_000
conf.sample_every_samples = 100_000_000
conf.latent_beta_scheduler = 'const0.008'
conf.latent_loss_type = LossType.l1
return conf
def bedroom256_autoenc_latent():
conf = pretrain_bedroom256_autoenc()
conf = latent_diffusion_config(conf)
conf = latent_512_batch_size(conf)
conf = latent_mlp_2048_norm_10layers(conf)
conf = adamw_weight_decay(conf)
conf.name = 'bedroom256_autoenc_latent'
conf.continue_from = None
conf.postfix = '_500M'
conf.total_samples = 60_000_000
conf.sample_every_samples = 100_000_000
conf.latent_beta_scheduler = 'const0.008'
conf.latent_loss_type = LossType.l1
return conf
def nature1024_autoenc_latent():
conf = pretrain_nature1024_autoenc()
conf = latent_diffusion_config(conf)
conf = latent_512_batch_size(conf)
conf = latent_mlp_2048_norm_10layers(conf)
conf = adamw_weight_decay(conf)
conf.name = 'nature1024_autoenc_latent'
conf.continue_from = None
conf.postfix = '_500M'
conf.total_samples = 60_000_000
conf.sample_every_samples = 100_000_000
conf.latent_beta_scheduler = 'const0.008'
conf.latent_loss_type = LossType.l1
return conf
def train_autoenc_latent():
conf = pretrain_autoenc()
conf = latent_diffusion_config(conf)
conf = latent_512_batch_size(conf)
conf = latent_mlp_2048_norm_10layers(conf)
conf = adamw_weight_decay(conf)
conf.name = 'train_autoenc_latent'
conf.continue_from = None
conf.postfix = '_500M'
conf.total_samples = 60_000_000
conf.sample_every_samples = 100_000_000
conf.latent_beta_scheduler = 'const0.008'
conf.latent_loss_type = LossType.l1
return conf
def lhq1024_autoenc_latent():
conf = pretrain_lhq1024_autoenc()
conf = latent_diffusion_config(conf)
conf = latent_512_batch_size(conf)
conf = latent_mlp_2048_norm_10layers(conf)
conf = adamw_weight_decay(conf)
# just for the name
conf.name = 'lhq1024_autoenc_latent'
conf.continue_from = None #PretrainConfig('200M', f'log-latent/{conf.name}/last.ckpt')
conf.postfix = '_500M'
conf.total_samples = 60_000_000
conf.sample_every_samples = 100_000_000
conf.latent_beta_scheduler = 'const0.008'
conf.latent_loss_type = LossType.l1
# conf.name = 'ffhq256d2c_autoenc_latent'
return conf
def ffhq1024_autoenc_latent():
conf = pretrain_ffhq1024_autoenc()
conf = latent_diffusion_config(conf)
conf = latent_512_batch_size(conf)
conf = latent_mlp_2048_norm_10layers(conf)
conf = adamw_weight_decay(conf)
# just for the name
conf.name = 'ffhq1024_autoenc_latent'
conf.continue_from = None #PretrainConfig('200M', f'log-latent/{conf.name}/last.ckpt')
conf.postfix = '_500M'
conf.total_samples = 60_000_000
conf.sample_every_samples = 100_000_000
conf.latent_beta_scheduler = 'const0.008'
conf.latent_loss_type = LossType.l1
return conf