-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for distributed tests on pytorch>=1.12 (#2141)
Fix for distributed tests Co-authored-by: Olatunji Ruwase <olruwase@microsoft.com>
- Loading branch information
Showing
16 changed files
with
365 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import torch | ||
import deepspeed.comm as dist | ||
|
||
from tests.unit.common import DistributedTest | ||
|
||
import pytest | ||
|
||
|
||
class TestInit(DistributedTest): | ||
world_size = 3 | ||
|
||
def test(self): | ||
assert dist.is_initialized() | ||
assert dist.get_world_size() == 3 | ||
assert dist.get_rank() < 3 | ||
|
||
|
||
# Demonstration of pytest's parameterization and fixtures | ||
@pytest.fixture(params=["hello"]) | ||
def greeting(request): | ||
return request.param | ||
|
||
|
||
@pytest.mark.parametrize("number,color", [(1138, "purple")]) | ||
class TestDistArgs(DistributedTest): | ||
world_size = 2 | ||
""" Classes that use DistributedTest class must define a test* method """ | ||
@pytest.mark.parametrize("shape", ["icosahedron"]) | ||
def test(self, number, color, shape, greeting): | ||
"""Ensure that we can parse args to DistributedTest methods. """ | ||
assert dist.get_world_size() == 2 | ||
assert number == 1138 | ||
assert color == "purple" | ||
assert shape == "icosahedron" | ||
assert greeting == "hello" | ||
|
||
|
||
# Demonstration of distributed tests grouped in single class | ||
@pytest.mark.parametrize("number", [1138]) | ||
class TestGroupedDistTest(DistributedTest): | ||
world_size = 2 | ||
|
||
def test_one(self, number): | ||
assert dist.get_world_size() == 2 | ||
assert number == 1138 | ||
|
||
@pytest.mark.parametrize("color", ["purple"]) | ||
def test_two(self, number, color): | ||
assert dist.get_world_size() == 2 | ||
assert number == 1138 | ||
assert color == "purple" | ||
|
||
|
||
class TestDistAllReduce(DistributedTest): | ||
world_size = [1, 2, 4] | ||
|
||
def test(self): | ||
x = torch.ones(1, 3).cuda() * (dist.get_rank() + 1) | ||
sum_of_ranks = (dist.get_world_size() * (dist.get_world_size() + 1)) // 2 | ||
result = torch.ones(1, 3).cuda() * sum_of_ranks | ||
dist.all_reduce(x) | ||
assert torch.all(x == result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.