随机数种子

  1. def init_seeds(seed=0):
  2. torch.manual_seed(seed) # sets the seed for generating random numbers.
  3. torch.cuda.manual_seed(seed) # Sets the seed for generating random numbers for the current GPU. It’s safe to call this function if CUDA is not available; in that case, it is silently ignored.
  4. torch.cuda.manual_seed_all(seed) # Sets the seed for generating random numbers on all GPUs. It’s safe to call this function if CUDA is not available; in that case, it is silently ignored.
  5. if seed == 0:
  6. torch.backends.cudnn.deterministic = True
  7. torch.backends.cudnn.benchmark = False

参见:12