Thank you so much for your quick reply, even in Sunday!
Can you give an example? how to use the backward hook?
My original problem is

  
    
    
    .backward() not working in a method of a class 
  
  
    Hello everyone. I really need to embed a .backward() Function in a .forward() of another Function, but failed, help! 
x = np.array([[1.,2.], [3.,4.], [5.,6.]])
x = Variable(torch.from_numpy(x).float(), requires_grad=True)
y = var(x)
y.backward(y)     
# it works fine up to here
print(x.grad)       

# but -----------------
class Y_fun(Function):
    def forward(self, x):
        y = var(x)
        y.backward(y)
        print(x.grad)      # exact same thing, but in a forward method, failed
      …
  


I appreciate if you could help!