评价此页

torch.nn.modules.module.register_module_module_registration_hook#

torch.nn.modules.module.register_module_module_registration_hook(hook)[源代码]#

为所有模块注册一个通用的模块注册钩子(hook)。

警告

This adds global state to the nn.Module module

每次调用 register_module() 时都会调用此钩子。它应该具有以下签名:

hook(module, name, submodule) -> None or new submodule

The hook can modify the input or return a single modified value in the hook.

返回

一个句柄,可用于通过调用 handle.remove() 来移除添加的钩子

返回类型

torch.utils.hooks.RemovableHandle