-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (50 loc) · 1.58 KB
/
Copy pathmain.py
File metadata and controls
64 lines (50 loc) · 1.58 KB
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
# -*- coding: utf-8 -*-
# ---------------------
import torch
import logging
from conf import Conf
import click
import torch.backends.cudnn as cudnn
from trainer import trainer_run
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
@click.command()
@click.option('--exp_name', type=str, default=None)
@click.option('--conf_file_path', type=str, default=None)
@click.option('--seed', type=int, default=None)
def main(exp_name, conf_file_path, seed):
# type: (str, str, int) -> None
assert torch.backends.cudnn.enabled, "Running without cuDNN is discouraged"
# if `exp_name` is None,
# ask the user to enter it
if exp_name is None:
exp_name = input('>> experiment name: ')
# if `exp_name` contains '!',
# `log_each_step` becomes `False`
log_each_step = True
if '!' in exp_name:
exp_name = exp_name.replace('!', '')
log_each_step = False
# if `exp_name` contains a '@' character,
# the number following '@' is considered as
# the desired random seed for the experiment
split = exp_name.split('@')
if len(split) == 2:
seed = int(split[1])
exp_name = split[0]
cnf = Conf(conf_file_path=conf_file_path, seed=seed,
exp_name=exp_name, log_each_step=log_each_step)
print(f'\n▶ Starting Experiment \'{exp_name}\' [seed: {cnf.seed}]')
# Setup logging
logging.basicConfig(
format='[%(asctime)s] [p%(process)s] [%(pathname)s:%(lineno)d] [%(levelname)s] %(message)s',
level=logging.INFO,
)
cnf_attrs = vars(cnf)
for k in cnf_attrs:
s = f'{k} : {cnf_attrs[k]}'
logging.info(s)
# Run training
trainer_run(cnf)
if __name__ == '__main__':
main()