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 that is not a leaf, you need to call w.retain_grad() on it before the backward pass.