Hi,
You can do the following:
x = torch.rand()
output = net(x)
L = crit(output, label)

dLdx = autograd.grad(L, x, create_graph=True)[0]

dLdx.backward()
# Now you have the grads as usual in the .grad fields