Skip to content

Commit 4aad15d

Browse files
HAOCHENYEzhouzaida
andauthored
[Enhancement] Deprecate _save_to_state_dict implemented in mmengine (#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>
1 parent d1dd240 commit 4aad15d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

mmengine/runner/checkpoint.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from mmengine.fileio import load as load_file
2020
from mmengine.logging import print_log
2121
from mmengine.model import BaseTTAModel, is_model_wrapper
22-
from mmengine.utils import mkdir_or_exist
22+
from mmengine.utils import deprecated_function, mkdir_or_exist
2323
from mmengine.utils.dl_utils import load_url
2424

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

576576

577+
@deprecated_function(
578+
since='0.3.0',
579+
removed_in='0.5.0',
580+
instructions='`_save_to_state_dict` will be deprecated in the future, '
581+
'please use `nn.Module._save_to_state_dict` directly.')
577582
def _save_to_state_dict(module, destination, prefix, keep_vars):
578583
"""Saves module state to `destination` dictionary.
579584
@@ -626,7 +631,7 @@ def get_state_dict(module, destination=None, prefix='', keep_vars=False):
626631
destination._metadata = OrderedDict()
627632
destination._metadata[prefix[:-1]] = local_metadata = dict(
628633
version=module._version)
629-
_save_to_state_dict(module, destination, prefix, keep_vars)
634+
module._save_to_state_dict(destination, prefix, keep_vars)
630635
for name, child in module._modules.items():
631636
if child is not None:
632637
get_state_dict(

mmengine/utils/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
22
from .manager import ManagerMeta, ManagerMixin
33
from .misc import (check_prerequisites, concat_list, deprecated_api_warning,
4-
has_method, import_modules_from_strings, is_list_of,
4+
deprecated_function, has_method,
5+
import_modules_from_strings, is_list_of,
56
is_method_overridden, is_seq_of, is_str, is_tuple_of,
67
iter_cast, list_cast, requires_executable, requires_package,
78
slice_list, to_1tuple, to_2tuple, to_3tuple, to_4tuple,
@@ -26,5 +27,5 @@
2627
'is_abs', 'is_method_overridden', 'has_method', 'digit_version',
2728
'get_git_hash', 'ManagerMeta', 'ManagerMixin', 'Timer', 'check_time',
2829
'TimerError', 'ProgressBar', 'track_iter_progress',
29-
'track_parallel_progress', 'track_progress'
30+
'track_parallel_progress', 'track_progress', 'deprecated_function'
3031
]

0 commit comments

Comments
 (0)