torch.optim.Optimizer.register_state_dict_pre_hook¶
- Optimizer.register_state_dict_pre_hook(hook, prepend=False)[source][source]¶
注册一个在调用
state_dict()之前被调用的状态字典预钩子。它应该具有以下签名:
hook(optimizer) -> None
The
optimizerargument is the optimizer instance being used. The hook will be called with argumentselfbefore callingstate_dictonself. The registered hook can be used to perform pre-processing before thestate_dictcall is made.- 参数:
hook(可调用对象)- 用户定义的将被注册的钩子。
prepend (bool) – 如果为 True,提供的预
hook将在所有已注册的预钩子state_dict之前触发。否则,提供的hook将在所有已注册的预钩子之后触发。(默认:False)
- 返回值:
一个可以用来通过调用
handle.remove()移除已添加钩子的句柄。- 返回类型:
torch.utils.hooks.RemoveableHandle