Skip to content

Commit

Permalink
[Enhancement] Deprecate _save_to_state_dict implemented in mmengine (#…
Browse files Browse the repository at this point in the history
…610)

* [Refine] Make get_state_dict directly call nn.Module._save_to_state_dict

* deprecate _save_to_state_dict

* deprecate _save_to_state_dict in 0.5.0

* deprecate in 0.3.0

Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>

Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>
  • Loading branch information
HAOCHENYE and zhouzaida committed Oct 28, 2022
1 parent d1dd240 commit 4aad15d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions mmengine/runner/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from mmengine.fileio import load as load_file
from mmengine.logging import print_log
from mmengine.model import BaseTTAModel, is_model_wrapper
from mmengine.utils import mkdir_or_exist
from mmengine.utils import deprecated_function, mkdir_or_exist
from mmengine.utils.dl_utils import load_url

# `MMENGINE_HOME` is the highest priority directory to save checkpoints
Expand Down Expand Up @@ -574,6 +574,11 @@ def weights_to_cpu(state_dict):
return state_dict_cpu


@deprecated_function(
since='0.3.0',
removed_in='0.5.0',
instructions='`_save_to_state_dict` will be deprecated in the future, '
'please use `nn.Module._save_to_state_dict` directly.')
def _save_to_state_dict(module, destination, prefix, keep_vars):
"""Saves module state to `destination` dictionary.
Expand Down Expand Up @@ -626,7 +631,7 @@ def get_state_dict(module, destination=None, prefix='', keep_vars=False):
destination._metadata = OrderedDict()
destination._metadata[prefix[:-1]] = local_metadata = dict(
version=module._version)
_save_to_state_dict(module, destination, prefix, keep_vars)
module._save_to_state_dict(destination, prefix, keep_vars)
for name, child in module._modules.items():
if child is not None:
get_state_dict(
Expand Down
5 changes: 3 additions & 2 deletions mmengine/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright (c) OpenMMLab. All rights reserved.
from .manager import ManagerMeta, ManagerMixin
from .misc import (check_prerequisites, concat_list, deprecated_api_warning,
has_method, import_modules_from_strings, is_list_of,
deprecated_function, has_method,
import_modules_from_strings, is_list_of,
is_method_overridden, is_seq_of, is_str, is_tuple_of,
iter_cast, list_cast, requires_executable, requires_package,
slice_list, to_1tuple, to_2tuple, to_3tuple, to_4tuple,
Expand All @@ -26,5 +27,5 @@
'is_abs', 'is_method_overridden', 'has_method', 'digit_version',
'get_git_hash', 'ManagerMeta', 'ManagerMixin', 'Timer', 'check_time',
'TimerError', 'ProgressBar', 'track_iter_progress',
'track_parallel_progress', 'track_progress'
'track_parallel_progress', 'track_progress', 'deprecated_function'
]

0 comments on commit 4aad15d

Please sign in to comment.