Change scheduling by step to by epoch
This commit is contained in:
35
train_ms.py
35
train_ms.py
@@ -347,19 +347,18 @@ def run():
|
|||||||
epoch_str = 1
|
epoch_str = 1
|
||||||
global_step = 0
|
global_step = 0
|
||||||
|
|
||||||
steps_per_epoch = len(train_loader)
|
def lr_lambda(epoch):
|
||||||
warmup_steps = hps.train.warmup_epochs * steps_per_epoch
|
"""
|
||||||
|
Learning rate scheduler for warmup and exponential decay.
|
||||||
def lr_lambda(step):
|
- During the warmup period, the learning rate increases linearly.
|
||||||
"""for warmup"""
|
- After the warmup period, the learning rate decreases exponentially.
|
||||||
if step < warmup_steps:
|
"""
|
||||||
return step / warmup_steps
|
if epoch < hps.train.warmup_epochs:
|
||||||
|
return float(epoch) / float(max(1, hps.train.warmup_epochs))
|
||||||
else:
|
else:
|
||||||
return hps.train.lr_decay ** (step - warmup_steps)
|
return hps.train.lr_decay ** (epoch - hps.train.warmup_epochs)
|
||||||
|
|
||||||
scheduler_last_epoch = -1
|
scheduler_last_epoch = epoch_str - 2
|
||||||
if global_step > 0:
|
|
||||||
scheduler_last_epoch = global_step - 1
|
|
||||||
scheduler_g = torch.optim.lr_scheduler.LambdaLR(
|
scheduler_g = torch.optim.lr_scheduler.LambdaLR(
|
||||||
optim_g, lr_lambda=lr_lambda, last_epoch=scheduler_last_epoch
|
optim_g, lr_lambda=lr_lambda, last_epoch=scheduler_last_epoch
|
||||||
)
|
)
|
||||||
@@ -367,12 +366,6 @@ def run():
|
|||||||
optim_d, lr_lambda=lr_lambda, last_epoch=scheduler_last_epoch
|
optim_d, lr_lambda=lr_lambda, last_epoch=scheduler_last_epoch
|
||||||
)
|
)
|
||||||
if net_dur_disc is not None:
|
if net_dur_disc is not None:
|
||||||
if not optim_dur_disc.param_groups[0].get("initial_lr"):
|
|
||||||
if global_step == 0:
|
|
||||||
optim_dur_disc.param_groups[0]["initial_lr"] = hps.train.learning_rate
|
|
||||||
else:
|
|
||||||
optim_dur_disc.param_groups[0]["initial_lr"] = dur_resume_lr
|
|
||||||
initial_lr = optim_dur_disc.param_groups[0].get("initial_lr")
|
|
||||||
scheduler_dur_disc = torch.optim.lr_scheduler.LambdaLR(
|
scheduler_dur_disc = torch.optim.lr_scheduler.LambdaLR(
|
||||||
optim_dur_disc, lr_lambda=lr_lambda, last_epoch=scheduler_last_epoch
|
optim_dur_disc, lr_lambda=lr_lambda, last_epoch=scheduler_last_epoch
|
||||||
)
|
)
|
||||||
@@ -409,6 +402,10 @@ def run():
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
scheduler_g.step()
|
||||||
|
scheduler_d.step()
|
||||||
|
if net_dur_disc is not None:
|
||||||
|
scheduler_dur_disc.step()
|
||||||
|
|
||||||
if epoch == hps.train.epochs:
|
if epoch == hps.train.epochs:
|
||||||
# Save the final models
|
# Save the final models
|
||||||
@@ -716,10 +713,6 @@ def train_and_evaluate(
|
|||||||
for_infer=True,
|
for_infer=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
scheduler_g.step()
|
|
||||||
scheduler_d.step()
|
|
||||||
if net_dur_disc is not None:
|
|
||||||
scheduler_dur_disc.step()
|
|
||||||
global_step += 1
|
global_step += 1
|
||||||
# 本家ではこれをスピードアップのために消すと書かれていたので、一応消してみる
|
# 本家ではこれをスピードアップのために消すと書かれていたので、一応消してみる
|
||||||
# gc.collect()
|
# gc.collect()
|
||||||
|
|||||||
Reference in New Issue
Block a user