-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.py
More file actions
63 lines (50 loc) · 1.75 KB
/
benchmark.py
File metadata and controls
63 lines (50 loc) · 1.75 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
import os
import shutil
from argparse import ArgumentParser, Namespace
from hackathon.model_runner import ModelRunner
from hackathon.models.attn_nores import model_setup as attn_model
from hackathon.models.Conv1D import model_setup as conv1d_model
from hackathon.models.linear import model_setup as linear_model
from hackathon.models.LSTM import model_setup as lstm_model
from hackathon.models.simplemlp import model_setup as simplemlp_model
model_funs = [
linear_model,
attn_model,
conv1d_model,
lstm_model,
simplemlp_model,
]
def main(args: Namespace):
for model_fn in model_funs:
model_name = model_fn.__module__.split('.')[-1].lower()
log_dir = f'./hackathon/logs/{model_name}/xval'
if os.path.isdir(log_dir):
shutil.rmtree(log_dir)
# Training.
runner = ModelRunner(log_dir=log_dir, quickrun=args.quickrun, seed=910)
trainer, model, _ = runner.train(
model_fn=model_fn,
patience=15,
max_epochs=1 if args.quickrun else -1,
accelerator=None if args.gpu == -1 else 'gpu',
devices=None if args.gpu == -1 else f'{args.gpu},')
# Evaluating.
datamodule = runner.data_setup(fold=-1)
runner.predict(
trainer=trainer,
model=model,
datamodule=datamodule,
version='final')
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument(
'--quickrun',
action='store_true',
help='Quick development run with only 1 epoch and 2 CV folds, less data.')
parser.add_argument(
'--gpu',
type=int,
default=-1,
help='GPU ID to use, -1 (default) deactivates GPU.')
args = parser.parse_args()
main(args)