-
-
Notifications
You must be signed in to change notification settings - Fork 655
warning if current device index is lower than current local rank #1335
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
vfdev-5
merged 7 commits into
pytorch:device-index-warning
from
HelioStrike:device-index-warning
Oct 7, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
726041a
warning if current device index is lower than current local rank
HelioStrike 5677f45
Merge branch 'master' of github.com:pytorch/ignite into device-index-…
vfdev-5 029197d
Updated code and tests
vfdev-5 c98ac5b
Merge branch 'master' into device-index-warning
vfdev-5 d605e70
Fixed formatting
vfdev-5 354dfca
Updated code and tests for horovod
vfdev-5 c3a2db5
Updated tests
vfdev-5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,13 @@ def _init_from_context(self) -> None: | |
self._setup_attrs() | ||
|
||
def _compute_nproc_per_node(self) -> int: | ||
tensor = torch.tensor([self.get_local_rank() + 1]).to(self.device()) | ||
print("_compute_nproc_per_node") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debug print to remove ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks ! |
||
local_rank = self.get_local_rank() | ||
device = torch.device("cpu") | ||
if self.backend() == dist.Backend.NCCL: | ||
# we manually set cuda device to local rank in order to avoid a hang on all_reduce | ||
device = torch.device("cuda:{}".format(local_rank)) | ||
tensor = torch.tensor([self.get_local_rank() + 1]).to(device) | ||
dist.all_reduce(tensor, op=dist.ReduceOp.MAX) | ||
return int(tensor.item()) | ||
|
||
|
@@ -220,6 +226,11 @@ def get_node_rank(self) -> int: | |
def device(self) -> torch.device: | ||
if self.backend() == dist.Backend.NCCL: | ||
index = torch.cuda.current_device() | ||
if index < self.get_local_rank(): | ||
vfdev-5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
warnings.warn( | ||
"Current device index is less than current local rank. " | ||
"Please, make sure to call torch.cuda.set_device(local_rank)." | ||
) | ||
return torch.device("cuda:{}".format(index)) | ||
return torch.device("cpu") | ||
|
||
|
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
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.