Fix wrong learning rate evaluation in CosineAnnealingLR in Python 2 (#4656)
diff --git a/test/test_optim.py b/test/test_optim.py
index 66a78fd..f05b219a 100644
--- a/test/test_optim.py
+++ b/test/test_optim.py
@@ -503,7 +503,7 @@
epochs = 10
eta_min = 1e-10
single_targets = [eta_min + (0.05 - eta_min) *
- (1 + math.cos(x / epochs * math.pi)) / 2
+ (1 + math.cos(math.pi * x / epochs)) / 2
for x in range(epochs)]
targets = [single_targets, list(map(lambda x: x * epochs, single_targets))]
scheduler = CosineAnnealingLR(self.opt, T_max=epochs, eta_min=eta_min)
diff --git a/torch/optim/lr_scheduler.py b/torch/optim/lr_scheduler.py
index 33b7ebf..0b125c4 100644
--- a/torch/optim/lr_scheduler.py
+++ b/torch/optim/lr_scheduler.py
@@ -194,7 +194,7 @@
def get_lr(self):
return [self.eta_min + (base_lr - self.eta_min) *
- (1 + math.cos(self.last_epoch / self.T_max * math.pi)) / 2
+ (1 + math.cos(math.pi * self.last_epoch / self.T_max)) / 2
for base_lr in self.base_lrs]