Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce multi-node training setup #26

Closed
wants to merge 5 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions train_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Standard library
import os
import random
import time
from argparse import ArgumentParser
Expand All @@ -22,7 +23,7 @@
}


def main():
def main(): # pylint: disable=too-many-branches
"""
Main function for training and evaluating models
"""
Expand Down Expand Up @@ -230,13 +231,24 @@ def main():
)

# Instantiate model + trainer
if args.eval:
use_distributed_sampler = False
else:
use_distributed_sampler = True
sadamov marked this conversation as resolved.
Show resolved Hide resolved

devices = 1
num_nodes = 1
if torch.cuda.is_available():
device_name = "cuda"
torch.set_float32_matmul_precision(
"high"
) # Allows using Tensor Cores on A100s
accelerator = "cuda"
if "SLURM_JOB_ID" in os.environ and not args.eval:
devices = int(
os.environ.get("SLURM_GPUS_PER_NODE", torch.cuda.device_count())
)
num_nodes = int(os.environ.get("SLURM_JOB_NUM_NODES", 1))
# Allows using Tensor Cores on A100s
torch.set_float32_matmul_precision("high")
else:
device_name = "cpu"
accelerator = "cpu"

# Load model parameters Use new args for model
model_class = MODELS[args.model]
Expand Down Expand Up @@ -269,8 +281,10 @@ def main():
trainer = pl.Trainer(
max_epochs=args.epochs,
deterministic=True,
strategy="ddp",
accelerator=device_name,
accelerator=accelerator,
devices=devices,
num_nodes=num_nodes,
use_distributed_sampler=use_distributed_sampler,
logger=logger,
log_every_n_steps=1,
callbacks=[checkpoint_callback],
Expand Down
Loading