Set the random seed for reproducibility. Parameters: seed (int): The seed to use for generating random numbers.
(seed, set_cudnn=False)
| 61 | |
| 62 | |
| 63 | def set_random_seed(seed, set_cudnn=False): |
| 64 | """Set the random seed for reproducibility. |
| 65 | |
| 66 | Parameters: |
| 67 | seed (int): The seed to use for generating random numbers. |
| 68 | """ |
| 69 | torch.manual_seed(seed) |
| 70 | if torch.cuda.is_available(): |
| 71 | torch.cuda.manual_seed_all(seed) # For multi-GPU. |
| 72 | np.random.seed(seed) |
| 73 | random.seed(seed) |
| 74 | if set_cudnn and torch.backends.cudnn.is_available(): |
| 75 | torch.backends.cudnn.deterministic = True |
| 76 | torch.backends.cudnn.benchmark = False |
no outgoing calls
no test coverage detected