-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharticle_figures.py
More file actions
299 lines (220 loc) · 8.73 KB
/
article_figures.py
File metadata and controls
299 lines (220 loc) · 8.73 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 7 08:46:57 2024
@author: bemi
Generate plots for the article.
"""
from src.config_classes.ddpm_config import DDPMConfig
from src.config_classes.enc_dec_config import EncDecConfig
from src.config_classes.nn_config import NNConfig
from src.config_classes.optimizer_config import OptimizerConfig, OptimizerArgs
from src.config_classes.training_config import TrainingConfig
from src.evaluation import display
from src.evaluation.encoder_inspector import EncoderInspector
# Save relevant sample files in [base_folder] and relevant checkpoints in
# [base_folder]/checkpoints
# figures will be saved in [save_folder]
# Checkpoints:
# 2023-09-25_S3VA_fixed_-13_3_5_0_unet_32_unet_mult_res_4_m1_to_1_cifar10_2_128
# 2023-09-05_S3VA_fixed_-13_3_5_0_unet_8_unet_2_m1_to_1_mnist_1_128
#
# Sample files:
# 2023-08-22_S3VA_fixed_-13_3_5_0_unet_8_unet_2_m1_to_1_cifar10_2_128_1400000_samples_256_000.h5
# 2023-09-25_S3VA_fixed_-13_3_5_0_unet_32_unet_mult_res_4_m1_to_1_cifar10_2_128_8000000_samples_256_000.h5
# 2023-09-25_VDM2_V_fixed_-13_3_5_0_unet_32_simple_cifar10_2_128_8000000_samples_256_000.h5
def make_all_article_figures(base_folder: str, save_folder: str) -> None:
make_heatmaps(base_folder, save_folder)
make_comparison_of_samples(base_folder, save_folder)
make_encoded_mnist_example(base_folder, save_folder)
def make_heatmaps(base_folder: str, save_folder: str) -> None:
# 2023-09-25_S3VA_fixed_-13_3_5_0_unet_32_unet_mult_res_4_m1_to_1_cifar10_2_128
model_config = DDPMConfig(
ddpm_type='S3VA',
vocab_size=256,
sample_softmax=False,
n_timesteps = 0,
antithetic_time_sampling=True,
loss_parameterisation = 'eps_hat',
no_recon_loss = False,
# configurations of the noise schedule
gamma_type='fixed',
gamma_min=-13.3,
gamma_max=5.0,
# configurations of the score model
score_model_config = NNConfig(
m_type = 'unet',
with_fourier_features=True,
with_attention=False,
n_embd = 128,
n_layer = 32,
num_groups_groupnorm = 32,
p_dropout = 0.1,
down_conv = False,
pooling = False,
channel_scaling = 'same', # 'same' or 'double'
non_id_init = False
),
# configurations of the encoder
encoder_config = EncDecConfig(
enc_type = 'trainable', # simple, trainable
vocab_size = 256,
nn_config = NNConfig(
m_type = 'unet_mult_res',
with_fourier_features=True,
with_attention=False,
n_embd = 64,
n_layer = 4,
num_groups_groupnorm = 16,
p_dropout = 0.1,
down_conv = False,
pooling = True,
channel_scaling = 'double', # 'same' or 'double'
non_id_init = False
),
id_at_zero = False,
m1_to_1 = True,
k = 1.0,
gamma_reg = False,
end_reg = False,
end_half_reg = False
)
)
opt_config = OptimizerConfig(
name='adamw',
args=OptimizerArgs(
b1=0.9,
b2=0.99,
eps=1e-8,
weight_decay=0.01,
),
learning_rate=2e-4,
use_gradient_clipping = False,
gradient_clip_norm = 2.0
)
train_config = TrainingConfig(
dataset_name='cifar10_unconditional',
seed=2,
num_steps_train=5000,
batch_size=128,
steps_per_logging=100,
steps_per_eval=500,
steps_per_save=1000,
step_saves_to_keep = [20000, 100000],
profile=False,
)
#model_name = naming.get_model_name(model_config, train_config, opt_config)
inspector = EncoderInspector(
train_config, model_config, opt_config, base_folder, '2023-09-25', 8000000)
inspector.set_examples('eval', num_classes = 10, num_examples = 10,
eval_batch_idx = 2)
inspector.get_article_heatmaps_x_t_changes(
save_folder, # save_to_folder
show_late_t = False,
ts_for_table = [4, 6, 8, 10],
example_idxs = [1, 3, 4, 7],
move_to_0_to_1_from_m2_2 = True)
inspector.get_article_heatmaps_x_t_changes(
save_folder, # save_to_folder
show_late_t = False,
ts_for_table = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
example_idxs = [1, 3, 4, 7, 0, 2, 5, 6, 8, 9],
move_to_0_to_1_from_m2_2 = True)
def make_comparison_of_samples(
base_folder: str, save_folder: str) -> None:
sample_files = [
'2023-08-22_S3VA_fixed_-13_3_5_0_unet_8_unet_2_m1_to_1_cifar10_2_128_1400000_samples_256_000.h5',
'2023-09-25_S3VA_fixed_-13_3_5_0_unet_32_unet_mult_res_4_m1_to_1_cifar10_2_128_8000000_samples_256_000.h5',
'2023-09-25_VDM2_V_fixed_-13_3_5_0_unet_32_simple_cifar10_2_128_8000000_samples_256_000.h5'
]
display.display_comparison_samples_from_h5(
base_folder, sample_files, dataset = 'cifar10', save_dir = save_folder)
def make_encoded_mnist_example(base_folder: str, save_folder: str) -> None:
# 2023-09-05_S3VA_fixed_-13_3_5_0_unet_8_unet_2_m1_to_1_mnist_1_128
model_config = DDPMConfig(
ddpm_type='S3VA',
vocab_size=256,
sample_softmax=False,
n_timesteps = 0,
antithetic_time_sampling=True,
loss_parameterisation = 'eps_hat',
no_recon_loss = False,
# configurations of the noise schedule
gamma_type='fixed', # learnable_scalar / fixed
gamma_min=-13.3,
gamma_max=5.0,
# configurations of the score model
score_model_config = NNConfig(
m_type = 'unet',
with_fourier_features=True,
with_attention=False,
n_embd = 128,
n_layer = 8,
num_groups_groupnorm = 32,
p_dropout = 0.1,
down_conv = False,
pooling = False,
channel_scaling = 'same', # 'same' or 'double'
non_id_init = False
),
# configurations of the encoder
encoder_config = EncDecConfig(
enc_type = 'trainable', # simple, trainable, trainable_t
vocab_size = 256,
nn_config = NNConfig(
m_type = 'unet',
with_fourier_features=True,
with_attention=False,
n_embd = 64,
n_layer = 2,
num_groups_groupnorm = 16,
p_dropout = 0.1,
down_conv = False,
pooling = True,
channel_scaling = 'double', # 'same' or 'double'
non_id_init = False
),
id_at_zero = False,
m1_to_1 = True,
k = 1.0,
gamma_reg = False,
end_reg = False,
end_half_reg = False
)
)
opt_config = OptimizerConfig(
name='adamw',
args=OptimizerArgs(
b1=0.9,
b2=0.99,
eps=1e-8,
weight_decay=0.01,
),
learning_rate=2e-4,
use_gradient_clipping = False,
gradient_clip_norm = 2.0
)
train_config = TrainingConfig(
dataset_name='mnist_unconditional',
seed=1,
num_steps_train=5000,
batch_size=128,
steps_per_logging=100,
steps_per_eval=500,
steps_per_save=1000,
step_saves_to_keep = [20000, 100000],
profile=False,
)
#model_name = naming.get_model_name(model_config, train_config, opt_config)
inspector = EncoderInspector(
train_config, model_config, opt_config, base_folder, '2023-09-05', 1400000)
inspector.set_examples('eval', num_classes = 10, num_examples = 10,
eval_batch_idx = 2)
inspector.get_encoded_for_ts(save_folder,
ts_for_table = [0.0, 0.70, 0.80, 0.90, 0.92, 0.94, 0.96, 0.98, 1.0],
example_idxs = [0, 3, 6, 9],
move_to_0_to_1_from_m1_1 = True)
# base_folder = 'insert_base_folder_here'
# save_folder = 'insert_base_folder_here'
#
# make_all_article_figures(base_folder, save_folder)