Functions 7
register_module_buffer_registration_hook
functionFull reference ↗- tensorplay.nn.modules.module.register_module_buffer_registration_hook(hook: Callable[[...], None]) RemovableHandle[source]
Register a buffer registration hook common to all modules.
Warning
This adds global state to the nn.Module module
The hook will be called every time
register_buffer()is invoked. It should have the following signature:hook(module, name, buffer) -> None or new bufferThe hook can modify the input or return a single modified value in the hook.
- Returns:
a handle that can be used to remove the added hook by calling
handle.remove()- Return type:
tensorplay.utils.hooks.RemovableHandle
register_module_forward_hook
functionFull reference ↗- tensorplay.nn.modules.module.register_module_forward_hook(hook: Callable[[...], None], *, with_kwargs: bool = False, always_call: bool = False) RemovableHandle[source]
Register a global forward hook for all the modules.
Warning
This adds global state to the nn.module module and it is only intended for debugging/profiling purposes.
The hook will be called every time after
forward()has computed an output. It should have the following signature:hook(module, input, output) -> None or modified outputThe input contains only the positional arguments given to the module. Keyword arguments won’t be passed to the hooks and only to the
forward. You can optionally modify the output of the module by returning a new value that will replace the output from theforward()function.- Parameters:
hook (Callable) – The user defined hook to be registered.
always_call (bool) – If
Truethehookwill be run regardless of whether an exception is raised while calling the Module. Default:False
- Returns:
a handle that can be used to remove the added hook by calling
handle.remove()- Return type:
tensorplay.utils.hooks.RemovableHandle
This hook will be executed before specific module hooks registered with
register_forward_hook.
register_module_forward_pre_hook
functionFull reference ↗- tensorplay.nn.modules.module.register_module_forward_pre_hook(hook: Callable[[...], None]) RemovableHandle[source]
Register a forward pre-hook common to all modules.
Warning
This adds global state to the nn.module module and it is only intended for debugging/profiling purposes.
The hook will be called every time before
forward()is invoked. It should have the following signature:hook(module, input) -> None or modified inputThe input contains only the positional arguments given to the module. Keyword arguments won’t be passed to the hooks and only to the
forward. The hook can modify the input. User can either return a tuple or a single modified value in the hook. We will wrap the value into a tuple if a single value is returned(unless that value is already a tuple).This hook has precedence over the specific module hooks registered with
register_forward_pre_hook.- Returns:
a handle that can be used to remove the added hook by calling
handle.remove()- Return type:
tensorplay.utils.hooks.RemovableHandle
register_module_full_backward_hook
functionFull reference ↗- tensorplay.nn.modules.module.register_module_full_backward_hook(hook: Callable[[Module, tuple[TensorBase, ...] | TensorBase, tuple[TensorBase, ...] | TensorBase], None | tuple[TensorBase, ...] | TensorBase]) RemovableHandle[source]
Register a backward hook common to all the modules.
Warning
This adds global state to the nn.module module and it is only intended for debugging/profiling purposes.
Hooks registered using this function behave in the same way as those registered by
tensorplay.nn.Module.register_full_backward_hook(). Refer to its documentation for more details.Hooks registered using this function will be called before hooks registered using
tensorplay.nn.Module.register_full_backward_hook().- Returns:
a handle that can be used to remove the added hook by calling
handle.remove()- Return type:
tensorplay.utils.hooks.RemovableHandle
register_module_full_backward_pre_hook
functionFull reference ↗- tensorplay.nn.modules.module.register_module_full_backward_pre_hook(hook: Callable[[Module, tuple[TensorBase, ...] | TensorBase], None | tuple[TensorBase, ...] | TensorBase]) RemovableHandle[source]
Register a backward pre-hook common to all the modules.
Warning
This adds global state to the nn.module module and it is only intended for debugging/profiling purposes.
Hooks registered using this function behave in the same way as those registered by
tensorplay.nn.Module.register_full_backward_pre_hook(). Refer to its documentation for more details.Hooks registered using this function will be called before hooks registered using
tensorplay.nn.Module.register_full_backward_pre_hook().- Returns:
a handle that can be used to remove the added hook by calling
handle.remove()- Return type:
tensorplay.utils.hooks.RemovableHandle
register_module_module_registration_hook
functionFull reference ↗- tensorplay.nn.modules.module.register_module_module_registration_hook(hook: Callable[[...], None]) RemovableHandle[source]
Register a module registration hook common to all modules.
Warning
This adds global state to the nn.Module module
The hook will be called every time
register_module()is invoked. It should have the following signature:hook(module, name, submodule) -> None or new submoduleThe hook can modify the input or return a single modified value in the hook.
- Returns:
a handle that can be used to remove the added hook by calling
handle.remove()- Return type:
tensorplay.utils.hooks.RemovableHandle
register_module_parameter_registration_hook
functionFull reference ↗- tensorplay.nn.modules.module.register_module_parameter_registration_hook(hook: Callable[[...], None]) RemovableHandle[source]
Register a parameter registration hook common to all modules.
Warning
This adds global state to the nn.Module module
The hook will be called every time
register_parameter()is invoked. It should have the following signature:hook(module, name, param) -> None or new parameterThe hook can modify the input or return a single modified value in the hook.
- Returns:
a handle that can be used to remove the added hook by calling
handle.remove()- Return type:
tensorplay.utils.hooks.RemovableHandle

