Upload src/egg_damage/seeds.py
Browse files- src/egg_damage/seeds.py +22 -0
src/egg_damage/seeds.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import random
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def set_seed(seed: int) -> None:
|
| 10 |
+
random.seed(seed)
|
| 11 |
+
np.random.seed(seed)
|
| 12 |
+
os.environ["PYTHONHASHSEED"] = str(seed)
|
| 13 |
+
try:
|
| 14 |
+
import torch
|
| 15 |
+
|
| 16 |
+
torch.manual_seed(seed)
|
| 17 |
+
torch.cuda.manual_seed_all(seed)
|
| 18 |
+
torch.backends.cudnn.benchmark = False
|
| 19 |
+
torch.backends.cudnn.deterministic = True
|
| 20 |
+
except Exception:
|
| 21 |
+
pass
|
| 22 |
+
|