Add kernel based alltoallv and cuda backend for MoE dispatch and combine#5863
Open
samnordmann wants to merge 1 commit intodispatch_combine/stubfrom
Open
Add kernel based alltoallv and cuda backend for MoE dispatch and combine#5863samnordmann wants to merge 1 commit intodispatch_combine/stubfrom
samnordmann wants to merge 1 commit intodispatch_combine/stubfrom
Conversation
Collaborator
Author
|
!test |
Contributor
Greptile SummaryThis PR adds a kernel-based alltoallv implementation and CUDA backend support for MoE dispatch/combine operations. The implementation introduces a custom CUDA kernel ( Key changes:
Issues found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Application
participant Dispatch as doMoEDispatch
participant Combine as doMoECombine
participant Metadata as prepareAlltoallvMetadata
participant Kernel as launchAlltoallvKernel
participant SymTensor as SymmetricTensor
participant Barrier as alltoallvBarrier
App->>Dispatch: x, topk_idx, topk_weights, is_token_in_rank
Note over Dispatch: Sort tokens by destination rank
Dispatch->>Dispatch: Reorder x, topk_idx, topk_weights by rank
alt Backend == NCCL
Dispatch->>Dispatch: Use ProcessGroup alltoall_base
else Backend == CUDA
Dispatch->>Metadata: prepareAlltoallvMetadata(n_tokens_to_rank)
Note over Metadata: Exchange counts via TCPStore<br/>Compute offsets and metadata
Metadata-->>Dispatch: AlltoallvMetadata
Dispatch->>SymTensor: Allocate symmetric send/recv buffers
SymTensor-->>Dispatch: Send/recv tensor handles
Dispatch->>SymTensor: setupRemoteHandles() for each buffer
Note over SymTensor: Exchange IPC handles across ranks
loop For each payload (x, topk_idx, topk_weights, src_idx, src_rank)
Dispatch->>Kernel: launchAlltoallvKernel(send, recv_ptrs, metadata)
Note over Kernel: CUDA kernel copies data<br/>from send to recv buffers<br/>across all ranks
end
Dispatch->>Barrier: alltoallvBarrier()
Note over Barrier: Synchronize all ranks
end
Note over Dispatch: Reorder by expert ID locally
Dispatch-->>App: recv_x, recv_topk_idx, recv_topk_weights, recv_src_idx, recv_src_rank
Note over App: ... Expert computation happens here ...
App->>Combine: x, topk_weights, src_idx, src_rank, n_tokens_to/from_rank
Note over Combine: Sort by source rank
alt Backend == NCCL
Combine->>Combine: Use ProcessGroup alltoall_base
else Backend == CUDA
Combine->>Metadata: prepareAlltoallvMetadata(n_tokens_from_rank)
Metadata-->>Combine: AlltoallvMetadata
Combine->>SymTensor: Allocate symmetric buffers
Combine->>SymTensor: setupRemoteHandles()
loop For each payload (x, topk_weights, src_idx)
Combine->>Kernel: launchAlltoallvKernel(send, recv_ptrs, metadata)
end
Combine->>Barrier: alltoallvBarrier()
end
Note over Combine: Scatter by original token index
Combine-->>App: combined_x, combined_topk_weights
|
Comment on lines
+36
to
+38
| if (!communicator_->isBackendAvailable(CommunicatorBackend::kNccl)) { | ||
| GTEST_SKIP() << "Backend " << backend << " not available."; | ||
| } |
Contributor
There was a problem hiding this comment.
logic: checking wrong backend constant - should check backend parameter, not hardcoded kNccl
Suggested change
| if (!communicator_->isBackendAvailable(CommunicatorBackend::kNccl)) { | |
| GTEST_SKIP() << "Backend " << backend << " not available."; | |
| } | |
| if (!communicator_->isBackendAvailable(backend)) { | |
| GTEST_SKIP() << "Backend " << backend << " not available."; | |
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.