Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Correctly saves _metadata of state_dict when saving checkpoints #1131

Merged
merged 1 commit into from
May 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mmengine/runner/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,11 @@ def weights_to_cpu(state_dict):
Returns:
OrderedDict: Model weights on GPU.
"""
# stash metadata to put in state_dict later
metadata = getattr(state_dict, '_metadata', OrderedDict())
state_dict = apply_to(state_dict, lambda x: hasattr(x, 'cpu'),
lambda x: x.cpu())
# Keep metadata in state_dict
state_dict._metadata = getattr(state_dict, '_metadata', OrderedDict())
state_dict._metadata = metadata
return state_dict


Expand Down