这是用户在 2024-10-26 11:25 为 https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.register_load_state_dict_pre_hook.ht... 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
  • Docs >  """ 文档 >"""
  • torch.optim >
  • torch.optim.Optimizer.register_load_state_dict_pre_hook
    torch.optim.Optimizer.register_load_state_dict_pre_hook torch.optim.Optimizer 注册加载状态字典前钩子
Shortcuts  快捷键

torch.optim.Optimizer.register_load_state_dict_pre_hook
torch.optim.Optimizer.register_load_state_dict_pre_hook torch.optim.Optimizer 注册加载状态字典前钩子

Optimizer.register_load_state_dict_pre_hook(hook, prepend=False)[source]
```python Optimizer.register_load_state_dict_pre_hook(hook, prepend=False)[source] ``` ```python Optimizer 注册加载状态字典预处理钩子(hook, prepend=False)[源代码] ```

Register a load_state_dict pre-hook which will be called before load_state_dict() is called. It should have the following signature:
注册一个在调用 load_state_dict() 之前将被调用的 load_state_dict 预钩子。它应该具有以下签名:

hook(optimizer, state_dict) -> state_dict or None

The optimizer argument is the optimizer instance being used and the state_dict argument is a shallow copy of the state_dict the user passed in to load_state_dict. The hook may modify the state_dict inplace or optionally return a new one. If a state_dict is returned, it will be used to be loaded into the optimizer.
```plaintext optimizer 参数是正在使用的优化器实例, state_dict 参数是用户传递给 load_state_dictstate_dict 的浅拷贝。钩子可以就地修改状态字典,或者可选地返回一个新的状态字典。如果返回了状态字典,它将被用于加载到优化器中。 ```

The hook will be called with argument self and state_dict before calling load_state_dict on self. The registered hook can be used to perform pre-processing before the load_state_dict call is made.
钩子将在调用 self 上的 load_state_dict 之前,使用参数 selfstate_dict 进行调用。已注册的钩子可以在执行 load_state_dict 调用之前进行预处理。

Parameters 参数
  • hook (Callable) – The user defined hook to be registered.
    钩子(Callable)- 用户定义的待注册钩子。

  • prepend (bool) – If True, the provided pre hook will be fired before all the already registered pre-hooks on load_state_dict. Otherwise, the provided hook will be fired after all the already registered pre-hooks. (default: False)
    ``` prepend(布尔值)- 如果为 True,提供的预操作 hook 将在所有已注册的预钩子 load_state_dict 之前执行。否则,提供的 hook 将在所有已注册的预钩子之后执行。(默认:False) ```

Returns 返回

a handle that can be used to remove the added hook by calling handle.remove()
一个可以通过调用 handle.remove() 来移除已添加钩子的句柄

Return type 返回类型

torch.utils.hooks.RemoveableHandle

Docs 文档

Access comprehensive developer documentation for PyTorch
PyTorch 开发者文档全面访问

View Docs 查看文档

Tutorials 教程

Get in-depth tutorials for beginners and advanced developers
深入教程,适合初学者和高级开发者

View Tutorials 查看教程

Resources 资源

Find development resources and get your questions answered
找到开发资源,获取您的疑问解答

View Resources 查看资源