Skip scheduler step is opt is not performed (#1854)

Skip scheduler step is opt is not perfomed

Co-authored-by: Jonas Kulhanek <jonas.kulhanek@live.com>
This commit is contained in:
Matthew TancikandJonas Kulhanek authored and GitHub committed 2023-05-09 07:30:53 -07:00
1 parent f299098f46
commit 069fa0f498
1 file changed
+4 -1
+4 -1
View File
@@ -461,8 +461,11 @@ class Trainer:
metrics_dict["Gradients/Total"] = total_grad
scale = self.grad_scaler.get_scale()
self.grad_scaler.update()
self.optimizers.scheduler_step_all(step)
# If the gradient scaler is decreased, no optimization step is performed so we should not step the scheduler.
if scale <= self.grad_scaler.get_scale():
self.optimizers.scheduler_step_all(step)
# Merging loss and metrics dict into a single output.
return loss, loss_dict, metrics_dict