From 95d3825e48ad8eb6caab2374d831b4e76824dc25 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Rasmussen?= Date: Fri, 29 Mar 2019 06:42:52 -0700 Subject: [PATCH] ReduceLrOnPlateau: best=current -> best=copy(current) (#16364) (#16697) Summary: Fixes #16364 Pull Request resolved: https://github.com/pytorch/pytorch/pull/16697 Differential Revision: D14680879 Pulled By: soumith fbshipit-source-id: c50c22f3eacea4474fb3a04fe85fbf11d5a177c9 --- torch/optim/lr_scheduler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torch/optim/lr_scheduler.py b/torch/optim/lr_scheduler.py index 3650794..b4dadb5 100644 --- a/torch/optim/lr_scheduler.py +++ b/torch/optim/lr_scheduler.py @@ -360,7 +360,8 @@ class ReduceLROnPlateau(object): self.num_bad_epochs = 0 def step(self, metrics, epoch=None): - current = metrics + # convert `metrics` to float, in case it's a zero-dim Tensor + current = float(metrics) if epoch is None: epoch = self.last_epoch = self.last_epoch + 1 self.last_epoch = epoch -- 2.7.4