# Why is it required to set seeds separately for each library?

I have set the seed for torch in my code as:

``````torch.manual_seed(3)
``````

Now, since I am importing numpy and tensorflow as well, is it required set the seeds for each library separately? If yes, why?

Yes, this is required since each library uses their own pseudorandom number generator, which needs to be seeded.

Thank you for the clarification.
So does the number I use matter? For example, since I used 3 for torch, should I use 3 for the other libraries also or it can be any random number?

No, I don’t think it matters since different PRNG implementations could be used as already seen in this small example:

``````torch.manual_seed(2809)
torch.randn(1)
# tensor([-2.0748])

np.random.seed(2809)
np.random.randn(1)
# array([0.23747478])
``````

Also note that not all libraries support the same backends (e.g. numpy doesn’t support the GPU) so a parity isn’t even possible for all use cases.

1 Like