-
Notifications
You must be signed in to change notification settings - Fork 25
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
Introduce ManagedDeviceMesh to integrate DeviceMesh with TorchFT #56
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
24126da
Update
fegin 4b9252b
Update (base update)
fegin 884c4bd
Update
fegin e98c67c
Update
fegin 7453067
Update
fegin 6fb19cd
Update
fegin 50b7520
Update base for Update on "Introduce ManagedDeviceMesh to integrate D…
fegin dd0bdb1
Update on "Introduce ManagedDeviceMesh to integrate DeviceMesh with T…
fegin 9711549
Update on "Introduce ManagedDeviceMesh to integrate DeviceMesh with T…
fegin 029ea69
Update base for Update on "Introduce ManagedDeviceMesh to integrate D…
fegin 95ff257
Update on "Introduce ManagedDeviceMesh to integrate DeviceMesh with T…
fegin 939ac2a
Update base for Update on "Introduce ManagedDeviceMesh to integrate D…
fegin ee798ba
Update on "Introduce ManagedDeviceMesh to integrate DeviceMesh with T…
fegin 73d0e81
Update base for Update on "Introduce ManagedDeviceMesh to integrate D…
fegin 52c5362
Update
fegin 15645b6
Update
fegin 1120930
Update
fegin 96ea9be
Update
fegin 99cb0ab
Update
fegin 556e286
Update
fegin 3122fda
Update (base update)
fegin a03406f
Update
fegin a92576c
Update
fegin 31ba2ef
Update
fegin 745f33e
Update
fegin 85cbb85
Update
fegin d58ee00
Update
fegin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import multiprocessing | ||
import os | ||
import unittest | ||
from concurrent.futures import ProcessPoolExecutor | ||
from typing import Any, Dict, Tuple | ||
from unittest.mock import Mock | ||
|
||
import torch | ||
import torch.distributed as dist | ||
from torch import nn | ||
from torch._C._distributed_c10d import ( | ||
AllgatherOptions, | ||
AllreduceOptions, | ||
BroadcastOptions, | ||
ReduceOp, | ||
_resolve_process_group, | ||
) | ||
from torch.distributed import ( | ||
ReduceOp, | ||
TCPStore, | ||
Work, | ||
_functional_collectives, | ||
get_world_size, | ||
) | ||
from torch.distributed._composable.fsdp import fully_shard | ||
from torch.distributed.device_mesh import init_device_mesh | ||
|
||
from torchft.manager import Manager | ||
from torchft.process_group import ManagedProcessGroup, ft_init_device_mesh | ||
|
||
|
||
class FSDPTest(unittest.TestCase): | ||
@staticmethod | ||
def _test_fsdp(world_size: int, rank: int) -> None: | ||
torch.cuda.set_device(rank) | ||
|
||
group_size = world_size // 2 | ||
group = rank // group_size | ||
group_rank = rank % group_size | ||
|
||
os.environ["MASTER_ADDR"] = "127.0.0.1" | ||
os.environ["MASTER_PORT"] = str(12346 + group) | ||
os.environ["RANK"] = str(group_rank) | ||
os.environ["WORLD_SIZE"] = str(group_size) | ||
|
||
manager = Mock(spec=Manager) | ||
device_mesh = ft_init_device_mesh( | ||
device_type="cuda", | ||
mesh_shape=(2, 2), | ||
mesh_dim_names=("dp_replicate", "dp_shard"), | ||
replicate_dim=0, | ||
manager=manager, | ||
) | ||
manager.num_participants.return_value = 1 | ||
model = nn.Linear(128, 128).cuda() | ||
batch = torch.randn(4, 128).cuda() | ||
shard_model = fully_shard(model, mesh=device_mesh) | ||
shard_model(batch).mean().backward() | ||
|
||
# pyre-ignore[56]: Pyre was not able to infer the type of argument | ||
@unittest.skipIf(torch.cuda.device_count() < 4, "Not enough GPUs") | ||
def test_fsdp(self) -> None: | ||
multiprocessing.set_start_method("spawn") | ||
with ProcessPoolExecutor(max_workers=4) as executor: | ||
futures = [] | ||
for i in range(4): | ||
future = executor.submit(self._test_fsdp, 4, i) | ||
futures.append(future) |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! Does this solve the issue with flattening in FSDP or just throws an error for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work for the case where we flatten the device mesh to compute the global loss average but not work for data loader. I think we need to customize dataloader anyway.