Solved by albanD in post #2 
              
              
                Hi, 
When you call .backward(), then .grad field of only the leaf variables is populated (to reduce memory usage). 
A leaf variable is one that the user created with requires_grad=True. In your case, y.is_leaf == True but w.is_leaf == False. 
If you want the .grad field to be populated for a Tensor …