TorchComms Integration for MSCCL++#771
Open
michael-beebe wants to merge 4 commits intomicrosoft:mainfrom
Open
Conversation
- python/mscclpp_torchcomm/: TorchComms integration for MSCCL++
- CMakeLists.txt: FetchContent torchcomms, links mscclpp + PyTorch
- TorchCommMSCCLPP: backend class with init/finalize lifecycle,
algorithm selection via AlgorithmCollection, GPU event-based
async work tracking
- TorchCommMSCCLPPBootstrap: rank discovery via c10d::Store
- TorchWorkMSCCLPP: GPU event pool + async completion handles
- TorchCommMSCCLPPPy: pybind11 module + dynamic loader interface
- CMakeLists.txt: add MSCCLPP_BUILD_EXT_TORCHCOMMS option (OFF default)
- Supported: allreduce (10 native algorithms), allgather (2 algorithms)
- Uses same algorithm selector as NCCL extension
- Links mscclpp shared lib (not static) to avoid dual-singleton crashes
- test_correctness.py: allreduce/allgather with --sweep mode for multi-size/dtype coverage, in-place and repeated variants - test_sizes.py: message size sweep from 1 element to 32MB - test_error_handling.py: unsupported ops, invalid reduce ops, metadata - test_training_loop.py: simulated multi-iteration training loop - test_multicomm.py: multiple communicators (known limitation) - test_user_algorithms.py: DSL algorithm registration via builder
- bench_torchcomms.py: allreduce/allgather benchmark with CUDA event timing, curated sizes per native algorithm, JSON output - bench_report.py: generates report + latency/bandwidth figures with algorithm region annotations - run_benchmarks.sh: orchestrator script
- docs/quickstart.md: build instructions, usage example, supported collectives table, environment variables, test/benchmark commands - Consistent with existing doc style (dollar prompts, MSCCLPP_BUILD var)
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
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.
What This PR Does
This PR adds TorchComms support to MSCCL++, allowing PyTorch users to use MSCCL++ collectives through the TorchComms API with a single line:
This is valuable because it gives PyTorch training frameworks (torchtitan, FSDP2, etc.) a clean way to use MSCCL++ for high-performance collectives without LD_PRELOAD hacks or custom CUDA kernel code. Users can run MSCCL++ for the hot-path collectives (allreduce, allgather) and NCCL for everything else — mixed-backend training with no code changes.
Architecture
Communicator Lifecycle
When a user calls
torchcomms.new_comm("mscclpp", device), TorchComms dlopen's our_comms_mscclpp.*.somodule and callsinit(), which:UniqueIdthrough c10d::Store (rank 0 generates, others read), creates the MSCCL++Communicatorwith aTcpBootstrapGpuBuffer(cuMemMap) for native algorithms that need intermediate storageAlgorithmCollectionBuilder::buildDefaultAlgorithms()which registers 12 native algorithms + 2 DSL plans, then wires up the topology-aware algorithm selectorWhat Happens When You Call a Collective
Component Diagram
The backend is a thin adapter. It does not implement any collective algorithms — it delegates entirely to MSCCL++'s
AlgorithmCollection, which selects the optimal native algorithm based on message size, topology, NVLS support, and compute capability.Files to Review
Core Backend (focus here)
TorchCommMSCCLPP.hppTorchCommMSCCLPP.cppinit()bootstraps and builds the AlgorithmCollection.executeCollective()is the central dispatch — builds aCollectiveRequest, callsselectAlgorithm(), executes. Unsupported ops throw with NCCL/RCCL guidance.TorchCommMSCCLPPBootstrap.hpp/cppUniqueId, writes to c10d::Store, other ranks read it. Same pattern as TorchComms' NCCL backend.TorchWorkMSCCLPP.hpp/cppwait()usescudaStreamWaitEventfor GPU-side sync — no CPU blocking.TorchCommMSCCLPPPy.cppDynamicLoaderInterfacefor TorchComms' dlopen discovery.CMakeLists.txt(torchcomm)Build System
CMakeLists.txt(root)MSCCLPP_BUILD_EXT_TORCHCOMMSoption (OFF by default) andadd_subdirectory()Tests, Benchmarks, Docs
Tests (6 files, ~960 lines), benchmarks (3 files, ~500 lines), and docs (quickstart.md) are straightforward and lower review priority.
Supported Collectives
Key Design Decisions
1. Thin adapter, not a reimplementation.
The backend calls
AlgorithmCollection::selectAlgorithm()andAlgorithm::execute(). It does not contain any collective kernel code. Algorithm registration, selection logic, and kernel implementations all live in MSCCL++ core.2. Same algorithm selector as the NCCL extension.
We reuse
algorithm_selector.hppfromsrc/ext/nccl/so the TorchComms path selects the same algorithms as the LD_PRELOAD NCCL shim. This avoids divergence and ensures consistent behavior.3. Shared library linking (not static).
The module links against
libmscclpp.so(notmscclpp_static.a) to avoid dual-singleton crashes.mscclpp_collectives.solinks against the shared lib, so if we statically linked, there would be two copies of singletons likeUnixSocketServer::instance().4. GpuBuffer for scratch allocation.
Scratch memory is allocated via
mscclpp::GpuBuffer(cuMemMap) instead of plaincudaMalloc. This registers POSIX file descriptors in the unix socket server, which is required for cross-rank IPC sharing. Plain cudaMalloc causes "Requested fd not found" crashes.5. Build-gated behind
MSCCLPP_BUILD_EXT_TORCHCOMMS=OFF.No impact on existing builds. TorchComms headers are fetched on-demand via CMake FetchContent only when the option is enabled.
6. GPU event pooling.
Every collective call needs 2 CUDA events (start + end) for async tracking. Creating/destroying events costs ~5-10μs each. The pool amortizes this across thousands of collective calls in a training loop.
7. User-defined algorithms via AlgorithmCollectionBuilder singleton.
Custom algorithms (DSL or native) are configured on the builder before creating the TorchComms communicator. The backend picks them up during
init(). No algorithm registration API lives on the backend itself.Limitations
Algorithm::execute()operates on contiguous buffers (one input pointer, one output pointer), so the backend implementsall_gather_singleandreduce_scatter_singlebut not the tensor-list variants. The tensor-list variants throw with guidance to use the single-tensor variant instead.RuntimeErrorwith an explicit message naming the operation and suggesting the caller use a separate NCCL/RCCL communicator. This is the expected pattern for mixed-backend training.algorithm_selector.hppfromsrc/ext/nccl/rather than sharing it through a common path. A TODO in the code notes this should be consolidated intoAlgorithmCollectionBuilderso all consumers get a default selector automatically.How to Build and Test