[nccl-ep] Add ncclEpUpdateHandle to rebind topk_idx without reallocating#2085
Open
kwen2501 wants to merge 3 commits intoNVIDIA:masterfrom
Open
[nccl-ep] Add ncclEpUpdateHandle to rebind topk_idx without reallocating#2085kwen2501 wants to merge 3 commits intoNVIDIA:masterfrom
kwen2501 wants to merge 3 commits intoNVIDIA:masterfrom
Conversation
…ndle` The `ncclAllGather` and `call_metadata_preprocessing` are on the same CUDA stream, so intra-stream ordering already guarantees the allgather completes before the preprocessing kernel launches. Additionally, it seems nowhere else would use the allgather result `global_routing_map`. Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Ke Wen <kwen@nvidia.com>
ncclEpCreateHandle allocates ~8 GPU buffers whose sizes depend only on group-level constants, yet the current API forces a full destroy+create cycle whenever topk_idx changes between iterations. This causes unnecessary cudaMalloc/cudaFree traffic (both device-synchronizing). Add ncclEpUpdateHandle that resets and re-runs only the topk_idx-dependent computation (convert_topk_to_routing_map, ncclAllGather, and call_metadata_preprocessing) on an existing handle. Refactor ncclEpCreateHandle to delegate to ncclEpUpdateHandle for the computation phase, eliminating code duplication. Also fix dense_prob_buffer sizing to use max_tokens_per_rank instead of num_tokens so the buffer is large enough for reuse across different token counts. Co-authored-by: Claude <noreply@anthropic.com> RFC: NVIDIA#2084 Signed-off-by: Ke Wen <kwen@nvidia.com> Made-with: Cursor
71a21ec to
df56902
Compare
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.
Summary
ncclEpUpdateHandleAPI that rebindstopk_idxon an existing handle without reallocating GPU buffers. This avoids unnecessarycudaMalloc/cudaFreetraffic (both device-synchronizing) in MoE hot loops where only the routing changes between iterations.ncclEpCreateHandleto delegate the computation phase toncclEpUpdateHandle, eliminating code duplication.dense_prob_buffersizing to usemax_tokens_per_rankinstead ofnum_tokensso the buffer is reusable across different token counts.RFC: #2084
API
Usage
Changes
nccl_ep.h: AddncclEpUpdateHandledeclarationnccl_ep.cc: AddncclEpUpdateHandleimplementation (resets buffers + re-runs convert/allgather/preprocess). RefactorncclEpCreateHandleto be allocation-only, delegating computation toncclEpUpdateHandle.nccl_wrapper.py: Add ctypes binding forncclEpUpdateHandleCo-authored-by: Claude noreply@anthropic.com
Made with Cursor