Wanted to show that this is better
w = torch.randn(2,5)
w.requires_grad_()

instead of
w = torch.randn(2, 5, requires_grad=True)

not to include gradients of initialization.
w = torch.randn(2, 5, requires_grad=True)
w.backward(retain_graph=True)
print(w.grad)

But my example to show grads failed with the error:

RuntimeError: grad can be implicitly created only for scalar outputs

How can I read the gradients of w initialization in the second case?