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
|
|
|
|
|
2020-06-27 13:13:29 +00:00
|
|
|
from pytorch_lightning import Trainer, seed_everything
|
2020-04-03 21:57:34 +00:00
|
|
|
from pl_examples.models.lightning_template import LightningTemplateModel
|
2019-09-08 22:17:33 +00:00
|
|
|
|
2020-06-27 13:13:29 +00:00
|
|
|
seed_everything(234)
|
2019-09-08 22:17:33 +00:00
|
|
|
|
|
|
|
|
2020-06-01 15:00:32 +00:00
|
|
|
def main(args):
|
2020-07-03 04:17:18 +00:00
|
|
|
""" Main training routine specific for this project. """
|
2019-09-08 22:17:33 +00:00
|
|
|
# ------------------------
|
|
|
|
# 1 INIT LIGHTNING MODEL
|
|
|
|
# ------------------------
|
2020-06-01 15:00:32 +00:00
|
|
|
model = LightningTemplateModel(**vars(args))
|
2019-09-08 22:17:33 +00:00
|
|
|
|
|
|
|
# ------------------------
|
|
|
|
# 2 INIT TRAINER
|
|
|
|
# ------------------------
|
2020-06-27 13:13:29 +00:00
|
|
|
trainer = Trainer.from_argparse_args(args)
|
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)
|
|
|
|
|
|
|
|
|
2020-06-27 13:13:29 +00:00
|
|
|
def run_cli():
|
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)
|
2020-06-27 13:13:29 +00:00
|
|
|
parser = Trainer.add_argparse_args(parser)
|
2020-06-01 15:00:32 +00:00
|
|
|
args = parser.parse_args()
|
2019-09-08 22:17:33 +00:00
|
|
|
|
|
|
|
# ---------------------
|
|
|
|
# RUN TRAINING
|
|
|
|
# ---------------------
|
2020-06-01 15:00:32 +00:00
|
|
|
main(args)
|
2020-06-27 13:13:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run_cli()
|