-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
36 lines (28 loc) · 948 Bytes
/
train.py
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
import os, time
from config.global_train_config import config
import torch
import numpy as np
import random
## For reproducible results
def seed_all(s):
np.random.seed(s)
random.seed(s)
os.environ['PYTHONHASHSEED'] = str(s)
torch.manual_seed(s)
print(f'Seeds set to {s}!')
if not config.using_HPC:
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = f"{config.gpu}"
if __name__ == "__main__":
seed_all(42) #Set random seeds for reproducibility
if config.project == 'PROJECTNAME':
from src.model.archs.PROJECTNAME import MODELCLASS
model = MODELCLASS(config)
else:
raise NotImplementedError
if config.continue_epoch != '-1':
model.load_epoch(config.continue_epoch)
startTime = time.time()
model.train()
print(f'Training {config.project} model took {time.time() - startTime} seconds')
print('Optimization done.')