forked from huggingface/optimum-habana
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…299) * TP reference - ibm foundation-model-stack * Code cleanup -removed unused code --------- Co-authored-by: Kalyan <kkumar@habana.ai>
- Loading branch information
Showing
9 changed files
with
1,105 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
from .distributed_runner import DistributedRunner | ||
from .fast_ddp import all_reduce_gradients | ||
import os | ||
import torch | ||
|
||
def rank_and_world(group=None): | ||
""" | ||
Returns (rank, world_size) from the optionally-specified group, otherwise | ||
from the default group, or if non-distributed just returns (0, 1) | ||
""" | ||
if torch.distributed.is_initialized() and group is None: | ||
group = torch.distributed.GroupMember.WORLD | ||
|
||
if group is None: | ||
world_size = 1 | ||
rank = 0 | ||
else: | ||
world_size = group.size() | ||
rank = group.rank() | ||
|
||
return rank, world_size | ||
|
||
|
||
_LOCAL_RANK = int(os.getenv("LOCAL_RANK", 0)) | ||
|
||
|
||
def local_rank(): | ||
return _LOCAL_RANK |
Oops, something went wrong.