-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] ElasticLauncher auto dist_backend
- Loading branch information
Yuyao Huang
committed
Jan 25, 2022
1 parent
aedd5bf
commit 7f6741e
Showing
4 changed files
with
26 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
import pytest | ||
import torch | ||
import torch.distributed as dist | ||
from ice.llutil.multiprocessing.launcher import ElasticLauncher | ||
from ice.llutil.launcher import ElasticLauncher | ||
|
||
|
||
def sum_rank(launcher:ElasticLauncher): | ||
def sum_rank(launcher: ElasticLauncher): | ||
# print(launcher.rank) | ||
tensor = torch.Tensor([launcher.rank]).to(launcher.assigned_device) | ||
dist.all_reduce(tensor, op=dist.ReduceOp.SUM) | ||
|
||
assert tensor.item() == (0 + launcher.world_size - 1) * launcher.world_size // 2 | ||
|
||
|
||
def test_sum_rank(): | ||
launcher = ElasticLauncher(devices="cpu:0-3").freeze() | ||
launcher(sum_rank, launcher) | ||
|
||
|
||
@pytest.mark.cuda | ||
def test_sum_rank_cuda(): | ||
launcher = ElasticLauncher(devices="cuda:0-1").freeze() | ||
launcher = ElasticLauncher(devices="cuda:0,1").freeze() | ||
launcher(sum_rank, launcher) | ||
|
||
|
||
@pytest.mark.cuda | ||
def test_same_gpu(): | ||
launcher = ElasticLauncher(devices="cuda:0,0").freeze() | ||
launcher(sum_rank, launcher) |