-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.py
92 lines (76 loc) · 3.05 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import faulthandler
from pytest import param
faulthandler.enable()
from pytorch_lightning.loggers import WandbLogger
# Standard libraries
import wandb
from agents.BaseTrainer import BaseTrainer
from config.hparams import Parameters
from utils.agent_utils import parse_params
def main():
parameters = Parameters.parse()
# initialize wandb instance
wdb_config = parse_params(parameters)
if parameters.hparams.train:
tags = [
parameters.data_param.dataset_name,
parameters.data_param.subset,
parameters.optim_param.optimizer,
parameters.network_param.network_name,
f"{'not'*(not parameters.network_param.freeze)} freezed",
parameters.network_param.pretrained_name,
]
if parameters.hparams.limit_train_batches != 1.0:
tags += [f"{parameters.hparams.limit_train_batches}_train"]
if parameters.network_param.freeze_transformer:
tags += ["transformer_freezed"]
wandb.init(
name=f"{parameters.network_param.network_name}_{parameters.data_param.language}{'_CNN_not_freezed'*(not parameters.network_param.freeze)}{f'_{parameters.hparams.limit_train_batches}_train'*(parameters.hparams.limit_train_batches!=1.0)}{'_tf_freezed'*(parameters.network_param.freeze_transformer)}",
config=wdb_config,
project=parameters.hparams.wandb_project,
entity=parameters.hparams.wandb_entity,
allow_val_change=True,
job_type="train",
tags=tags,
)
wandb_run = WandbLogger(
config=wdb_config,
project=parameters.hparams.wandb_project,
entity=parameters.hparams.wandb_entity,
allow_val_change=True,
)
agent = BaseTrainer(parameters, wandb_run)
agent.run()
else:
tags = [
parameters.data_param.dataset_name,
parameters.data_param.subset,
parameters.data_param.language,
parameters.network_param.network_name,
f"{'not'*(not parameters.network_param.freeze)} freezed",
parameters.network_param.pretrained_name,
"test",
]
if parameters.hparams.limit_train_batches != 1.0:
tags += [f"{parameters.hparams.limit_train_batches}_train"]
if parameters.network_param.freeze_transformer:
tags += ["transformer_freezed"]
wandb_run = wandb.init(
name=parameters.hparams.best_model_run + "_test",
config=wdb_config,
project=parameters.hparams.wandb_project,
entity=parameters.hparams.wandb_entity,
allow_val_change=True,
job_type="test",
tags=tags,
)
wandb_logger = WandbLogger(
config=wdb_config,
project=parameters.hparams.wandb_project,
entity=parameters.hparams.wandb_entity,
allow_val_change=True,
)
agent = BaseTrainer(parameters, wandb_logger)
agent.predict()
if __name__ == "__main__":
main()