Hi,
Using .data is the same as “doing it in a non-differentiable way”.
Note that you should never use .data anymore and use with torch.no_grad() to do this as it is much safer (look for side effects of .data on this forum if you want to know more).
.grad() or .backward() will give the same thing here.
It will compute the gradient as if you did not changed the parameters (and because you use .data, will ingore the inplace change in the inplace checks and potentially compute these gradients wrong).