'understanding how hooking function in pytorch?

I have a function used for hook gradients in a network.

    def activations_hook(self, grad):
        self.gradients = grad

and then 'h = x.register_hook(self.activations_hook)'. I can't understand how it works without passing any arguments when calling the function.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source