-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_train.py
More file actions
29 lines (25 loc) · 918 Bytes
/
utils_train.py
File metadata and controls
29 lines (25 loc) · 918 Bytes
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
from tab_ddpm.modules import MLPDiffusion, ResNetDiffusion
def get_model(
model_name,
model_params,
n_num_features,
category_sizes
):
print(model_name)
if model_name == 'mlp':
model = MLPDiffusion(**model_params, category_sizes=category_sizes)
elif model_name == 'resnet':
model = ResNetDiffusion(**model_params)
else:
raise "Unknown model!"
return model
def update_ema(target_params, source_params, rate=0.999):
"""
Update target parameters to be closer to those of source parameters using
an exponential moving average.
:param target_params: the target parameter sequence.
:param source_params: the source parameter sequence.
:param rate: the EMA rate (closer to 1 means slower).
"""
for targ, src in zip(target_params, source_params):
targ.detach().mul_(rate).add_(src.detach(), alpha=1 - rate)