ReduceLrOnPlateau: best=current -> best=copy(current) (#16364) (#16697)
authorSøren Rasmussen <soren.rasmussen@alexandra.dk>
Fri, 29 Mar 2019 13:42:52 +0000 (06:42 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 29 Mar 2019 13:56:51 +0000 (06:56 -0700)
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

index 3650794..b4dadb5 100644 (file)
@@ -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