Compare commits

...
25 Commits
Author SHA1 Message Date
William Falcon ab87244884 release v0.2.6 2019-07-20 09:39:00 -04:00
William Falcon 2aa0b3be5c removed logging 2019-07-20 09:31:10 -04:00
William Falcon 0fdf290201 removed logging 2019-07-20 09:22:47 -04:00
William Falcon 1a39f703ad removed logging 2019-07-20 09:22:04 -04:00
William Falcon 955e9ea6d5 removed logging 2019-07-20 09:18:45 -04:00
William Falcon 10e031a843 removed logging 2019-07-20 09:17:20 -04:00
William Falcon 229d168c20 removed logging 2019-07-20 09:15:09 -04:00
William Falcon 468bd141f4 added slurm managed flag catch for non-slurm peeps 2019-07-20 09:08:24 -04:00
William Falcon 00678c6053 added slurm managed flag catch for non-slurm peeps 2019-07-20 08:53:36 -04:00
William Falcon bbb5001aac added slurm managed flag catch for non-slurm peeps 2019-07-20 08:53:24 -04:00
William Falcon a514674358 added slurm managed flag catch for non-slurm peeps 2019-07-20 08:38:17 -04:00
William Falcon 9757841e67 release v0.2.5.2 2019-07-18 17:59:39 -04:00
William Falcon 0ac7a8590b added slurm managed flag catch for non-slurm peeps 2019-07-18 17:59:16 -04:00
William Falcon 6e12431e6b added slurm managed flag catch for non-slurm peeps 2019-07-18 17:58:38 -04:00
William Falcon c2e2298586 release v0.2.5.1 2019-07-18 17:14:34 -04:00
William Falcon 319feb7da5 removed printing. added auto process gen if slurm tasks do not match 2019-07-18 17:13:57 -04:00
William Falcon 5195124d4e added slurm no process warning 2019-07-18 17:06:56 -04:00
William Falcon 4e67983f23 added slurm no process warning 2019-07-18 17:05:09 -04:00
William Falcon c02b6c4c88 added slurm no process warning 2019-07-18 17:03:27 -04:00
William Falcon ad44d9168b added slurm no process warning 2019-07-18 16:47:46 -04:00
William Falcon 53a1a6d462 removed print lines 2019-07-18 16:37:48 -04:00
William Falcon 59d60eaf18 testing single process ddp 2019-07-18 15:06:20 -04:00
William Falcon 112be99b19 testing single process ddp 2019-07-18 14:57:56 -04:00
William Falcon 0e67773d2e testing single process ddp 2019-07-18 14:53:01 -04:00
William Falcon 394cdeeb8b added epoch flag back 2019-07-18 13:32:36 -04:00
2 changed files with 51 additions and 16 deletions
+50 -15
View File
@@ -1,12 +1,12 @@
""" """
The trainer handles all the logic for running a val loop, training loop, distributing, etc... The trainer handles all the logic for running a val loop, training loop, distributing, etc...
""" """
from time import sleep
import subprocess import subprocess
import traceback import traceback
import warnings import warnings
import os import os
import pdb import pdb
import re
import torch import torch
from torch.utils.data.distributed import DistributedSampler from torch.utils.data.distributed import DistributedSampler
@@ -146,6 +146,7 @@ class Trainer(TrainerIO):
self.print_nan_grads = print_nan_grads self.print_nan_grads = print_nan_grads
self.data_parallel_device_ids = None self.data_parallel_device_ids = None
self.world_size = 1 self.world_size = 1
self.node_rank = 0
self.use_ddp = False self.use_ddp = False
self.use_dp = False self.use_dp = False
@@ -372,15 +373,35 @@ class Trainer(TrainerIO):
# when using multi-node or DDP within a node start each module in a separate process # when using multi-node or DDP within a node start each module in a separate process
if self.use_ddp: if self.use_ddp:
print('using ddp')
# must copy only the meta of the exp so it survives pickle/unpickle when going to new process # must copy only the meta of the exp so it survives pickle/unpickle when going to new process
self.experiment = self.experiment.get_meta_copy() self.experiment = self.experiment.get_meta_copy()
mp.spawn(self.ddp_train, nprocs=len(self.data_parallel_device_ids), args=(model, ))
# whenever we have the correct number of tasks, we let slurm manage processes
# otherwise we launch the required number of processes
try:
nb_slurm_tasks = int(os.environ['SLURM_NTASKS'])
nb_requested_gpus = len(self.data_parallel_device_ids) * self.nb_gpu_nodes
is_slurm_managing_tasks = nb_slurm_tasks == nb_requested_gpus
except Exception as e:
# likely not on slurm, so set the slurm managed flag to false
is_slurm_managing_tasks = False
if is_slurm_managing_tasks:
task = int(os.environ['SLURM_LOCALID'])
self.ddp_train(task, model)
else:
msg = f"""
You requested {nb_requested_gpus} GPUs but launched {nb_slurm_tasks} slurm tasks.
We will launch {nb_requested_gpus} processes for you.
We recommend you let slurm manage the processes by setting: --ntasks-per-node={nb_requested_gpus}
If you're not using SLURM, ignore this message!
"""
warnings.warn(msg)
mp.spawn(self.ddp_train, nprocs=len(self.data_parallel_device_ids), args=(model, ))
# 1 gpu or dp option triggers training using DP module # 1 gpu or dp option triggers training using DP module
# easier to avoid NCCL issues # easier to avoid NCCL issues
elif self.use_dp: elif self.use_dp:
print('using dp')
self.dp_train(model) self.dp_train(model)
# ON CPU # ON CPU
@@ -416,7 +437,6 @@ class Trainer(TrainerIO):
) )
self.optimizers = optimizers self.optimizers = optimizers
self.__run_pretrain_routine(model) self.__run_pretrain_routine(model)
def ddp_train(self, gpu_nb, model): def ddp_train(self, gpu_nb, model):
@@ -430,9 +450,10 @@ class Trainer(TrainerIO):
# node rank using relative slurm id # node rank using relative slurm id
# otherwise default to node rank 0 # otherwise default to node rank 0
try: try:
node_rank = int(os.environ['SLURM_NODEID']) node_id = os.environ['SLURM_NODEID']
except KeyError as e: self.node_rank = int(node_id)
node_rank = 0 except Exception as e:
self.node_rank = 0
# recover original exp before went into process # recover original exp before went into process
# init in write mode only on proc 0 # init in write mode only on proc 0
@@ -440,10 +461,10 @@ class Trainer(TrainerIO):
self.experiment = self.experiment.get_non_ddp_exp() self.experiment = self.experiment.get_non_ddp_exp()
# show progbar only on prog_rank 0 # show progbar only on prog_rank 0
self.prog_bar = self.prog_bar and node_rank == 0 and gpu_nb == 0 self.prog_bar = self.prog_bar and self.node_rank == 0 and gpu_nb == 0
# determine which process we are and world size # determine which process we are and world size
self.proc_rank = node_rank * len(self.data_parallel_device_ids) + gpu_nb self.proc_rank = self.node_rank * len(self.data_parallel_device_ids) + gpu_nb
self.world_size = self.nb_gpu_nodes * len(self.data_parallel_device_ids) self.world_size = self.nb_gpu_nodes * len(self.data_parallel_device_ids)
# set up server using proc 0's ip address # set up server using proc 0's ip address
@@ -488,15 +509,29 @@ class Trainer(TrainerIO):
port = 12910 port = 12910
os.environ['MASTER_PORT'] = f'{port}' os.environ['MASTER_PORT'] = f'{port}'
root_node = self.__resolve_root_node_address()
os.environ['MASTER_ADDR'] = root_node
dist.init_process_group("nccl", rank=self.proc_rank, world_size=self.world_size)
def __resolve_root_node_address(self):
try: try:
root_node = os.environ['SLURM_NODELIST'].split(' ')[0] root_node = os.environ['SLURM_NODELIST'].split(' ')[0]
if '[' in root_node:
name = root_node.split('[')[0]
number = root_node.split(',')[0]
if '-' in number:
number = number.split('-')[0]
number = re.sub('[^0-9]', '', number)
root_node = name + number
except Exception as e: except Exception as e:
root_node = '127.0.0.2' root_node = '127.0.0.2'
os.environ['MASTER_ADDR'] = root_node return root_node
sleep(self.proc_rank*0.5)
dist.init_process_group("nccl", rank=self.proc_rank, world_size=self.world_size)
def __run_pretrain_routine(self, model): def __run_pretrain_routine(self, model):
""" """
@@ -672,7 +707,7 @@ class Trainer(TrainerIO):
def __log_vals_blacklist(self): def __log_vals_blacklist(self):
"""avoid logging some vals lightning uses to maintain state""" """avoid logging some vals lightning uses to maintain state"""
blacklist = {'batch_nb', 'v_nb', 'epoch', 'gpu'} blacklist = {'batch_nb', 'v_nb', 'gpu'}
return blacklist return blacklist
def __run_tng_batch(self, data_batch, batch_nb): def __run_tng_batch(self, data_batch, batch_nb):
+1 -1
View File
@@ -7,7 +7,7 @@ from setuptools import setup, find_packages
# http://blog.ionelmc.ro/2014/05/25/python-packaging/ # http://blog.ionelmc.ro/2014/05/25/python-packaging/
setup( setup(
name="pytorch-lightning", name="pytorch-lightning",
version='0.2.5', version='0.2.6',
description="The Keras for ML researchers using PyTorch", description="The Keras for ML researchers using PyTorch",
author="William Falcon", author="William Falcon",
author_email="waf2107@columbia.edu", author_email="waf2107@columbia.edu",