simplify examples structure (#1247)

* simplify examples structure

* update changelog

* fix imports

* rename example

* rename scripts

* changelog
This commit is contained in:
Jirka Borovec
2020-04-03 17:57:34 -04:00
committed by GitHub
parent 16f4cc9ff0
commit 22bedf9b57
20 changed files with 138 additions and 84 deletions
@@ -0,0 +1,51 @@
"""
Multi-node example (GPU)
"""
import os
from argparse import ArgumentParser
import numpy as np
import torch
import pytorch_lightning as pl
from pl_examples.models.lightning_template import LightningTemplateModel
SEED = 2334
torch.manual_seed(SEED)
np.random.seed(SEED)
def main(hparams):
"""Main training routine specific for this project."""
# ------------------------
# 1 INIT LIGHTNING MODEL
# ------------------------
model = LightningTemplateModel(hparams)
# ------------------------
# 2 INIT TRAINER
# ------------------------
trainer = pl.Trainer(
gpus=2,
num_nodes=2,
distributed_backend='ddp2'
)
# ------------------------
# 3 START TRAINING
# ------------------------
trainer.fit(model)
if __name__ == '__main__':
root_dir = os.path.dirname(os.path.realpath(__file__))
parent_parser = ArgumentParser(add_help=False)
# each LightningModule defines arguments relevant to it
parser = LightningTemplateModel.add_model_specific_args(parent_parser, root_dir)
hyperparams = parser.parse_args()
# ---------------------
# RUN TRAINING
# ---------------------
main(hyperparams)