Repository navigation
[PG][5/N] Generalize device collectives and implement AllGather - #4791
Draft
caozhanhao wants to merge 1 commit into
Draft
caozhanhao wants to merge 1 commit into
caozhanhao wants to merge 1 commit into
Conversation
This was referenced Oct 20, 2026
This was referenced Nov 5, 2026
caozhanhao
force-pushed
the
czh/pg-device-collectives-pr5
branch
from
November 9, 2026 13:32
48f65da to
7edbd09
Compare
caozhanhao
changed the base branch from
czh/pg-device-collectives-pr4
to
czh/pg-device-collectives-pr4-split
November 9, 2026 13:35
caozhanhao
force-pushed
the
czh/pg-device-collectives-pr5
branch
from
November 9, 2026 14:14
7edbd09 to
0dad5f6
Compare
yuechen-sys
force-pushed
the
czh/pg-device-collectives-pr5
branch
from
November 10, 2026 07:37
0dad5f6 to
ac2d7dc
Compare
Signed-off-by: caozhanhao <cao2013zh@163.com>
caozhanhao
force-pushed
the
czh/pg-device-collectives-pr5
branch
from
November 14, 2026 13:57
ac2d7dc to
9f5b766
Compare
This branch has not been deployed
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.
Description
Part of #3483 (Phase 3), stacked on #5364.
Previously, the device collective framework was structured around two algorithms, two protocols, and a single collective operation (AllReduce). Algorithm selection, control endpoint distribution, and GPU execution state were tightly bound to this AllReduce-centric setup.
This PR refactors and generalises the framework to dispatch arbitrary collective operations. PR 6/N will build upon this foundation to expand the remaining collective operations and reduction operators.
User-visible behavior
GpuCollectiveBackend::New) now supportsall_gatheralongsideall_reduce.MOONCAKE_PG_COLLECTIVE_ALGORITHMenvironment variable.Algorithm policy syntax and semantics
The policy string uses the following grammar:
;, and per-operation rules by,.@max_bytesspecifies an inclusive upper bound on the message size (in bytes). If omitted, the rule applies without an upper bound.KiB,MiB, andGiBsuffixes (e.g.,512KiB,1MiB)."auto"uses the Coordinator's automatic capability-based policy.[0, largest max_bytes]. Sizes above that bound, as well as unspecified operations, retain the default automatic policy.Examples
unset,"", or"auto":The Coordinator chooses algorithms automatically based on advertised route capabilities.
"allreduce:ring":Forces Ring for AllReduce across all sizes. AllGather keeps its automatic policy.
"allreduce:oneshot@512KiB":Uses OneShot for AllReduce inputs
"allreduce:ring;allgather:ring":Forces Ring for both AllReduce and AllGather across all input sizes.
"allreduce:oneshot@512KiB,ring;allgather:ring":AllReduce uses OneShot for inputs
"allreduce:ring@1048576":Forces Ring for AllReduce inputs
Framework generalization and architecture
To support more operations, algorithms, and protocols cleanly, this PR introduces several abstractions:
AlgorithmProviderandProtocolProviderProtocolProvidermanages transport resources and communication state (e.g.,SimpleProtocol,LLProtocol). It provides communication primitives and exposes a serializedProtocolEndpointfor group negotiation.AlgorithmProviderdefines collective algorithm and GPU kernel launch logic (e.g.,RingAlgorithm,OneShotAlgorithm). Each algorithm references aProtocolProviderwithout owning it, declaring the set ofOpTypeoperations it supports (supports(operation)).AlgorithmProvider, and multiple algorithms can share oneProtocolProvider.Centralized dispatch:
DeviceCollectiveDispatcherDeviceCollectiveDispatcherextracts algorithm selection, plan installation, and dispatch logic fromDeviceCollectiveRuntime:DeviceGroupEndpoint.installGroupView(), inspects the activeGroupView::collective_algorithm_choices, identifies which algorithms are selected, updates shared protocols exactly once, and updates or invalidates algorithm plans viaControlUpdateBuilder.selectAlgorithm(request)matches the request's(OpType, byte_size)against the active algorithm policy and routes execution to the corresponding provider.Route capability-aware collective selection
PR 4/N introduced coordinated transfer endpoint installations managed by the Coordinator. This PR takes advantage of that coordinated handshake to collect hardware and route capabilities from the data plane before selecting collective algorithms.
DeviceTransferInstallResultcontaining theDeviceTransferRouteInfo(reachable,directly_addressable, andnative_atomics) for each GlobalRank.GroupView, it passes the verified routes of all active members toCollectiveSelection.OneShotrequires that every directed pair of active ranks has a directly addressable route with native atomics. If any peer pair lacks direct addressing or native atomics, the Coordinator automatically avoids OneShot and selects Ring.Unified invocation lifecycle, local-only execution, and recovery
Collective kernels previously duplicated startup boilerplate, view epoch synchronization, local-only execution, and failure reporting. This PR consolidates them into shared device-side primitives and host runtime management.
Unified kernel lifecycle:
runCollectiveInvocationAll collective kernels now enter and exit through a common template wrapper:
runCollectiveInvocation<Execution, Request, Plan>():applyPendingControlUpdate), and prepares execution.synchronizeCollectiveViewEpoch), settingview.synchronized = true. Subsequent collectives executing against the sameGroupViewgeneration skip redundant handshakes entirely, eliminating per-collective synchronization overhead on the hot path.Algorithm-agnostic local-only execution
When a group has only one active participant (
participant_count == 1), or when a rank transitions intoIsolatedduring extension, cross-rank communication is bypassed.Rather than requiring each algorithm kernel to implement single-rank special cases, the runtime routes these requests directly to
executeLocalOnlyCollective():Adapting failure recovery to the dispatcher
In the existing recovery mechanism, a kernel encountering an unrecoverable failure parks the last arriving CTA in
recoverCollectiveFailure(), reports the failure to the host, and waits for a pinned control update viarecovery.poll().Previously, host recovery re-published a monolithic static
Configurationsnapshot with hardcoded plans. With PR 5/N's decoupling intoDispatcherand dynamic providers, recovery updates are restructured accordingly:published_view_update_.GroupViewthat has not yet been consumed by the GPU (!published_view_update_->handle.poll()), recovery directly merges the active rank mirror update into this pending update and re-publishes it as a pinned control update.dispatcher_->invalidatePlans()to invalidate active plans instead.Supporting changes
ProviderEndpoint: Extracted a genericProviderEndpointbased onstruct_packserialization, replacing standalone endpoint structs for routes, protocols, and algorithms.GpuBuffer<T>,PinnedHostBuffer<T>, andMappedHostBuffer<T>togpu_runtime.h, replacing manual allocation and deallocation boilerplates.Scope and follow-up work
To thoroughly validate the generalized framework, PR 5/N and PR 6/N were developed together. To keep the review manageable, they are split into two PRs: PR 5/N establishes the core framework abstractions and ships Ring / OneShot AllGather to validate multi-output collectives, while the remaining operations and algorithms follow in PR 6/N.
Related work and suggested merge order
PR #4747 introduces Tree AllReduce stacked on PR 3/N (#4372). The recommended review and merge order is:
mainand merge it.Suggested Merge Priority
Module
mooncake-transfer-engine)mooncake-store)mooncake-conductor)mooncake-reshard)mooncake-ep)mooncake-pg)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-common)mooncake-rl)Type of Change
How Has This Been Tested?
TBD
Checklist
./scripts/code_format.shAI Assistance Disclosure
Codex was used to assist in designing and implementing this PR. All code and architectural changes have been thoroughly reviewed and verified by me in person.