Repository navigation
Fix scale-up semantics with two-phase extension protocol - #1968
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements a two-phase scale-up protocol for elastic world size extension, ensuring newly added ranks start as inactive and are only activated after signaling readiness. Key changes include updating MooncakeBackend::extendGroupSizeTo to initialize ranks as inactive and adding pg.join_group and pg.recover_ranks to the extension workflow. Feedback identifies a potential race condition in mooncake_backend.cpp where the group size is updated before rank metadata is fully initialized, and a missing timeout in a polling loop within the test suite.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements a two-phase scale-up protocol for the Mooncake backend, enabling ranks to join a group by establishing transport readiness before explicit activation. Key changes include the introduction of a max_world_size parameter for pre-allocating metadata, a pollingLimit_ in the connection poller to monitor potential joiners, and updates to ensure newly added ranks remain inactive until recovered. Review feedback identifies a potential bug where the connected peer counter may fail to update for ranks warmed up before joining, and suggests optimizations for collective operation overhead and tensor resizing logic during group expansion.
Track whether a peer has been counted in totalConnectedPeers_ so ranks that connect before entering groupSize_ are counted once they join, preventing waitUntilAllConnected hangs.
No functional change; aligns formatting with CI expectations.
Tests elastic group extension with multiple disjoint subgroups (group_a, group_b, group_c) using the split-ranks pattern required by SGLang: - Primary ranks initialize with initial_world_size only - Joiners wait for the extend signal, then init with full world_size - Each subgroup uses membership appropriate to the caller's WORLD view Also removes the redundant test_pg_elastic_simple.py file.
When a group has max_world_size > actual_size (e.g., size=3, max=4), _allgather_base and _reduce_scatter_base iterated meta_->size (=4) times into a buffer sized for only actual_size (=3) ranks, causing OOB writes/reads. Fix: skip inactive ranks (meta_->activeRanks[j] == false) in the send/recv lambdas. Inactive ranks have j >= actual_size, so skipping them avoids the overflow while preserving correct slot-j indexing for active ranks. allreduce was already safe (uses activeRanks in the reduce kernel). Add test_allgather_reduce_scatter_extension and test_allgather_reduce_scatter_recovery to cover both the overflow path (pre-activation with max_world_size > active ranks) and post-activation correctness for both extension and recovery scenarios.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a two-phase elastic scale-up protocol for the Mooncake backend, enabling ranks to observe and activate joiners without immediate group size changes. Key implementation details include the addition of a max_world_size option to pre-size metadata, a pollingLimit in the connection poller to monitor potential joiners, and the masking of inactive ranks during collective operations like allgather and reduce_scatter. The changes also include comprehensive tests for elastic extension and rank recovery. Feedback points out a potential issue with the identity mapping of reserved ranks in subgroups and an off-by-one error in the world size validation logic.
| for (int i = size; i < max_size; ++i) { | ||
| local2global_rank_map_[i] = i; | ||
| } |
There was a problem hiding this comment.
Initializing local2global_rank_map_ with identity for reserved slots (i >= size) assumes that future joiners will have global ranks exactly matching their local rank indices. This assumption breaks elastic scale-up for subgroups where joiners may have arbitrary global ranks. Consider allowing the user to provide a mapping or updating the map dynamically when joiner metadata is discovered in the store.
There was a problem hiding this comment.
Leave the case where local rank ≠ global rank to future work.
01833f9 to
3c06802
Compare
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Resolve conflicts between PR #1968 (two-phase scale-up) and main (ProcessGroup inheritance #2040). Key resolution: - mooncake_backend.h: Keep maxWorldSize_ constructor overload but drop Options{"mooncake"} prefix (ProcessGroup doesn't use it) - test_mooncake_backend_elastic.py: Keep two-phase protocol (get_peer_state -> recover_ranks) instead of simple extend_group_size_to; update _get_backend() to dist.group.WORLD
Re-add MooncakeP2PShim (from PR #2043) to the fix-scaleup-p0-crash branch. The shim was lost during the previous merge conflict resolution. It is needed because MooncakeBackend inherits ProcessGroup (not Backend) after #2040, and P2P dispatch requires getBackend() to return a registered Backend instance.
…e deprecated wheel PG tests - Sync MooncakeP2PShim with upstream main (#2043): clang-format getBackendName to single line (80 cols), add recvAnysource comment - Fix P2PProxy::ReleaseResources SIGABRT during process teardown by tolerating cudaSetDevice failure when CUDA driver is already shut down - Remove deprecated mooncake-wheel PG tests superseded by mooncake-pg/tests: test_mooncake_backend.py, test_mooncake_backend_cpu.py, test_mooncake_backend_elastic.py, test_mooncake_backend_p2p_cpu.py, test_mooncake_backend_chunk.py, test_mooncake_backend_perf.py
Merges the P2P credit/ack protocol refactor from upstream main: - CreditSlot/AckSlot replace old head/tail ring buffer - P2PChunkPool for send/recv staging - Per-peer epoch tracking (peer_epoch_) for stale detection - ExtensionState serialization now includes p2pEpochs - All P2PProxy methods renamed to camelCase Our CUDA driver shutdown tolerance in releaseResources() is preserved: upstream's setCudaDeviceIfNeeded() uses TORCH_CHECK which aborts on cudaErrorCudartUnloading during process teardown.
Before this change, getSize() returned meta_->size which was set to max_world_size at init time, causing dist.get_world_size() to report the pre-allocated capacity instead of the actual member count. Introduce meta_->activeSize to track the visible group size: - meta_->size remains the capacity (= max_world_size), used by collectives to iterate over all slots (activeRanks masks inactive) - meta_->activeSize tracks the actual member count, returned by getSize() / dist.get_world_size() - activeSize starts at world_size (not max_world_size) and grows when extendGroupSizeTo() or recoverRanks() expands the group For extension ranks, activeSize equals world_size; local-only behavior before joinGroup() is ensured by activeRanks masking. Add assertions in test_extension to verify world_size transitions.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements elastic group size management and a two-phase scale-up protocol. It introduces maxWorldSize for pre-allocating rank metadata, activeSize to track participating ranks, and a pollingLimit in the connection poller to detect joiners. Collective operations were updated to respect active ranks, and safety checks were added for CUDA driver shutdown during resource release. Feedback suggests refactoring duplicated peer-counting logic in connection_poller.cpp and optimizing the activeSize update in mooncake_backend.cpp using std::max_element.
| if (pollingRank < | ||
| groupSize_.load(std::memory_order_acquire)) { | ||
| totalConnectedPeers_.fetch_add( | ||
| 1, std::memory_order_release); | ||
| peerState.countedInGroup = true; | ||
| backend_wakeup_cv_.notify_all(); | ||
| } |
There was a problem hiding this comment.
This block of logic for counting a newly connected peer is duplicated in three places within this function (here, lines 344-350, and lines 375-381). This duplication can make maintenance harder and lead to inconsistencies if one instance is changed but not others.
Consider extracting this logic into a private helper method within the ConnectionContext class. A similar pattern is also used on lines 417-424, which could potentially be unified into the same helper by adding a check for !peerState.countedInGroup.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
dd05432 to
8f5bb0c
Compare
8f5bb0c to
3270818
Compare
…e-ai#1968) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Description
This PR fixes Mooncake PG elastic scale-up semantics by introducing an optional
max_world_sizeat backend initialization time.Key idea:
group_sizeunchanged (healthy ranks remain the only participants in collectives).ConnectionPollerto poll up tomax_world_size(a capacity / observation upper bound) so existing ranks can observe joiners without callingextend_group_size_to().get_peer_state()polling →recover_ranks()join_group()Motivation: why we need to decouple “polling range” from “group size”
In elastic scale-up, there are ranks that are not yet part of the current collective group, but we still want healthy ranks to proactively:
Previously, this often required calling
extend_group_size_to()first, which expands the group size and can make subsequent collectives implicitly include ranks that have not joined yet.With
max_world_size, we decouple these concepts:group_size(what collectives must consider right now)pollingLimit/max_world_size(what the poller is allowed to observe and warm up)API / behavior changes
max_world_sizetoMooncakeBackendOptions.active_rankstensor can be pre-sized tomax_world_size.[group_size, max_world_size)are treated as inactive reserved slots initially.ConnectionPollerusespollingLimit_(default =groupSize_) as the polling upper bound.< groupSize_contribute tototalConnectedPeers_(sowaitUntilAllConnected()semantics remain correct).Ideal calling sequence (two-phase scale-up protocol, no extend)
dist.init_process_group(..., world_size=group_size, pg_options=MooncakeBackendOptions(..., max_world_size=MAX))dist.init_process_group(..., world_size=MAX, pg_options=MooncakeBackendOptions(..., is_extension=True, max_world_size=MAX))pg.join_group(backend)publishes metadata and blocks until recovered state is published.pg.get_peer_state(backend, join_ranks)until all ready.pg.recover_ranks(backend, join_ranks)activates joiners.Notes:
get_peer_state()is a collective among healthy ranks; application code must ensure all active ranks enter it consistently.Module
mooncake-transfer-engine)mooncake-store)mooncake-ep)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-pg)mooncake-rl)Type of Change
How Has This Been Tested?
Verified in the existing k8s environment
sunxun/mooncake-pg-elastic-teston CPU (forcing TCP via env, without involving intra-node NVLink):MC_FORCE_TCP=1 python -m pytest -q /tmp/Mooncake-src/Mooncake/mooncake-pg/tests/test_pg_elastic.py -k "TestMooncakePGElasticCPU and test_extension"MC_FORCE_TCP=1 python -m pytest -q /tmp/Mooncake-src/Mooncake/mooncake-wheel/tests/test_mooncake_backend_elastic.py -k elasticChecklist
./scripts/code_format.shbefore submitting.