NeMo
NeMo copied to clipboard
Account for mpirun use case in get_rank
What does this PR do ?
Some distributed workloads can possibly be launched "manually" with mpirun -n N python ...
. I'm adapting nemo.utils.get_rank.py
module to take it into account and produce correct rank information in such cases.
Currently the below rank_example.py script (with the project pattern for setting up distributed environment) when launched with, for example, mpirun -n 2 python rank_example.py
outputs
RANKS (NeMo, PyT): (0, 0)
RANKS (NeMo, PyT): (0, 1)
while the expected output is
RANKS (NeMo, PyT): (0, 0)
RANKS (NeMo, PyT): (1, 1)
The MR fixes this.
rank_example.py:
import torch.distributed as dist
from pytorch_lightning.trainer.trainer import Trainer
from nemo.collections.nlp.parts.nlp_overrides import NLPDDPStrategy
from nemo.utils.get_rank import get_rank
trainer = Trainer(
strategy=NLPDDPStrategy(),
devices=-1,
num_nodes=1,
accelerator="gpu",
logger=False,
precision="bf16",
enable_checkpointing=False,
)
def dummy():
return
if trainer.strategy.launcher is not None:
trainer.strategy.launcher.launch(dummy, trainer=trainer)
trainer.strategy.setup_environment()
print("RANKS (NeMo, PyT):", (get_rank(), dist.get_rank()))
Collection: [ALL]
Changelog
- Fixing
is_global_rank_zero
andget_rank
helper functions in case of usingmpirun
by consideringOMPI_COMM_WORLD_RANK
env var.
Jenkins CI
To run Jenkins, a NeMo User with write access must comment jenkins
on the PR.
Before your PR is "Ready for review"
Pre checks:
- [x] Make sure you read and followed Contributor guidelines
- [ ] Did you write any new necessary tests?
- [x] Did you add or update any necessary documentation?
- [ ] Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
- [ ] Reviewer: Does the PR have correct import guards for all optional libraries?
PR Type:
- [x] Bugfix
If you haven't finished some of the above items you can still open "Draft" PR.
Who can review?
Anyone in the community is free to review the PR once the checks have passed. Contributor guidelines contains specific people who can review PRs to various areas.