-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add ShardedTensor
support in LightningModule
#8944
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e7c66ae
Add `ShardedTensor` support in `LightningModule`
52262dd
Make single_process_pg a test helper
1255cb0
Apply suggestions from code review
b722d80
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c952e9e
Update pytorch_lightning/core/lightning.py
3f48510
Make single_process_pg a pytest.fixture
3bcef8a
Update tests/conftest.py
ananthsub 06afc4e
CHANGELOG
447af29
Merge branch 'master' into sharded_tensor_hooks
ananthsub 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
# Copyright The PyTorch Lightning team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
from contextlib import contextmanager | ||
|
||
import torch.distributed as dist | ||
|
||
from pytorch_lightning.plugins.environments.lightning_environment import find_free_network_port | ||
|
||
|
||
@contextmanager | ||
def single_process_pg(): | ||
yifuwang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Initialize the default process group with only the current process for | ||
testing purposes. The process group is destroyed when the with block is | ||
exited. | ||
""" | ||
if dist.is_initialized(): | ||
raise RuntimeError("Can't use `single_process_pg ` when the default process group is already initialized.") | ||
yifuwang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
orig_environ = os.environ.copy() | ||
os.environ["MASTER_ADDR"] = "localhost" | ||
os.environ["MASTER_PORT"] = str(find_free_network_port()) | ||
os.environ["RANK"] = "0" | ||
os.environ["WORLD_SIZE"] = "1" | ||
dist.init_process_group("gloo") | ||
try: | ||
yield | ||
finally: | ||
dist.destroy_process_group() | ||
os.environ.clear() | ||
os.environ.update(orig_environ) |
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.
Uh oh!
There was an error while loading. Please reload this page.