Difference between two tensors using the same device

Hi

Doing my first steps with PyTorch…

I’m trying to understand why tensor a and b yield different results when the device assignment is as follows(assuming device=cuda):

torch.manual_seed(1234)
a = torch.rand(size=(2,3)).to(device)
b = torch.rand(size=(2,3), device=device)

Thanks!

Different backends could use different algorithms for the desired operations which are not guaranteed to return bitwise identical results. E.g. in this case cuRAND will be used on the GPU to sample the random numbers.

Thanks for the reply.

I guess I should stick with one way only. Should I prefer one method over the other?

For performance reason you could directly create the tensor in the device you want to use in your script.

Thank you, will take this into account.