How to split dataset into two considering fixed seed to ensure reproducibility in PyTorch?
I am working on one of my University assignment and there is one sub-task which says. Split the data in two (Train and Validation) while using using a fixed seed to ensure reproducibility. I have wrote some code which is working fine but I want to know whether it is the correct way or not?
torch.manual_seed(0)

mnist_train, mnist_val = torch.utils.data.random_split(mnist_rest, [54000,6000])

I am working on MNIST dataset.

According to PyTorch's docs:
Completely reproducible results are not guaranteed across PyTorch releases, individual commits, or different platforms. Furthermore, results may not be reproducible between CPU and GPU executions, even when using identical seeds.
However, there are some steps you can take to limit the number of sources of nondeterministic behavior for a specific platform, device, and PyTorch release. First, you can control sources of randomness that can cause multiple executions of your application to behave differently. Second, you can configure PyTorch to avoid using nondeterministic algorithms for some operations, so that multiple calls to those operations, given the same inputs, will produce the same result.
To control randomness, it's recommended you to use followings to reproduce the result:
In PyTorch:
You can use torch.manual_seed() to seed the RNG for all devices (both CPU and CUDA):
import torch
torch.manual_seed(0)

In Python:
For custom operators, you might need to set python seed as well:
import random
random.seed(0)

If you or any of the libraries you are using rely on NumPy, you can seed the global NumPy RNG with:
import numpy as np
np.random.seed(0)

