Torch.empty() returns nan

This is expected since you are using uninitialized memory for the tensor which may contain any value including NaN.
Initialize tensors via e.g. torch.randn to draw samples from a Normal distribution.