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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment port when taken #2140

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions pytorch_lightning/core/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,8 @@ def init_ddp_connection(
self,
global_rank: int,
world_size: int,
is_slurm_managing_tasks: bool = True
is_slurm_managing_tasks: bool = True,
retries: int = 20
) -> None:
"""
Override to define your custom way of setting up a distributed environment.
Expand Down Expand Up @@ -957,7 +958,16 @@ def init_ddp_connection(

torch_backend = "nccl" if self.trainer.on_gpu else "gloo"
log.info(f"initializing ddp: GLOBAL_RANK: {global_rank}, MEMBER: {global_rank+1}/{world_size}")
torch_distrib.init_process_group(torch_backend, rank=global_rank, world_size=world_size)
while True:
try:
torch_distrib.init_process_group(torch_backend, rank=global_rank, world_size=world_size)
break
except RuntimeError:
# port is taken; we increment the port and try again
if retries <= 0:
raise
retries -= 1
os.environ['MASTER_PORT'] = str(int(os.environ['MASTER_PORT']) + 1)

def configure_apex(
self,
Expand Down