2019-09-08 22:17:33 +00:00
|
|
|
"""
|
2020-04-03 19:01:40 +00:00
|
|
|
Runs a model on the CPU on a single node.
|
2019-09-08 22:17:33 +00:00
|
|
|
"""
|
|
|
|
import os
|
2019-10-22 08:32:40 +00:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
2019-09-08 22:17:33 +00:00
|
|
|
import numpy as np
|
|
|
|
import torch
|
|
|
|
|
2020-02-09 22:39:10 +00:00
|
|
|
import pytorch_lightning as pl
|
2020-04-03 21:57:34 +00:00
|
|
|
from pl_examples.models.lightning_template import LightningTemplateModel
|
2019-09-08 22:17:33 +00:00
|
|
|
|
|
|
|
SEED = 2334
|
|
|
|
torch.manual_seed(SEED)
|
|
|
|
np.random.seed(SEED)
|
|
|
|
|
|
|
|
|
|
|
|
def main(hparams):
|
|
|
|
"""
|
|
|
|
Main training routine specific for this project
|
|
|
|
:param hparams:
|
|
|
|
"""
|
|
|
|
# ------------------------
|
|
|
|
# 1 INIT LIGHTNING MODEL
|
|
|
|
# ------------------------
|
|
|
|
model = LightningTemplateModel(hparams)
|
|
|
|
|
|
|
|
# ------------------------
|
|
|
|
# 2 INIT TRAINER
|
|
|
|
# ------------------------
|
2020-03-12 16:42:52 +00:00
|
|
|
trainer = pl.Trainer(max_epochs=hparams.epochs)
|
2019-09-08 22:17:33 +00:00
|
|
|
|
|
|
|
# ------------------------
|
2019-10-05 18:13:32 +00:00
|
|
|
# 3 START TRAINING
|
2019-09-08 22:17:33 +00:00
|
|
|
# ------------------------
|
|
|
|
trainer.fit(model)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-10-05 18:13:32 +00:00
|
|
|
# ------------------------
|
|
|
|
# TRAINING ARGUMENTS
|
|
|
|
# ------------------------
|
|
|
|
# these are project-wide arguments
|
2019-09-08 22:17:33 +00:00
|
|
|
root_dir = os.path.dirname(os.path.realpath(__file__))
|
2019-10-05 18:13:32 +00:00
|
|
|
parent_parser = ArgumentParser(add_help=False)
|
2019-09-08 22:17:33 +00:00
|
|
|
|
2019-10-05 18:13:32 +00:00
|
|
|
# each LightningModule defines arguments relevant to it
|
2019-09-08 22:17:33 +00:00
|
|
|
parser = LightningTemplateModel.add_model_specific_args(parent_parser, root_dir)
|
|
|
|
hyperparams = parser.parse_args()
|
|
|
|
|
|
|
|
# ---------------------
|
|
|
|
# RUN TRAINING
|
|
|
|
# ---------------------
|
|
|
|
main(hyperparams)
|