-
Notifications
You must be signed in to change notification settings - Fork 41
/
train.py
executable file
·48 lines (40 loc) · 1.41 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
37
38
39
40
41
42
43
44
45
46
47
48
import os
import hydra
import logging
import torch
from pytorch_lightning import seed_everything, Trainer
from pytorch_lightning.callbacks import LearningRateMonitor, ModelCheckpoint
from pytorch_lightning.plugins import DDPPlugin
from avg_ckpts import ensemble
from datamodule.data_module import DataModule
@hydra.main(version_base="1.3", config_path="configs", config_name="config")
def main(cfg):
seed_everything(42, workers=True)
cfg.gpus = torch.cuda.device_count()
checkpoint = ModelCheckpoint(
monitor="monitoring_step",
mode="max",
dirpath=os.path.join(cfg.exp_dir, cfg.exp_name) if cfg.exp_dir else None,
save_last=True,
filename="{epoch}",
save_top_k=10,
)
lr_monitor = LearningRateMonitor(logging_interval="step")
callbacks = [checkpoint, lr_monitor]
# Set modules and trainer
if cfg.data.modality in ["audio", "visual"]:
from lightning import ModelModule
elif cfg.data.modality == "audiovisual":
from lightning_av import ModelModule
modelmodule = ModelModule(cfg)
datamodule = DataModule(cfg)
trainer = Trainer(
**cfg.trainer,
#logger=WandbLogger(name=cfg.exp_name, project="auto_avsr"),
callbacks=callbacks,
strategy=DDPPlugin(find_unused_parameters=False)
)
trainer.fit(model=modelmodule, datamodule=datamodule)
ensemble(cfg)
if __name__ == "__main__":
main()