Skip to content
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

[fix] Better support for rank_zero_only setting for SLURM and torchelastic #6802

Merged
merged 22 commits into from
Apr 7, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pytorch_lightning/utilities/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,18 @@ def wrapped_fn(*args, **kwargs):
return wrapped_fn


# TODO: this should be part of the cluster environment
def _get_local_rank() -> int:
local_rank_keys = ('LOCAL_RANK', 'SLURM_LOCALID')
ananthsub marked this conversation as resolved.
Show resolved Hide resolved
for key in local_rank_keys:
rank = os.environ.get(key)
if rank is not None:
return int(rank)
return 0


# add the attribute to the function but don't overwrite in case Trainer has already set it
rank_zero_only.rank = getattr(rank_zero_only, 'rank', int(os.environ.get('LOCAL_RANK', 0)))
rank_zero_only.rank = getattr(rank_zero_only, 'rank', _get_local_rank())


def _warn(*args, **kwargs):
Expand Down