-
Notifications
You must be signed in to change notification settings - Fork 374
[comm] TRT-LLM's Multi-Node NVLink All-Reduce Kernel #1213
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
Merged
+1,280
β1
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd3009c
We add TRT-LLM's Multi-Node NVLink All-Reduce Kernel
nvmbreughe 8667f65
Addressed suggestions from Gemini Reviewer
nvmbreughe 5d3e4ce
Reran pre-commit
nvmbreughe abfe592
trigger-ci-with-new-docker-image
yzh119 3e1441d
Segfault fix and addressed reviewer comments
nvmbreughe 70ee773
More reviewer suggestions
nvmbreughe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "flashinfer/comm/trtllm_mnnvl_allreduce.cuh" | ||
#include "pytorch_extension_utils.h" | ||
|
||
using namespace flashinfer::trtllm_mnnvl_allreduce; | ||
|
||
#define DISPATCH_FLOATING_TYPES_FOR_MNNVL_ALLREDUCE(scalar_type, c_type, ...) \ | ||
[&] { \ | ||
switch (scalar_type) { \ | ||
case at::ScalarType::Float: { \ | ||
using c_type = float; \ | ||
return __VA_ARGS__(); \ | ||
} \ | ||
case at::ScalarType::Half: { \ | ||
using c_type = half; \ | ||
return __VA_ARGS__(); \ | ||
} \ | ||
case at::ScalarType::BFloat16: { \ | ||
using c_type = __nv_bfloat16; \ | ||
return __VA_ARGS__(); \ | ||
} \ | ||
default: \ | ||
TORCH_CHECK(false, "Unsupported dtype in DISPATCH_FLOATING_TYPES_FOR_MNNVL_ALLREDUCE: ", \ | ||
scalar_type); \ | ||
} \ | ||
}() | ||
|
||
void trtllm_mnnvl_all_reduce(at::Tensor& in, at::Tensor& out, int64_t multicast_buffer_ptr, | ||
int64_t buffer_ptrs_dev, int64_t buffer_M, | ||
at::Tensor& buffer_flags_mnnvl, int64_t nranks, int64_t rank, | ||
bool wait_for_results, bool launch_with_pdl) { | ||
const c10::cuda::OptionalCUDAGuard device_guard(in.device()); | ||
auto stream = at::cuda::getCurrentCUDAStream(); | ||
|
||
DISPATCH_FLOATING_TYPES_FOR_MNNVL_ALLREDUCE(in.scalar_type(), c_type, [&] { | ||
// Extract parameters from tensors | ||
int64_t num_tokens = in.size(0); | ||
int64_t token_dim = in.size(1); | ||
|
||
// Validate input parameters | ||
TORCH_CHECK(nranks >= 2 && nranks <= 64, "nranks must be between 2 and 64, got ", nranks); | ||
TORCH_CHECK(rank >= 0 && rank < nranks, "rank must be between 0 and nranks-1, got ", rank); | ||
|
||
// Create the parameters struct | ||
AllReduceParams<c_type> params; | ||
params.nranks = nranks; | ||
params.rank = rank; | ||
params.buffer_M = buffer_M; | ||
params.num_tokens = num_tokens; | ||
params.token_dim = token_dim; | ||
params.buffer_ptrs_dev = reinterpret_cast<void**>(buffer_ptrs_dev); | ||
params.multicast_ptr = reinterpret_cast<void*>(multicast_buffer_ptr); | ||
params.buffer_flags = buffer_flags_mnnvl.data_ptr(); | ||
params.wait_for_results = wait_for_results; | ||
params.launch_with_pdl = launch_with_pdl; | ||
params.input = in.data_ptr(); | ||
params.output = out.data_ptr(); | ||
params.stream = stream.stream(); | ||
|
||
auto status = twoshot_allreduce_dispatch_world_size<c_type>(params); | ||
TORCH_CHECK(status == cudaSuccess, | ||
"twoshot_allreduce_dispatch_world_size failed with error code ", | ||
cudaGetErrorString(status)); | ||
}); | ||
} | ||
|
||
TORCH_LIBRARY_FRAGMENT(TORCH_EXTENSION_NAME, m) { | ||
m.def("trtllm_mnnvl_all_reduce", &trtllm_mnnvl_all_reduce); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we include mnnvl comm in aot build?
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.
In the past @yzh119 suggested not to do this yet. Maybe we can do it as part of another PR?
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.
Not necessary at this moment.