What is manual_seed?

You just need to call torch.manual_seed(seed), and it will set the seed of the random number generator to a fixed value, so that when you call for example torch.rand(2), the results will be reproducible.
An example

import torch

torch.manual_seed(2)
print(torch.rand(2))

gives you

 0.4360
 0.1851
[torch.FloatTensor of size 2]

Try now without the torch.manual_seed, and you’ll see that it changes over time.

16 Likes