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

Distributed initialization for single process #777

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions pytorch_pfn_extras/distributed/_initialize.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from typing import Tuple

import torch
import torch.distributed


def initialize_ompi_environment(
Expand Down Expand Up @@ -60,7 +60,7 @@ def initialize_ompi_environment(
"Invalid value for init_method, only 'env' and 'tcp' are supported"
)

if world_size > 1 and not torch.distributed.is_initialized(): # type: ignore
if not torch.distributed.is_initialized(): # type: ignore
torch.distributed.init_process_group( # type: ignore
backend, init_method=init_method, world_size=world_size, rank=rank
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import torch.distributed
from pytorch_pfn_extras.distributed import initialize_ompi_environment


def test_initialize_ompi_environment_with_single_process():
assert not torch.distributed.is_initialized()
world_size, rank, local_rank = initialize_ompi_environment(
backend="gloo", init_method="tcp"
)
assert torch.distributed.is_initialized()
torch.distributed.destroy_process_group()
assert not torch.distributed.is_initialized()
Loading