Gradients are only defined for floating point types and you would get an error if you try to enable it on another dtype:
x = torch.randn(1, requires_grad=True)
x.long().requires_grad_()
> RuntimeError: only Tensors of floating point dtype can require gradients