From f545a5410bcf2095b9a29b8b3d90ef1f86330cab Mon Sep 17 00:00:00 2001 From: cnn Date: Tue, 8 Dec 2020 21:00:45 +0800 Subject: [PATCH] [Dygraph] solve load optimizer if some key not in optimizer (#1812) * solve load optimizer if some key not in optimizer * variable name tmp_key to key * add comment --- ppdet/utils/checkpoint.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ppdet/utils/checkpoint.py b/ppdet/utils/checkpoint.py index cf107e0fd..ffe475dfa 100644 --- a/ppdet/utils/checkpoint.py +++ b/ppdet/utils/checkpoint.py @@ -92,6 +92,10 @@ def load_weight(model, weight, optimizer=None): if optimizer is not None and os.path.exists(path + '.pdopt'): optim_state_dict = paddle.load(path + '.pdopt') + # to slove resume bug, will it be fixed in paddle 2.0 + for key in optimizer.state_dict().keys(): + if not key in optim_state_dict.keys(): + optim_state_dict[key] = optimizer.state_dict()[key] optimizer.set_state_dict(optim_state_dict) return -- GitLab