So I am able to fix the seeds and produce the same result everytime I run a new training. That is great. However, there are still some things I haven’t been able to answer myself.
My code is as follows and my questions are below the code.
seed = 1

def seed_worker(worker_id):
    import torch
    import random
    worker_seed = torch.initial_seed() % 2**32
    np.random.seed(worker_seed)
    random.seed(worker_seed)

random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

params = {'batch_size': batch_size,
          'shuffle': shuffle,
          'num_workers': num_workers,
          'worker_init_fn': seed_worker}

training_set = Dataset(partition['train'], labels)
training_generator = torch.utils.data.DataLoader(training_set, **params)

validation_set = Dataset(partition['validation'], labels)
validation_generator = torch.utils.data.DataLoader(validation_set, **params)



Is it possible to fix different seeds for each generator (training, validation)? And does it even make sense? Or do they already get different seeds?


In definition seed_worker, is it possible to choose a seed myself for the parameter worker_seed?


are some of my initializations redundant (e.g. manual_seed(…) etc.)?