Skip to content

Commit 188ee3f

Browse files
nguyen-binh-minhapaszke
authored andcommitted
Fix wrong learning rate evaluation in CosineAnnealingLR in Python 2 (#4656)
1 parent 05908e8 commit 188ee3f

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
@@ -503,7 +503,7 @@ def test_cos_anneal_lr(self):
503503
epochs = 10
504504
eta_min = 1e-10
505505
single_targets = [eta_min + (0.05 - eta_min) *
506-
(1 + math.cos(x / epochs * math.pi)) / 2
506+
(1 + math.cos(math.pi * x / epochs)) / 2
507507
for x in range(epochs)]
508508
targets = [single_targets, list(map(lambda x: x * epochs, single_targets))]
509509
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)