Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouzaida committed Mar 28, 2023
1 parent b89a2ca commit 85e1f59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/en/tutorials/hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ The four features mentioned above are described below.

- Make checkpoints for publish

If you want to automatically generate publishable checkpoints after training (remove unnecessary keys, such as optimizer state), you can set the `published_keys` parameter to choose which information to keep. Note: You need to set the `save_best` or `save_last` parameters accordingly, so that the releasable checkpoints will be generated. Setting `save_best` will generate the releasable weights of the optimal checkpoint, and setting `save_last` will generate the releasable final checkpoint. These two parameters can also be used set at the same time.
If you want to automatically generate publishable checkpoints after training (remove unnecessary keys, such as optimizer state), you can set the `published_keys` parameter to choose which information to keep. Note: You need to set the `save_best` or `save_last` parameters accordingly so that the releasable checkpoints will be generated. Setting `save_best` will generate the releasable weights of the optimal checkpoint, and setting `save_last` will generate the releasable final checkpoint. These two parameters can also be set at the same time.

```python
default_hooks = dict(checkpoint=dict(type='CheckpointHook', interval=1, save_best='accuracy', rule='less', published_keys=['meta', 'state_dict']))
Expand Down
5 changes: 3 additions & 2 deletions mmengine/hooks/checkpoint_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class CheckpointHook(Hook):
or ``save_best`` is not ``None``, it will automatically
publish model with keys in the list after training.
Defaults to None.
`New in version 0.7.1.`
Examples:
>>> # Save best based on single metric
>>> CheckpointHook(interval=2, by_epoch=True, save_best='acc',
Expand Down Expand Up @@ -370,10 +371,10 @@ def _publish_model(self, runner, ckpt_path: str) -> None:
logger='current')
checkpoint_data = pickle.dumps(checkpoint)
sha = hashlib.sha256(checkpoint_data).hexdigest()
final_path = osp.splitext(ckpt_path)[0] + f'-published-{sha[:8]}.pth'
final_path = osp.splitext(ckpt_path)[0] + f'-{sha[:8]}.pth'
save_checkpoint(checkpoint, final_path)
print_log(
f'The published model ({ckpt_path}) is saved at '
f'The checkpoint ({ckpt_path}) is published to '
f'{final_path}.',
logger='current')

Expand Down

0 comments on commit 85e1f59

Please sign in to comment.