Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add allreduce test #7

Merged
merged 3 commits into from
Feb 4, 2020
Merged
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
6 changes: 3 additions & 3 deletions tests/unit/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
DEEPSPEED_UNIT_WORKER_TIMEOUT = 5


def distributed_test(world_size=2):
def distributed_test(world_size=2, backend='gloo'):
"""A decorator for executing a function (e.g., a unit test) in a distributed manner.
This decorator manages the spawning and joining of processes, initialization of
torch.distributed, and catching of errors.
Expand All @@ -33,14 +33,14 @@ def dist_init(local_rank, num_procs, *func_args, **func_kwargs):
"""Initialize torch.distributed and execute the user function. """
os.environ['MASTER_ADDR'] = '127.0.0.1'
os.environ['MASTER_PORT'] = '29500'
dist.init_process_group(backend='nccl',
dist.init_process_group(backend=backend,
init_method='env://',
rank=local_rank,
world_size=num_procs)

# XXX temporarily disabled due to CUDA runtime error?
#if torch.cuda.is_available():
# torch.cuda.set_device(local_rank)
# torch.cuda.set_device(local_rank)

run_func(*func_args, **func_kwargs)

Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_dist.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import torch
import torch.distributed as dist

from common import distributed_test
Expand Down Expand Up @@ -26,3 +27,11 @@ def _test_dist_args_helper(x, color='red'):

"""Ensure that we can parse args to distributed_test decorated functions. """
_test_dist_args_helper(number, color=color)


@distributed_test(world_size=2)
def test_dist_allreduce():
x = torch.ones(1, 3) * (dist.get_rank() + 1)
result = torch.ones(1, 3) * 3
dist.all_reduce(x)
assert torch.all(x == result)