Skip to content

Various cleanups around distributed setup - #645

Merged
awgu merged 5 commits into
gh/awgu/21/basefrom
gh/awgu/21/head
Oct 22, 2024
Merged

awgu merged 5 commits into
gh/awgu/21/basefrom
gh/awgu/21/head

Conversation

@awgu

@awgu awgu commented Oct 22, 2024 •

Copy link
Copy Markdown
Contributor

awgu pushed a commit that referenced this pull request Oct 22, 2024
ghstack-source-id: 607605e
Pull Request resolved: #645
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 22, 2024
Comment thread torchtitan/profiling.py Outdated
# TODO: Can we find a cleaner way?
torch.distributed.barrier()
torch.distributed.barrier(device_ids=[torch.cuda.current_device()])
torch.cuda.synchronize()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread torchtitan/utils.py
# 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"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice catch though.

Comment thread torchtitan/utils.py
# 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()])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@awgu
awgu marked this pull request as ready for review October 22, 2024 15:59

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left an inline comments, other parts look great to me

@awgu

awgu commented Oct 22, 2024

Copy link
Copy Markdown
Contributor Author

removed the two barriers in profiling.py (one for trace profiler and one for memory profiler)

@awgu
awgu requested a review from tianyu-l October 22, 2024 18:30
@awgu

awgu commented Oct 22, 2024

Copy link
Copy Markdown
Contributor Author

ugh ghstack land does not work if I landed a lower PR in the stack
have to rebase and re-run CI

@awgu
awgu merged commit d8d0576 into gh/awgu/21/base Oct 22, 2024
awgu pushed a commit that referenced this pull request Oct 22, 2024
ghstack-source-id: 60e9e1a
Pull Request resolved: #645
@awgu
awgu deleted the gh/awgu/21/head branch October 22, 2024 20:28
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
ghstack-source-id: 60e9e1a
Pull Request resolved: pytorch#645
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
ghstack-source-id: 60e9e1a
Pull Request resolved: pytorch#645
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants