fn
register_module_full_backward_hook
→RemovableHandleregister_module_full_backward_hook(hook: Callable[..., object])Register a global post-hook fired after a module's backward pass.
Invoked once Lucid's autograd engine has finished accumulating gradients for a Module. The hook receives the module along with the input-gradients (gradients flowing back into the module's inputs) and the output-gradients (gradients that came from above). Mutating these in place propagates to subsequent backward computation; returning a new tuple of input-gradients replaces them.
Parameters
hookCallableSignature:
hook(module, grad_input, grad_output) -> None | tuple.Returns
RemovableHandleHandle for later deregistration.
Notes
Use the "full" variant whenever a Module has multiple inputs and you
need access to every per-input gradient. Pairs naturally with
register_module_full_backward_pre_hook for modify-then-observe
workflows.
Examples
>>> from lucid.nn.hooks import register_module_full_backward_hook
>>> def log_grad_norm(mod, grad_input, grad_output):
... for i, g in enumerate(grad_input):
... if g is not None:
... print(f'{type(mod).__name__}.in[{i}].grad_norm = {g.norm().item()}')
>>> handle = register_module_full_backward_hook(log_grad_norm)