There are many examples in this thread:

  
    
    
    Why cant I see .grad of an intermediate variable? 
  
  
    Hi! I am loving this framework… 
Since Im a noob, I am probably not getting something, but I am wondering why I cant get the gradient of an intermediate variable with .grad? Here is an example of what I mean: 
xx = Variable(torch.randn(1,1), requires_grad = True)
yy = 3*xx
zz = yy**2
zz.backward()
xx.grad # This is ok
yy.grad # This gives 0! 
zz.grad # This should give 1! 

So I get the correct result for xx.grad, but why does yy.grad show 0, as does zz.grad? How can I get the yy.grad value in t…
  


Also a search will give you a few more examples:
https://discuss.pytorch.org/search?q=register_hook