Pytorch operation to detect NaN

Is there an internal Pytorch procedure for detecting NaN in tensors? Tensorflow has tf.is_nan and tf.check_numerics ... Does Pytorch have something like this? I could not find something like this in the docs ...

I look specifically at the internal Pytorch procedure, as I would like this to happen both on the GPU and on the processor. This excludes numpy-based solutions (e.g. np.isnan(sometensor.numpy()).any() ) ...

+5
source share
1 answer

You can always use the fact that nan != nan :

 >>> x = torch.Tensor([1, 2, np.nan]) 1 2 nan [torch.FloatTensor of size 3] >>> x != x 0 0 1 [torch.ByteTensor of size 3] 
+7
source

Source: https://habr.com/ru/post/1274580/


All Articles