The following is included in my model’s __init__ function
self.grads = None
target_layer = self.model.features
target_layer.register_backward_hook(self.grad_hook)

And grad_hook(...) is defined as
def grad_hook(self, module, grad_input, grad_output):
        self.grads = grad_output[0].clone().detach()

This code works perfectly and I’m able to retrieve the gradients saved in self.grads after calling .backward(), but it prints the following warning:
UserWarning: 
Using a non-full backward hook when the forward contains multiple autograd Nodes is deprecated and will be removed in future versions. 
This hook will be missing some grad_input. 
Please use register_full_backward_hook to get the documented behavior.
warnings.warn("Using a non-full backward hook when the forward contains multiple autograd Nodes "

However, when I replace register_backward_hook by  register_full_backward_hook in __init__, the gradients are not saved, i.e., self.grads is None
Why is this happening?