2019-09-08 22:17:33 +00:00
|
|
|
"""
|
|
|
|
Multi-node example (GPU)
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import numpy as np
|
|
|
|
import torch
|
|
|
|
|
2019-10-05 18:21:12 +00:00
|
|
|
from argparse import ArgumentParser
|
2019-09-08 22:17:33 +00:00
|
|
|
from pytorch_lightning import Trainer
|
2019-10-18 13:44:58 +00:00
|
|
|
from pl_examples.basic_examples.lightning_module_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:
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
# ------------------------
|
|
|
|
# 1 INIT LIGHTNING MODEL
|
|
|
|
# ------------------------
|
|
|
|
model = LightningTemplateModel(hparams)
|
|
|
|
|
|
|
|
# ------------------------
|
|
|
|
# 2 INIT TRAINER
|
|
|
|
# ------------------------
|
|
|
|
trainer = Trainer(
|
2019-10-05 18:21:12 +00:00
|
|
|
gpus=2,
|
2019-10-05 20:39:05 +00:00
|
|
|
nb_gpu_nodes=2,
|
|
|
|
distributed_backend='ddp'
|
2019-09-08 22:17:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# ------------------------
|
2019-10-05 18:21:12 +00:00
|
|
|
# 3 START TRAINING
|
2019-09-08 22:17:33 +00:00
|
|
|
# ------------------------
|
|
|
|
trainer.fit(model)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
2019-10-05 18:21:12 +00:00
|
|
|
root_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
parent_parser = ArgumentParser(add_help=False)
|
2019-09-08 22:17:33 +00:00
|
|
|
|
2019-10-05 18:21:12 +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)
|