Torch.rand() generates very large numbers

When debugging my code, I found that torch.rand() sometimes can generate very big numbers.

A fraction of my code:

u1 = Variable(torch.rand(mu.size()).cuda())
u2 = Variable(torch.rand(mu.size()).cuda())
if mu.data.dim() == 6:
print(‘u1’, u1.data.max())
print(torch.rand(1))

Printed result (I use two GPUs):

u1 4293885184.0
u1 4293885184.0

1.6911e+09
[torch.FloatTensor of size 1]

1.6911e+09
[torch.FloatTensor of size 1]

My pytorch is compiled 3 weeks ago. Is it the problem of torch.rand()? Thanks for help!

print(torch.rand(1))
1.6911e+09
[torch.FloatTensor of size 1]

That’s the weirdest bug I have ever seen :no_mouth:

1 Like

Yeah, it’s very strange.

However, I avoided this problem by using a single GPU (by setting the nn.DataParallel device_ids = [0]). I will update pytorch and try multi GPU again.