Skip to content

[c10d] Add a collective time estimator for NCCL comms - #149343

Closed
fduwjj wants to merge 8 commits into
gh/fduwjj/114/basefrom
gh/fduwjj/114/head
Closed

fduwjj wants to merge 8 commits into
gh/fduwjj/114/basefrom
gh/fduwjj/114/head

Conversation

@fduwjj

@fduwjj fduwjj commented Mar 17, 2025 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

We want to upstream the feature from new nccl for users to estimate comm time.

Resolves #147753

cc @H-Huang @awgu @kwen2501 @wanchaol @fegin @wz337 @wconstab @d4l3k @c-p-i-o

@fduwjj
fduwjj requested a review from kwen2501 as a code owner March 17, 2025 20:09
@pytorch-bot

pytorch-bot Bot commented Mar 17, 2025 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/149343

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit b2c8efe with merge base 790f93d (image):

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (c10d) release notes category labels Mar 17, 2025

@kwen2501 kwen2501 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment thread torch/csrc/distributed/c10d/Backend.hpp Resolved
Not for landing and no unit test right now. Just use this PR to collective feedback to see if this is something we want to do.

cc H-Huang awgu kwen2501 wanchaol fegin wz337 wconstab d4l3k c-p-i-o

[ghstack-poisoned]
@fduwjj
fduwjj requested a review from kwen2501 March 17, 2025 23:12
Not for landing and no unit test right now. Just use this PR to collective feedback to see if this is something we want to do.

cc H-Huang awgu kwen2501 wanchaol fegin wz337 wconstab d4l3k c-p-i-o

[ghstack-poisoned]
fduwjj added a commit that referenced this pull request Mar 18, 2025
ghstack-source-id: 98ca59f
Pull Request resolved: #149343
@fduwjj fduwjj linked an issue Mar 18, 2025 that may be closed by this pull request
@fduwjj fduwjj changed the title [RFC] Add a collective time estimator for NCCL comms [c10d] Add a collective time estimator for NCCL comms Mar 18, 2025
We want to upstream the feature from new nccl for users to estimate comm time.

cc H-Huang awgu kwen2501 wanchaol fegin wz337 wconstab d4l3k c-p-i-o

[ghstack-poisoned]
Comment thread torch/distributed/distributed_c10d.py Resolved
We want to upstream the feature from new nccl for users to estimate comm time.

cc H-Huang awgu kwen2501 wanchaol fegin wz337 wconstab d4l3k c-p-i-o

[ghstack-poisoned]
@fduwjj
fduwjj requested a review from awgu March 18, 2025 20:43
@fduwjj

fduwjj commented Mar 18, 2025

Copy link
Copy Markdown
Collaborator Author

unit test passed and now it is ready for reviewing.

We want to upstream the feature from new nccl for users to estimate comm time.

cc H-Huang awgu kwen2501 wanchaol fegin wz337 wconstab d4l3k c-p-i-o

[ghstack-poisoned]
fduwjj added a commit that referenced this pull request Mar 18, 2025
ghstack-source-id: 0da4bd3
Pull Request resolved: #149343
>>> # Synchronous ops
>>> with _collective_estimator() as cm:
>>> for i in range(num_colls):
>>> dist.all_reduce(tensors[i])

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'm unclear about how this actually works.

when you run all_reduce inside CE context, does it actually perform the communication?

I assume it does not, because if it did then it would really be a profiler not an estimator. But its weird to hook the estimation into the real runtime APIs, which requires (1) users init a process group (it doesn't specify whether a fake PG is acceptable or real one is required), (2) users pass actual tensors in, but then these do not get correct data? Should these be fake tensors? or it doesn't matter?

@kwen2501 kwen2501 Mar 19, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(1) is required because only with a real communicator can we do accurate estimation. The communicator internally has knowledge about the links it runs on (e.g. intra-node or inter-node, whether the links are NVLink or PCI-e or IB).

(2) is similar to CUDA Graph capturing -- in the capturing context, nothing is actually run. But yeah, we should document the expectation well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That said, I don't know if Inductor uses real tensor or fake tensor for scheduling, we should try to support whatever Inductor's using.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I can add a TODO for (2) to support what inductor is using as well. Any customer from the compiler side is interested to try this tool?

@kwen2501 kwen2501 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Thanks

Comment thread torch/distributed/distributed_c10d.py Resolved
>>> # Synchronous ops
>>> with _collective_estimator() as cm:
>>> for i in range(num_colls):
>>> dist.all_reduce(tensors[i])

@kwen2501 kwen2501 Mar 19, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(1) is required because only with a real communicator can we do accurate estimation. The communicator internally has knowledge about the links it runs on (e.g. intra-node or inter-node, whether the links are NVLink or PCI-e or IB).

(2) is similar to CUDA Graph capturing -- in the capturing context, nothing is actually run. But yeah, we should document the expectation well.

Comment thread torch/distributed/__init__.py Resolved
Comment thread torch/distributed/distributed_c10d.py Resolved
We want to upstream the feature from new nccl for users to estimate comm time.

cc H-Huang awgu kwen2501 wanchaol fegin wz337 wconstab d4l3k c-p-i-o

[ghstack-poisoned]
We want to upstream the feature from new nccl for users to estimate comm time.

cc H-Huang awgu kwen2501 wanchaol fegin wz337 wconstab d4l3k c-p-i-o

[ghstack-poisoned]
fduwjj added a commit that referenced this pull request Mar 19, 2025
ghstack-source-id: 6b17853
Pull Request resolved: #149343
@fduwjj

fduwjj commented Mar 19, 2025

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 19, 2025
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
github-actions Bot deleted the gh/fduwjj/114/head branch April 22, 2025 02:15
ruisizhang123 added a commit that referenced this pull request Aug 11, 2025
…e estimation"

Computation Estimation:

-  BaseSchedulerNode/FusedSchedulerNode: Get the generated triton code and use [do_bench](https://github.com/pytorch/pytorch/blob/85111cd165f108ffabb4a90083d59d7a867ebd9f/torch/_inductor/codegen/triton.py#L4234) mode to benchmark the runtime.
- ExternKernelSchedulerNode: Realize faketensor into realtensor, and log the cuda event time.

Communication Estimation:

- NCCL estimation: estimate communication using NCCL's [ncclGroupSimulateEnd API](https://docs.nvidia.com/deeplearning/nccl/user-guide/docs/api/group.html?highlight=ncclsiminfo_t) from this [PR](#149343).
- Profiling-based estimation: Realize faketensor into realtensor, and log the cuda event time for performing the communication.

Note: By default, I use Profiling-based estimation to estimate communication. The reason is it gives better estimation performance in multi-node settings.

At the end, it aggregates the estimated runtime from all ranks, and take the median runtime as the final estimated results.  




cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
ruisizhang123 added a commit that referenced this pull request Aug 11, 2025
Computation Estimation:

-  BaseSchedulerNode/FusedSchedulerNode: Get the generated triton code and use [do_bench](https://github.com/pytorch/pytorch/blob/85111cd165f108ffabb4a90083d59d7a867ebd9f/torch/_inductor/codegen/triton.py#L4234) mode to benchmark the runtime.
- ExternKernelSchedulerNode: Realize faketensor into realtensor, and log the cuda event time.

Communication Estimation:

- NCCL estimation: estimate communication using NCCL's [ncclGroupSimulateEnd API](https://docs.nvidia.com/deeplearning/nccl/user-guide/docs/api/group.html?highlight=ncclsiminfo_t) from this [PR](#149343).
- Profiling-based estimation: Realize faketensor into realtensor, and log the cuda event time for performing the communication.

Note: By default, I use Profiling-based estimation to estimate communication. The reason is it gives better estimation performance in multi-node settings.

At the end, it aggregates the estimated runtime from all ranks, and take the median runtime as the final estimated results.  




cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (c10d) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC][c10d] Expose NCCL API for runtime estimation

5 participants