Hi,
You can use autograd.grad(loss, input) and it will return gradients for that input and only perform the necessary computations to get that value.
If you prefer for the .grad fields to be populated, you can use loss.backward(inputs=input).