-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_up.py
More file actions
37 lines (29 loc) · 815 Bytes
/
Copy pathset_up.py
File metadata and controls
37 lines (29 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import gc
import random
import warnings
import ctypes
import numpy as np
import torch
def set_seed(seed: int) -> None:
os.environ["PYTHONHASHSEED"] = str(seed)
os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
warnings.filterwarnings("ignore")
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
torch.use_deterministic_algorithms(False)
print(f"Random seed: {seed}")
def clear_memory() -> None:
gc.collect()
if torch.cuda.is_available():
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
try:
ctypes.CDLL("libc.so.6").malloc_trim(0)
except:
pass