Skip to content

Commit

Permalink
Distributed initialization process for single process
Browse files Browse the repository at this point in the history
  • Loading branch information
linshokaku committed Oct 30, 2023
1 parent c5b4d58 commit 5485a79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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()

0 comments on commit 5485a79

Please sign in to comment.