code: import random
  import numpy as np
  import torch
  
  
  def set_random_seed(seed):
      if seed < 0:
          return
      random.seed(seed)
      np.random.seed(seed)
      torch.manual_seed(seed)
      torch.cuda.manual_seed(seed)
      torch.cuda.manual_seed_all(seed)
      torch.backends.cudnn.deterministic = True
      torch.backends.cudnn.benchmark = False
  
  def worker_init_fn(worker_id):
      """The function is designed for pytorch multi-process dataloader.
      Note that we use the pytorch random generator to generate a base_seed.
      Please try to be consistent.
  
      References:
          https://pytorch.org/docs/stable/notes/faq.html#dataloader-workers-random-seed
  
      """
      base_seed = torch.IntTensor(1).random_().item()
      # print(worker_id, base_seed)
      np.random.seed(base_seed + worker_id)
  
  def dist_worker_init_fn(worker_id):
  
      worker_seed = torch.initial_seed() % 2**32
      np.random.seed(worker_seed)
      random.seed(worker_seed)
apis: torch.cuda.manual_seed_all torch.cuda.manual_seed torch.manual_seed torch.initial_seed numpy.random.seed torch.IntTensor