Unable to create DiskSaver when program launched with torch.distributed.launcher
See original GitHub issueš Bug description
As mentioned in this issue in MONAI, I tried to run this tutorial code with torch.distributed.launcher
. However, the program froze at instantiating the CheckpointSaver. The reason was that DiskSaver
of ignite
cannot be created when the program is launched with torch.distributed.launcher
(I am using SLURM). I also noticed that it might be caused by calling get_rank()
in the one_rank_only
decorator, which is used in the definition of DiskSaver
: https://github.com/pytorch/ignite/blob/d16d15efbbbfc476702e91f3ab2bc757b839be26/ignite/distributed/utils.py#L595
I also did a simple experiment to verify this. I launched the following script with srun python -m torch.distributed.launcher --nproc_per_node=4 --nnodes=1 script.py
, and found that the program froze at creating the DiskSaver
.
import torch.distributed as dist
from ignite.handlers import DiskSaver
from argparse import ArgumentParser
def create_disk_saver(args):
dist.init_process_group(backend='nccl', init_method='env://')
if dist.get_rank() == 0:
print('building DiskSaver')
disk_saver = DiskSaver(dirname='./runs/')
print('DiskSaver built')
dist.destroy_process_group()
def main():
parser = ArgumentParser()
parser.add_argument('--local_rank', type=int)
args = parser.parse_args()
create_disk_saver(args)
if __name__ == '__main__':
main()
I would be much appreciated if you could fix this. I prefer launching the program with torch.distributed.launcher
to ignite.distributed.Parallel
context manager, as it has less issues with the SLURM env.
Environment
- PyTorch Version (e.g., 1.4): 1.8
- Ignite Version (e.g., 0.3.0): 0.4.4
- OS (e.g., Linux): Linux
- How you installed Ignite (
conda
,pip
, source): pip - Python version: 3.8
- Any other relevant information:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:27 (21 by maintainers)
@sandylaker I tried a few runs on the cluster of my company.
1 - using
srun
andtorch.launch.distributed
withoutignite.distributed.Parallel
script, README
NOTE : I removed some mandatory options like
-J
,-p
,--mem
, etc. related to the own configuration of my cluster.2 - using
srun
withouttorch.launch.distributed
andignite.distributed.Parallel
script, README
3 - using
srun
andtorch.launch.distributed
withignite.distributed.Parallel
script, README
One script, both usages.
On a computing node, use
torch.launch.distributed
On the frontend, use
srun
(orsbatch
)HTH
@vfdev-5 Yes, Thatās what I mentioned looking the code a few days ago. However you explained it better š
The parallel / sequential sections remain a tricky (and classical) thing in parallel computing. Having to manage the 2 behaviours (collective call similar to reduction or guard per processor) makes the codes more complicated. An idea would be to have only handlers defined in collective, we avoid the if clauses and itās simpler.
Although I donāt know if the bug label should be added to this issue.
Last thing, I didnāt understand how
idist.sync()
would help, it doesnāt remove the collective code section ?