Repository navigation
Various cleanups around distributed setup - #645
Conversation
[ghstack-poisoned]
| # TODO: Can we find a cleaner way? | ||
| torch.distributed.barrier() | ||
| torch.distributed.barrier(device_ids=[torch.cuda.current_device()]) | ||
| torch.cuda.synchronize() |
There was a problem hiding this comment.
If we want to avoid timeout-related issues, I think we should block the CPU until all ranks finish the barrier? (I assume that the timeout starts counting with respect to CPU time)
There was a problem hiding this comment.
I added this barrier trying to do a GPU sync to avoid timeout. However, I later found that the barrier itself can cause timeout if things before are out of sync. So essentially this code doesn't help. I would suggest we remove both.
| # to mitigate the memory issue that collectives using | ||
| # async_op=True hold memory longer than they should | ||
| # such as those in tensor parallelism | ||
| os.environ["TORCH_NCCL_AVOID_RECORD_STREAMS"] = "1" |
There was a problem hiding this comment.
This env var is read at PGNCCL construction time. If we set it after init_process_group, then technically the default PG does not see this env var as set. This is fine for us before because TP PGs are initialized after this point.
There was a problem hiding this comment.
This is a nice catch though.
| # those may time out, before other ranks have finished with initialization done | ||
| # under the old/slow timeout. | ||
| torch.distributed.barrier() | ||
| torch.distributed.barrier(device_ids=[torch.cuda.current_device()]) |
There was a problem hiding this comment.
need to pass device_ids to barrier for 2D case or else we see:
[rank0]:2024-10-22 08:36:34,884 - root - INFO - Synchronizing and adjusting timeout for all ProcessGroups to 0:01:40
[rank0]:[rank0]:[W1022 08:36:34.831154637 ProcessGroupNCCL.cpp:4268] [PG ID 0 PG GUID 0 Rank 0] using GPU 0 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect. Specify device_ids in barrier() to force use of a particular device, or call init_process_group() with a device_id.
[ghstack-poisoned]
tianyu-l
left a comment
There was a problem hiding this comment.
left an inline comments, other parts look great to me
[ghstack-poisoned]
[ghstack-poisoned]
|
removed the two barriers in |
|
ugh |
[ghstack-poisoned]
ghstack-source-id: 60e9e1a Pull Request resolved: pytorch#645
ghstack-source-id: 60e9e1a Pull Request resolved: pytorch#645
Stack from ghstack (oldest at bottom):
run_llama_train.sh#643