From b1e16c2e7bc7e7c98cd29df395488a6c43af0ce8 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 24 Jul 2019 15:11:29 -0400 Subject: [PATCH] added auto port find --- pytorch_lightning/models/trainer.py | 6 +++++- tests/test_models.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/models/trainer.py b/pytorch_lightning/models/trainer.py index 2f26e915..e098ba9a 100644 --- a/pytorch_lightning/models/trainer.py +++ b/pytorch_lightning/models/trainer.py @@ -570,7 +570,11 @@ class Trainer(TrainerIO): :return: """ # sets the appropriate port - self.__find_open_port() + try: + port = os.environ['MASTER_PORT'] + except Exception as e: + port = 12910 + os.environ['MASTER_PORT'] = f'{port}' root_node = self.__resolve_root_node_address() os.environ['MASTER_ADDR'] = root_node diff --git a/tests/test_models.py b/tests/test_models.py index 6716fef5..5159b33e 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -113,6 +113,8 @@ def test_multi_gpu_model_ddp(): warnings.warn('test_multi_gpu_model_ddp cannot run. Rerun on a node with 2+ GPUs to run this test') return + os.environ['MASTER_PORT'] = str(np.random.randint(12000, 19000, 1)[0]) + trainer_options = dict( progress_bar=False, max_nb_epochs=1, @@ -137,6 +139,8 @@ def test_amp_gpu_ddp(): warnings.warn('test_amp_gpu_ddp cannot run. Rerun on a node with 2+ GPUs to run this test') return + os.environ['MASTER_PORT'] = str(np.random.randint(12000, 19000, 1)[0]) + trainer_options = dict( progress_bar=True, max_nb_epochs=1,