Register_hook and find the maximum gradient of non leaf variable

You’ll find the gradient by looking at y.grad. Usually this isn’t saved though, so take a look here:

If you want to specifically use a hook, then you can register a closure as a hook and that will save the gradient, As was done here:

1 Like