shAIo
(Shay Levy)
January 17, 2026, 1:06pm
1
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.
shAIo
(Shay Levy)
January 17, 2026, 2:51pm
3
Thanks for the reply.
I guess I should stick with one way only. Should I prefer one method over the other?
ptrblck
January 18, 2026, 12:00am
4
For performance reason you could directly create the tensor in the device you want to use in your script.
shAIo
(Shay Levy)
January 18, 2026, 5:03am
5
Thank you, will take this into account.