Is it possible to fix the seed for torch.utils.data.random_split() when splitting a dataset so that it is possible to reproduce the test results?
torch. seed()[source] Sets the seed for generating random numbers to a non-deterministic random number. Returns a 64 bit number used to seed the RNG.
You can use torch. seed() to get the current seed. You might want to check the reproducibility part of the doc though: https://pytorch.org/docs/stable/notes/randomness.html as having the seed most likely won't allow you to reproduce the result if you're using a different machine or using ops that are not deterministic.
You can use torch.manual_seed function to seed the script globally:
import torch
torch.manual_seed(0)
See reproducibility documentation for more information.
If you want to specifically seed torch.utils.data.random_split you could "reset" the seed to it's initial value afterwards. Simply use torch.initial_seed() like this:
torch.manual_seed(torch.initial_seed())
AFAIK pytorch does not provide arguments like seed or random_state (which could be seen in sklearn for example).
As you can see from the documentation is possible to pass a generator to random_split
random_split(range(10), [3, 7], generator=torch.Generator().manual_seed(42))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With