-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
36 lines (34 loc) · 1.22 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 torch
import pytorch_lightning as pl
from model import ClipBert
from dataset import MSCTDDataModule
import config
from callbacks import MyPrintingCallback, EarlyStopping
from pytorch_lightning.loggers import TensorBoardLogger
from pytorch_lightning.profilers import PyTorchProfiler
torch.set_float32_matmul_precision("medium") # make lightning happy
if __name__ == "__main__":
logger = TensorBoardLogger("tb_logs", name="model_v1")
profiler = PyTorchProfiler(
on_trace_ready=torch.profiler.tensorboard_trace_handler("tb_logs/profiler0"),
schedule=torch.profiler.schedule(skip_first=10, wait=1, warmup=1, active=20),
)
model = ClipBert(config=config)
dm = MSCTDDataModule(
data_dir=config.DATA_DIR,
batch_size=config.BATCH_SIZE,
num_workers=config.NUM_WORKERS,
)
trainer = pl.Trainer(
profiler=profiler,
logger=logger,
accelerator=config.ACCELERATOR,
devices=config.DEVICES,
min_epochs=1,
max_epochs=config.NUM_EPOCHS,
precision=config.PRECISION,
callbacks=[MyPrintingCallback(), EarlyStopping(monitor="val_loss")],
)
trainer.fit(model, dm)
trainer.validate(model, dm)
trainer.test(model, dm)