-
Notifications
You must be signed in to change notification settings - Fork 8
/
run.py
65 lines (49 loc) · 2.35 KB
/
run.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (c) 2020 Idiap Research Institute, https://www.idiap.ch/
# Written by Alireza Mohammadshahi <[email protected]>,
# This file is part of g2g-transformer.
# g2g-transformer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
# g2g-transformer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with g2g-transformer. If not, see <https://www.gnu.org/licenses/>.
import argparse
import os
from parser.cmds import Predict, Train
import torch
from config import Config
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Create the Biaffine Parser model.'
)
subparsers = parser.add_subparsers(title='Commands', dest='mode')
subcommands = {
'predict': Predict(),
'train': Train()
}
for name, subcommand in subcommands.items():
subparser = subcommand.add_subparser(name, subparsers)
subparser.add_argument('--conf', '-c', default='config.ini',
help='path to config file')
subparser.add_argument('--model', '-m', default='exp/',
help='path to model file')
subparser.add_argument('--seed', '-s', default=1, type=int,
help='seed for generating random numbers')
subparser.add_argument('--threads', '-t', default=4, type=int,
help='max num of threads')
subparser.add_argument('--batch_size', default=1000, type=int,
help='max num of buckets to use')
args = parser.parse_args()
print(f"Set the max num of threads to {args.threads}")
print(f"Set the seed for generating random numbers to {args.seed}")
torch.set_num_threads(args.threads)
torch.manual_seed(args.seed)
print(f"Override the default configs with parsed arguments")
config = Config(args.conf)
config.update(vars(args))
print(f"Run the subcommand in mode {args.mode}")
cmd = subcommands[args.mode]
cmd(config)