Fix random seed in training, validation and test generator

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

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 =, **params)

validation_set = Dataset(partition['validation'], labels)
validation_generator =, **params)
  1. 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?

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

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