-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
29 lines (26 loc) · 990 Bytes
/
utils.py
File metadata and controls
29 lines (26 loc) · 990 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
import os
import sys
import json
import torch
import random
import numpy as np
def seed_everything(seed: int):
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
torch.use_deterministic_algorithms(True, warn_only=True)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
def handle_unhandled_exception(exc_type, exc_value, exc_traceback, logger=None):
if issubclass(exc_type, KeyboardInterrupt):
#Will call default excepthook
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
#Create a critical level log message with info from the except hook.
logger.critical("Unhandled exception", exc_info=(exc_type, exc_value, exc_traceback))
def save_to_json(data, file_name):
with open(file_name, 'w') as fp:
json.dump(data, fp)