Skip to content

[PG] Enable asynchronous recovered-rank initialization with deferred join#1744

Open
UNIDY2002 wants to merge 1 commit intomainfrom
sunxun/deferred-recovery
Open

[PG] Enable asynchronous recovered-rank initialization with deferred join#1744
UNIDY2002 wants to merge 1 commit intomainfrom
sunxun/deferred-recovery

Conversation

@UNIDY2002
Copy link
Collaborator

Description

Motivation

During Elastic EP rank recovery, the recovered rank must re-run expensive initialization (especially CUDA graph capture).
Previously, this required the recovered and healthy ranks to enter the same communication phase, which paused healthy-rank inference and increased recovery disruption.

This change enables asynchronous recovered-rank initialization in Mooncake PG: recovered ranks can initialize in isolation first, then join the live process group after local recovery work is finished.

What this PR changes (Mooncake)

1. Deferred extension-group bootstrapping

  • For extension backends, backend construction no longer requires immediate full-group connection.
  • Added explicit local bootstrap/publish flow:
    • bootstrap local peer metadata for self
    • defer publishing full metadata / full connection until joinGroup()
  • Added local-only active-rank setup for extension mode so recovered rank can run isolated initialization safely.

2. Explicit deferred join API path

  • Added/finished joinGroup() behavior for extension backends:
    • publish local peer metadata
    • register into connection poller
    • wait for full-group connectivity
    • synchronize extension recovery state (task count + active ranks) from store

This is the key hook that lets the recovered rank rejoin the healthy group only after local init completes.

Behavior impact

  • Recovered rank can perform local recovery initialization without forcing healthy ranks into the same phase.
  • Healthy ranks continue inference for most of recovery.
  • Recovered rank joins at an explicit synchronization point via joinGroup().
  • Group expansion behavior remains compatible with elastic/fault-tolerant scenarios.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake EP (mooncake-ep)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • PyTorch Backend (mooncake-pg)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Other

How Has This Been Tested?

In the latest code of sgl-project/sglang#15771

Checklist

  • I have performed a self-review of my own code.
  • I have formatted my own code using ./scripts/code_format.sh before submitting.
  • I have updated the documentation.
  • I have added tests to prove my changes are effective.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the fault tolerance and elasticity of the Mooncake Process Group (PG) backend by introducing an asynchronous recovery mechanism. Previously, rank recovery caused disruptions to healthy ranks due to synchronous initialization requirements. The new approach allows recovered ranks to perform their intensive setup tasks independently before explicitly rejoining the active group, thereby minimizing performance impact on ongoing operations and improving the overall resilience of distributed training and inference systems.

Highlights

  • Asynchronous Recovered-Rank Initialization: Enabled recovered ranks in Mooncake PG to initialize in isolation, preventing healthy ranks from pausing inference during recovery.
  • Deferred Extension-Group Bootstrapping: Modified extension backends to allow for local-only initialization and defer full-group connection until explicitly joined.
  • Explicit Deferred Join API: Introduced a joinGroup() API that allows a recovered rank to rejoin the healthy process group only after its local initialization is complete.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a "deferred join" mechanism for Mooncake's distributed communication backend, allowing ranks to join a group in a local-only mode before fully integrating. This involves adding an active_ranks_mask parameter to various MooncakeEpBuffer synchronization methods (IB, RoCE, NVLink IPC) to optimize communication by skipping inactive ranks. The ConnectionContext and MooncakeBackend classes are updated with new state (isDummy_, localServerName_, connectionPollerRegistered_) and methods (bootstrapLocalPeer, setLocalOnlyActiveRanks, publishLocalPeerMetadata, waitForExtensionState, syncActiveRanksTensor, joinGroup) to manage this deferred join and rank recovery process. The ConnectionPoller's thread management is also improved. A new Python binding for join_group is added, and the Python mooncake_ep_buffer now passes the active_ranks_mask to the C++ backend. The test suite is updated with a new _deferred_recovery_worker and test_rank_recovery_deferred_join to validate this functionality. Review comments highlight a critical issue where the test_rank_recovery test will fail due to a NameError after the _recovery_worker function was renamed to _deferred_recovery_worker without updating the test itself. Additionally, there are two medium-severity improvement opportunities: one suggesting replacing a busy-wait loop with a blocking store->wait() call for efficiency in waitForExtensionState, and another recommending refactoring the repeated get_active_ranks call in mooncake_ep_buffer.py to avoid redundant distributed calls and code duplication.


def _recovery_worker(rank, num_processes, signals):
"""Worker for testing rank recovery."""
def _deferred_recovery_worker(rank, num_processes, signals):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

By renaming _recovery_worker to _deferred_recovery_worker, the existing test test_rank_recovery will fail with a NameError as it still tries to call the old function name _recovery_worker. Please update test_rank_recovery to call _deferred_recovery_worker if this is a replacement, or restore the original _recovery_worker if both are needed.

Comment on lines +843 to +857
while (true) {
if (meta_->store->check({task_count_key, active_ranks_key})) {
auto task_count_data = meta_->store->get(task_count_key);
std::string task_count(task_count_data.begin(),
task_count_data.end());
meta_->taskCount = std::stoi(task_count);

auto active_ranks = meta_->store->get(active_ranks_key);
deserializeActiveRanks(active_ranks, meta_->activeRanks,
meta_->size);
syncActiveRanksTensor();
return;
}
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This while (true) loop with a sleep implements a busy-wait to check for keys in the store. This is inefficient and can consume unnecessary CPU cycles. The c10d::Store API provides a blocking wait() method that is more suitable for this purpose. Please consider using store->wait({task_count_key, active_ranks_key}) to wait for the keys to become available, which will be more efficient.

    meta_->store->wait({task_count_key, active_ranks_key});

    auto task_count_data = meta_->store->get(task_count_key);
    std::string task_count(task_count_data.begin(),
                           task_count_data.end());
    meta_->taskCount = std::stoi(task_count);

    auto active_ranks = meta_->store->get(active_ranks_key);
    deserializeActiveRanks(active_ranks, meta_->activeRanks,
                           meta_->size);
    syncActiveRanksTensor();

Comment on lines +153 to +154
from mooncake.ep import get_active_ranks
active_ranks_mask = get_active_ranks(self.backend).tolist()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to get active_ranks_mask is repeated three times in this method. This is inefficient as it involves a distributed call (get_active_ranks) and duplicates code. It would be cleaner to fetch active_ranks_mask once at a higher scope within the connect method (e.g., before the if not self._use_fallback: block) and reuse the variable in all three places.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants