Issue 1:
Environment info

OS: Linux 4.13.0-31-generic #34~16.04.1-Ubuntu

PyTorch version: 0.3

How you installed PyTorch (conda, pip, source): pip

Python version: 3.5

CUDA/cuDNN version: 8/7

GPU models and configuration: 1080Ti

Issue

Snippet:

print("============================================================")
if DEBUG_LOG1 : print("type(decoder_output) = {}".format(type(decoder_output)))
if DEBUG_LOG1 : print("decoder_output.size() = {}".format(decoder_output.size()))
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
if DEBUG_LOG1 : print("decoder_output.data.topk(1) = ".format(decoder_output.data.topk(1)))
if DEBUG_LOG1 : print("decoder_output.data.topk(1) = ".format(decoder_output.data.topk(1)))
if DEBUG_LOG1 : print("decoder_output.data.topk(1) = ".format(decoder_output.data.topk(1)))
if DEBUG_LOG1 : print("decoder_output.data.topk(1) = ".format(decoder_output.data.topk(1)))
print("////////////////////////////////////////////////////////////")
topv, topi = decoder_output.data.topk(1)
if DEBUG_LOG1 : print("topi,topv = {}{}".format(topi,topv))
topv, topi = decoder_output.data.topk(1)
if DEBUG_LOG1 : print("topi,topv = {}{}".format(topi,topv))
topv, topi = decoder_output.data.topk(1)
if DEBUG_LOG1 : print("topi,topv = {}{}".format(topi,topv))
topv, topi = decoder_output.data.topk(1)
if DEBUG_LOG1 : print("topi,topv = {}{}".format(topi,topv))
print("------------------------------------------------------------")

Out:

============================================================
type(decoder_output) = <class 'torch.autograd.variable.Variable'>
decoder_output.size() = torch.Size([1, 29419])
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
decoder_output.data.topk(1) = (
nan
[torch.cuda.FloatTensor of size 1x1 (GPU 0)]
,
0
[torch.cuda.LongTensor of size 1x1 (GPU 0)]
)
decoder_output.data.topk(1) = (
nan
[torch.cuda.FloatTensor of size 1x1 (GPU 0)]
,
0
[torch.cuda.LongTensor of size 1x1 (GPU 0)]
)
decoder_output.data.topk(1) = (
nan
[torch.cuda.FloatTensor of size 1x1 (GPU 0)]
,
0
[torch.cuda.LongTensor of size 1x1 (GPU 0)]
)
decoder_output.data.topk(1) = (
nan
[torch.cuda.FloatTensor of size 1x1 (GPU 0)]
,
0
[torch.cuda.LongTensor of size 1x1 (GPU 0)]
)

////////////////////////////////////////////////////////////
topi,topv =
0
[torch.cuda.LongTensor of size 1x1 (GPU 0)]

nan
[torch.cuda.FloatTensor of size 1x1 (GPU 0)]

topi,topv =
9.2234e+18
[torch.cuda.LongTensor of size 1x1 (GPU 0)]

nan
[torch.cuda.FloatTensor of size 1x1 (GPU 0)]

topi,topv =
9.2234e+18
[torch.cuda.LongTensor of size 1x1 (GPU 0)]

nan
[torch.cuda.FloatTensor of size 1x1 (GPU 0)]

topi,topv =
2.1475e+09
[torch.cuda.LongTensor of size 1x1 (GPU 0)]

nan
[torch.cuda.FloatTensor of size 1x1 (GPU 0)]

------------------------------------------------------------

Issue 2:
Should I report this to torch repository?

>>> torch.topk(torch.FloatTensor([-1,float("nan"),2, 1]), 1)
(
2
[torch.FloatTensor of size 1],
2
[torch.LongTensor of size 1])

>>> torch.topk(torch.cuda.FloatTensor([-1,float("nan"),2]), 1)
(
nan
[torch.cuda.FloatTensor of size 1 (GPU 0)],
9.2054e+18
[torch.cuda.LongTensor of size 1 (GPU 0)])

In CPU, topk seems to ignore "nan" and its indices from result.

In GPU, topk with "nan" is kind of undefined behavior?

and other examples

>>> torch.max(torch.cuda.FloatTensor([float("nan"), 1]))
1.0

>>> torch.max(torch.FloatTensor([float("nan"), 1]))
nan

>>> torch.min(torch.cuda.FloatTensor([float("nan"), 1]))
1.0

>>> torch.min(torch.FloatTensor([float("nan"), 1]))
nan

>>> torch.sort(torch.FloatTensor([float("nan"), 1]))
(
nan
1
[torch.FloatTensor of size 2],
0
1
[torch.LongTensor of size 2])

>> torch.sort(torch.cuda.FloatTensor([float("nan"), 1]))
(
1
nan
[torch.cuda.FloatTensor of size 2 (GPU 0)],
1
0
[torch.cuda.LongTensor of size 2 (GPU 0)])

cc @VitalyFedyunin @ngimel @heitorschueroff