I encountered an inconsistent torch.max() behaviour when running it on cpu and gpu, which can be reproduced by:
import torch
x = torch.FloatTensor(2, 10, 10)
x[0, :, :] = 1
x[1, :, :] = 2
x[:, 3:7, 3:7] = 0
value, idx = torch.max(x, 0)
print(idx)
(0 ,.,.) =
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 0 0 0 0 1 1 1
1 1 1 0 0 0 0 1 1 1
1 1 1 0 0 0 0 1 1 1
1 1 1 0 0 0 0 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
[torch.LongTensor of size 1x10x10]
, and
value, idx = torch.max(x.cuda(), 0)
print(idx)
(0 ,.,.) =
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
[torch.cuda.LongTensor of size 1x10x10 (GPU 0)]
I supposed both the cpu and gpu output should be consistent?