| 153 | |
| 154 | |
| 155 | def set_random_seed(seed: int): |
| 156 | random.seed(seed) |
| 157 | np.random.seed(seed) |
| 158 | torch.manual_seed(seed) |
| 159 | torch.cuda.manual_seed(seed) |
| 160 | torch.cuda.manual_seed_all(seed) # For multi-GPU |
| 161 | torch.backends.cudnn.deterministic = True |
| 162 | torch.backends.cudnn.benchmark = False |
| 163 | os.environ['PYTHONHASHSEED'] = str(seed) |
| 164 | |
| 165 | # try: |
| 166 | # torch.use_deterministic_algorithms(True) |
| 167 | # except Exception as e: |
| 168 | # print(f"Could not use deterministic algorithms: {e}") |
| 169 | |
| 170 | torch.backends.cuda.matmul.allow_tf32 = False |
| 171 | torch.backends.cudnn.allow_tf32 = False |
| 172 | |
| 173 | def verify_random_seed(result_dir: str): |
| 174 | """ |