Skip to content

Commit d9001ce

Browse files
nguyen-binh-minhsoumith
authored andcommitted
Fix wrong learning rate evaluation in CosineAnnealingLR in Python 2 (#4656)
1 parent b68861d commit d9001ce

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

test/test_optim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def test_cos_anneal_lr(self):
465465
epochs = 10
466466
eta_min = 1e-10
467467
single_targets = [eta_min + (0.05 - eta_min) *
468-
(1 + math.cos(x / epochs * math.pi)) / 2
468+
(1 + math.cos(math.pi * x / epochs)) / 2
469469
for x in range(epochs)]
470470
targets = [single_targets, list(map(lambda x: x * epochs, single_targets))]
471471
scheduler = CosineAnnealingLR(self.opt, T_max=epochs, eta_min=eta_min)

torch/optim/lr_scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def __init__(self, optimizer, T_max, eta_min=0, last_epoch=-1):
194194

195195
def get_lr(self):
196196
return [self.eta_min + (base_lr - self.eta_min) *
197-
(1 + math.cos(self.last_epoch / self.T_max * math.pi)) / 2
197+
(1 + math.cos(math.pi * self.last_epoch / self.T_max)) / 2
198198
for base_lr in self.base_lrs]
199199

200200

0 commit comments

Comments
 (0)