-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtrain.py
executable file
·37 lines (30 loc) · 1.06 KB
/
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
37
import torch
from utils.tools import load_vocab, show_info
from utils.trainer import trainer
from utils.args import get_train_parser
from math import inf
from os import environ
import importlib
from preprocess import data_loader
import random
import warnings
warnings.filterwarnings("ignore")
def train():
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = True
args = get_train_parser()
_, tgt_index2word = load_vocab(args.vocab)
vocab_size = len(tgt_index2word)
setattr(args, 'vocab_size', vocab_size)
environ['CUDA_VISIBLE_DEVICES'] = ','.join(args.cuda_num)
show_info(epoch=args.epoch,
vocab_size=vocab_size,
USE_CUDA=len(args.cuda_num) != 0)
environ['MASTER_ADDR'] = 'localhost'
environ['MASTER_PORT'] = '8878'
mp = importlib.import_module('torch.multiprocessing')
seed = random.randint(0, 2048)
setattr(args, 'world_size', len(args.cuda_num))
mp.spawn(trainer, nprocs=args.world_size, args=(args, seed))
if __name__ == '__main__':
train()