backward() accepts a gradient as its argument.
If you don’t pass anything to this method, a scalar 1 is automatically used.
If you already have the gradient w.r.t the tensor, you could thus use loss.backward(gradient).