As mentionned in the doc 76 .backward() computes the gradient for all the leafs used to compute the output. Doc for leaf Tensor is here 27.
If you use autograd.grad doc here 14 you can specify explicitly which inputs you want the gradient for.
Depending on what you want to do, you should use the one that fits best.
Backpropagation algorithm is very well explained on the wikipedia article: https://en.wikipedia.org/wiki/Backpropagation 37
The short answer in this case of scalar output is that it computes the gradient dy/dx (either stored in y.grad if you use .backward() or returned to your if you use autograd.grad).