-
Notifications
You must be signed in to change notification settings - Fork 80
Symmetric memory pytorch backends #6023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
14fd212
5646c03
14816aa
6996d05
49d669c
8962475
62c6945
67181c8
eea57d8
a9ddffd
f9cac71
8e62ccc
1be0134
3596301
9b05915
6147139
b5a2418
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #!/bin/bash | ||
|
|
||
| export CC=clang-20 | ||
| export CXX=clang++-20 | ||
| export CUDAHOSTCXX=/usr/bin/clang++-20 | ||
| export LDFLAGS="-fuse-ld=mold" | ||
|
|
||
| export NVFUSER_BUILD_ENABLE_PCH | ||
|
|
||
| export UCC_HOME="/opt/hpcx/ucc" | ||
| export UCC_DIR="/opt/hpcx/ucc/lib/cmake/ucc" | ||
| export UCX_HOME="/opt/hpcx/ucx" | ||
| export UCX_DIR="/opt/hpcx/ucx/lib/cmake/ucx" | ||
|
|
||
| # export TORCH_CUDA_ARCH_LIST="9.0" | ||
|
|
||
| export NVFUSER_BUILD_WITH_UCC=1 | ||
| export NVFUSER_BUILD_INSTALL_DIR=$BUILD_DIRECTORY/nvfuser | ||
| export NVFUSER_BUILD_DIR=$BUILD_DIRECTORY | ||
|
|
||
| # Enable debug mode, leave empty for non-debug compilation | ||
| export NVFUSER_BUILD_BUILD_TYPE=Debug | ||
| export RUN_CMAKE="" | ||
|
|
||
| pip install -v -e ./python --no-build-isolation |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,13 @@ | |||||||||||||||||||||||||||||||||
| #include <numeric> | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #ifdef NVFUSER_DISTRIBUTED | ||||||||||||||||||||||||||||||||||
| #if NVFUSER_CAN_REGISTER_C10D_PROCESS_GROUP | ||||||||||||||||||||||||||||||||||
| #include <torch/csrc/distributed/c10d/GroupRegistry.hpp> | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
| #include <torch/csrc/distributed/c10d/PrefixStore.hpp> | ||||||||||||||||||||||||||||||||||
| #if NVFUSER_CAN_REGISTER_C10D_PROCESS_GROUP | ||||||||||||||||||||||||||||||||||
| #include <torch/csrc/distributed/c10d/ProcessGroup.hpp> | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
| #include <torch/csrc/distributed/c10d/exception.h> | ||||||||||||||||||||||||||||||||||
| #ifdef USE_C10D_NCCL | ||||||||||||||||||||||||||||||||||
| #include <torch/csrc/distributed/c10d/ProcessGroupNCCL.hpp> | ||||||||||||||||||||||||||||||||||
|
|
@@ -362,6 +368,12 @@ void Communicator::cleanup() { | |||||||||||||||||||||||||||||||||
| pg_nccl->shutdown(); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
| #if NVFUSER_CAN_REGISTER_C10D_PROCESS_GROUP | ||||||||||||||||||||||||||||||||||
| for (const auto& entry : process_groups_) { | ||||||||||||||||||||||||||||||||||
| c10d::unregister_process_group(entry.first); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| process_groups_.clear(); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+370
to
+373
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(The surrounding |
||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
| backends_.clear(); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -402,6 +414,28 @@ c10d::Backend* Communicator::getBackendForTeam( | |||||||||||||||||||||||||||||||||
| }(); | ||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||
| backends_[team_key] = nullptr; | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
| #if NVFUSER_CAN_REGISTER_C10D_PROCESS_GROUP | ||||||||||||||||||||||||||||||||||
| std::optional<c10d::ProcessGroup::BackendType> pg_backend = | ||||||||||||||||||||||||||||||||||
| (b == CommunicatorBackend::kNccl) | ||||||||||||||||||||||||||||||||||
| ? std::optional<c10d::ProcessGroup::BackendType>( | ||||||||||||||||||||||||||||||||||
| c10d::ProcessGroup::BackendType::NCCL) | ||||||||||||||||||||||||||||||||||
| : std::nullopt; | ||||||||||||||||||||||||||||||||||
| if (backends_[team_key] != nullptr && pg_backend.has_value()) { | ||||||||||||||||||||||||||||||||||
| auto rank_it = std::find(team.begin(), team.end(), deviceId()); | ||||||||||||||||||||||||||||||||||
| RankType team_rank = std::distance(team.begin(), rank_it); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| auto pg = c10::make_intrusive<c10d::ProcessGroup>( | ||||||||||||||||||||||||||||||||||
| c10::make_intrusive<c10d::PrefixStore>(team_key, store_), | ||||||||||||||||||||||||||||||||||
| team_rank, | ||||||||||||||||||||||||||||||||||
| static_cast<int>(team.size())); | ||||||||||||||||||||||||||||||||||
| pg->setBackend(c10::DeviceType::CUDA, *pg_backend, backends_[team_key]); | ||||||||||||||||||||||||||||||||||
| pg->setDefaultBackend(*pg_backend); | ||||||||||||||||||||||||||||||||||
| pg->setGroupName(team_key); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| c10d::register_process_group(team_key, pg); | ||||||||||||||||||||||||||||||||||
| process_groups_[team_key] = std::move(pg); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return backends_.at(team_key).get(); | ||||||||||||||||||||||||||||||||||
|
|
@@ -424,4 +458,13 @@ void Communicator::barrier(std::optional<CommunicatorBackend> backend) { | |||||||||||||||||||||||||||||||||
| getWorld(backend)->barrier(options)->wait(); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| } // namespace nvfuser | ||||||||||||||||||||||||||||||||||
| std::string Communicator::getSymmMemGroupKey( | ||||||||||||||||||||||||||||||||||
| std::optional<CommunicatorBackend> backend) { | ||||||||||||||||||||||||||||||||||
| std::vector<RankType> all_ranks(size_); | ||||||||||||||||||||||||||||||||||
| std::iota(all_ranks.begin(), all_ranks.end(), 0); | ||||||||||||||||||||||||||||||||||
| CommunicatorBackend b = backend.value_or(default_backend_); | ||||||||||||||||||||||||||||||||||
| (void)getBackendForTeam(all_ranks, b); | ||||||||||||||||||||||||||||||||||
| return getTeamKey(all_ranks, b); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+458
to
+465
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The function body uses column-0 indentation, inconsistent with every other member function in this file. All statements should be indented at the standard 2-space level. Additionally, the file is missing a trailing newline (shown by
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| } // namespace nvfuser | ||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,19 @@ | |
| #include <ATen/core/ivalue.h> | ||
| #include <c10/util/intrusive_ptr.h> | ||
|
|
||
| #if defined(NVFUSER_DISTRIBUTED) && \ | ||
| __has_include(<torch/csrc/distributed/c10d/GroupRegistry.hpp>) && \ | ||
|
||
| __has_include(<torch/csrc/distributed/c10d/ProcessGroup.hpp>) | ||
| #define NVFUSER_CAN_REGISTER_C10D_PROCESS_GROUP 1 | ||
| #else | ||
| #define NVFUSER_CAN_REGISTER_C10D_PROCESS_GROUP 0 | ||
| #endif | ||
|
|
||
| #ifdef NVFUSER_DISTRIBUTED | ||
| #include <torch/csrc/distributed/c10d/Backend.hpp> | ||
| #if NVFUSER_CAN_REGISTER_C10D_PROCESS_GROUP | ||
| #include <torch/csrc/distributed/c10d/ProcessGroup.hpp> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this header should always be present, no? |
||
| #endif | ||
| #include <torch/csrc/distributed/c10d/TCPStore.hpp> | ||
| #include <torch/csrc/distributed/c10d/Work.hpp> | ||
| #else | ||
|
|
@@ -110,6 +121,10 @@ class NVF_API Communicator { | |
| c10d::Backend* getWorld( | ||
| std::optional<CommunicatorBackend> backend = std::nullopt); | ||
|
|
||
| // Returns the world process-group name for the given backend. | ||
| std::string getSymmMemGroupKey( | ||
| std::optional<CommunicatorBackend> backend = std::nullopt); | ||
|
|
||
| // returns if a backend is available for creation | ||
| bool isBackendAvailable(CommunicatorBackend backend) const { | ||
| if (backend == CommunicatorBackend::kUcc) { | ||
|
|
@@ -153,6 +168,11 @@ class NVF_API Communicator { | |
| c10::intrusive_ptr<c10d::TCPStore> store_; | ||
| // cache for the created backends. The keys are strings generated from Teams | ||
| std::unordered_map<std::string, c10::intrusive_ptr<c10d::Backend>> backends_; | ||
| #if NVFUSER_CAN_REGISTER_C10D_PROCESS_GROUP | ||
| // c10d process-group wrappers registered for symmetric-memory rendezvous. | ||
| std::unordered_map<std::string, c10::intrusive_ptr<c10d::ProcessGroup>> | ||
| process_groups_; | ||
|
Comment on lines
+161
to
+164
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The same issue propagates into
The // communicator.h — wrap the new field:
#ifdef NVFUSER_DISTRIBUTED
std::unordered_map<std::string, c10::intrusive_ptr<c10d::ProcessGroup>>
process_groups_;
#endifAnd similarly guard the |
||
| #endif | ||
| }; | ||
|
|
||
| } // namespace nvfuser | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this file