# tensorplay.nn.modules.module.register_module_forward_hook

Source: https://www.tensorplay.cn/docs/generated/tensorplay.nn.modules.module.register_module_forward_hook.html

# tensorplay.nn.modules.module.register_module_forward_hook

tensorplay.nn.modules.module.register_module_forward_hook(hook: [Callable](https://docs.python.org/3/library/typing.html#typing.Callable)[[...], [None](https://docs.python.org/3/library/constants.html#None)], *, with_kwargs: [bool](https://docs.python.org/3/library/functions.html#bool) = False, always_call: [bool](https://docs.python.org/3/library/functions.html#bool) = False) &#x2192; RemovableHandle[[source]](../_modules/tensorplay/nn/modules/module.html#register_module_forward_hook)

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 output
```

The 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 the forward() function.

Parameters:

- hook ( Callable ) – The user defined hook to be registered.

- always_call ([bool](https://docs.python.org/3/library/functions.html#bool)) – If True the hook will 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.
