-
Notifications
You must be signed in to change notification settings - Fork 2
/
train.py
executable file
·36 lines (30 loc) · 1.39 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
import pytorch_lightning as pl
from pytorch_lightning.callbacks import ModelCheckpoint
from transformers import set_seed
from model import Summarizer, CoCoTripModule
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser()
parser = Summarizer.add_model_specific_args(parser)
parser = pl.Trainer.add_argparse_args(parser)
parser.add_argument("--seed", type=int, default=765)
parser.add_argument("--task", type=str, default="cont")
parser.add_argument("--ckpt", type=str, default=None)
args = parser.parse_args()
print(args)
set_seed(args.seed)
if args.ckpt is None:
summarizer = Summarizer(**vars(args))
else:
from pathlib import Path
ckpt_path = str(next(Path(args.ckpt).glob("*.ckpt")))
summarizer = Summarizer.load_from_checkpoint(ckpt_path, **vars(args))
datamodule = CoCoTripModule(tokenizer=summarizer.tokenizer, **vars(args))
checkpoint_callback = ModelCheckpoint(monitor="val_rouge-12lf",
verbose=True,
save_top_k=1,
mode="max",
filename="{epoch}-{val_rouge-12lf:.3f}")
trainer = pl.Trainer.from_argparse_args(args, callbacks=[checkpoint_callback])
trainer.fit(summarizer, datamodule=datamodule)
trainer.test()