From 42e6951e62a15b063a96f2d012d2f268b8c1d23e Mon Sep 17 00:00:00 2001 From: jsrozner Date: Fri, 4 Dec 2020 13:16:09 -0800 Subject: [PATCH] Remove save_state_warning in LambdaLR (#46813) Summary: Fixes https://github.com/pytorch/pytorch/issues/46405, https://github.com/pytorch/pytorch/issues/43352 I updated the docstring in the local file (function level comments). Do I also need to edit somewhere else or recompile docstrings? Also, though I didn't change any types here, how is typing (for IDE type checking) documentation generated / used)? Pull Request resolved: https://github.com/pytorch/pytorch/pull/46813 Reviewed By: ezyang Differential Revision: D24923112 Pulled By: vincentqb fbshipit-source-id: be7818e0d4593bfc5d74023b9c361ac2a538589a --- torch/optim/lr_scheduler.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/torch/optim/lr_scheduler.py b/torch/optim/lr_scheduler.py index 906aa519f1bd4..706d12683c274 100644 --- a/torch/optim/lr_scheduler.py +++ b/torch/optim/lr_scheduler.py @@ -19,8 +19,6 @@ "https://github.com/pytorch/pytorch/issues/new/choose." ) -SAVE_STATE_WARNING = "Please also save or load the state of the optimizer when saving or loading the scheduler." - class _LRScheduler(object): def __init__(self, optimizer, last_epoch=-1, verbose=False): @@ -211,9 +209,10 @@ def state_dict(self): is not the optimizer. The learning rate lambda functions will only be saved if they are callable objects and not if they are functions or lambdas. + + When saving or loading the scheduler, please make sure to also save or load the state of the optimizer. """ - warnings.warn(SAVE_STATE_WARNING, UserWarning) state_dict = {key: value for key, value in self.__dict__.items() if key not in ('optimizer', 'lr_lambdas')} state_dict['lr_lambdas'] = [None] * len(self.lr_lambdas) @@ -226,12 +225,13 @@ def state_dict(self): def load_state_dict(self, state_dict): """Loads the schedulers state. + When saving or loading the scheduler, please make sure to also save or load the state of the optimizer. + Arguments: state_dict (dict): scheduler state. Should be an object returned from a call to :meth:`state_dict`. """ - warnings.warn(SAVE_STATE_WARNING, UserWarning) lr_lambdas = state_dict.pop('lr_lambdas') self.__dict__.update(state_dict) # Restore state_dict keys in order to prevent side effects