As the warning explains you are trying to access the .grad attribute of a non-leaf tensor, which won’t be populated by default.
You can call .retain_grad() on the non-leaf Tensor to access the gradient after the backward call.
Also note that the usage of the .data attribute is not recommended, as Autograd won’t be able to track these operations which might yield to silent errors.