torch.optim.Optimizer.register_step_pre_hook#
- Optimizer.register_step_pre_hook(hook)[source]#
注册一个优化器步骤预钩子,它将在优化器步骤之前被调用。
它应具有以下签名
hook(optimizer, args, kwargs) -> None or modified args and kwargs
The
optimizer
argument is the optimizer instance being used. If args and kwargs are modified by the pre-hook, then the transformed values are returned as a tuple containing the new_args and new_kwargs.- 参数
hook (Callable) – 用户定义的待注册钩子。
- 返回
一个句柄,可用于通过调用
handle.remove()
来移除添加的钩子- 返回类型
torch.utils.hooks.RemovableHandle