The gradient in the loss won’t be retained by default.
By calling loss.backward() you are passing a gradient of 1 by default, since dL/dL = 1.
To print the gradient in L, you can use the following code:
L.retain_grad()
L.backward(retain_graph=True)
print('grad', L.grad)