- MNistNet.register_full_backward_hook(hook: Callable[[Module, Union[Tuple[Tensor, ...], Tensor], Union[Tuple[Tensor, ...], Tensor]], Union[None, Tensor]]) RemovableHandle #
Registers a backward hook on the module.
The hook will be called every time the gradients with respect to module inputs are computed. The hook should have the following signature:
hook(module, grad_input, grad_output) -> tuple(Tensor) or None
grad_outputare tuples that contain the gradients with respect to the inputs and outputs respectively. The hook should not modify its arguments, but it can optionally return a new gradient with respect to the input that will be used in place of
grad_inputin subsequent computations.
grad_inputwill only correspond to the inputs given as positional arguments and all kwarg arguments are ignored. Entries in
Nonefor all non-Tensor arguments.
For technical reasons, when this hook is applied to a Module, its forward function will receive a view of each Tensor passed to the Module. Similarly the caller will receive a view of each Tensor returned by the Module’s forward function.
Modifying inputs or outputs inplace is not allowed when using backward hooks and will raise an error.
a handle that can be used to remove the added hook by calling