torch.sqrt() would give you NaN gradients for negative inputs, which shouldn’t be possible given your code snippet and an Inf gradient for a zero input, which might be the case for your use case:
x = torch.tensor([0.], requires_grad=True)
y = torch.sqrt(x)
y.backward()
print(x.grad)
> tensor([inf])

You could add a small eps value to the sqrt op to avoid this. However, note that this might blow up your gradients due to the behavior of the derivative of the sqrt.