From: Søren Rasmussen Date: Fri, 29 Mar 2019 13:42:52 +0000 (-0700) Subject: ReduceLrOnPlateau: best=current -> best=copy(current) (#16364) (#16697) X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~559 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=95d3825e48ad8eb6caab2374d831b4e76824dc25;p=platform%2Fupstream%2Fpytorch.git 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 --- 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