By default the loss gradient won’t be retained, as it’s usually a 1 (or you would pass the loss gradient manually to loss.backward(gradient).
If you want to print it, you would need to call:
loss.retain_grad()
loss.backward()
print(loss.grad)
> tensor(1.)