If you’re using PyTorch’s nightly builds (or wait until PyTorch 1.8) then we’ve added nan_to_num. See its documentation here:

  
      pytorch.org
  
  
    

torch.nan_to_num — PyTorch master documentation 134