torch.optim.Optimizer.register_state_dict_post_hook¶
- Optimizer.register_state_dict_post_hook(hook, prepend=False)[source][source]¶
- Register a state dict post-hook which will be called after - state_dict()is called.- It should have the following signature: - hook(optimizer, state_dict) -> state_dict or None - The hook will be called with arguments - selfand- state_dictafter generating a- state_dicton- self. The hook may modify the state_dict inplace or optionally return a new one. The registered hook can be used to perform post-processing on the- state_dictbefore it is returned.- Parameters
- hook (Callable) – The user defined hook to be registered. 
- prepend (bool) – If True, the provided post - hookwill be fired before all the already registered post-hooks on- state_dict. Otherwise, the provided- hookwill be fired after all the already registered post-hooks. (default: False)
 
- Returns
- a handle that can be used to remove the added hook by calling - handle.remove()
- Return type
- torch.utils.hooks.RemoveableHandle