x = torch.tensor([0.0, 1.0], requires_grad=True)
y = torch.log(x)
grads, = torch.autograd.grad(y[1], x)
print(grads[0])

outputs nan, whereas
x = torch.tensor([-1.0, 1.0], requires_grad=True)
y = torch.log(x)
grads, = torch.autograd.grad(y[1], x)
print(grads[0])

outputs 0.0
Is this the expected output? If so, are there any quick hacks to make the gradients 0.0?
torch               1.9.1+cu111
Thank you!