Skip to content

feat: introduce async rebalance mode for dynamic EPLB - #3

Open
TheBasy wants to merge 1 commit into
mainfrom
eplb-rebalance-asnyc
Open

feat: introduce async rebalance mode for dynamic EPLB#3
TheBasy wants to merge 1 commit into
mainfrom
eplb-rebalance-asnyc

Conversation

@TheBasy

@TheBasy TheBasy commented Sep 22, 2025

Copy link
Copy Markdown
Collaborator

Add support for asynchronous rebalancing in the Expert Parallel Load Balancer (EPLB) to avoid blocking the decoding loop during load analysis. This enables continuous token generation while rebalance computation runs in the background.

New CLI argument:

  • --enable-eplb-rebalance-async: enables asynchronous rebalancing mode

Implementation details:

  • Launch background thread to:
    • Broadcast logical_count
    • Compute ExpertLocationMetadata
    • Store result in _rebalance_result
  • Use TP barrier via gloo cpu_group (send_single_signal / recv_single_signal) to ensure all ranks atomically enter the counter-swap phase
  • Introduce yield-based generator to keep decoding loop non-blocking
  • Model state transfer starts only after TP-wide agreement via _begin_transfer
  • Sync mode remains unchanged: uses blocking single-thread rebalance

This change improves latency stability under dynamic load conditions in MoE models.

Motivation

In Mixture-of-Experts (MoE) models, the Expert Parallel Load Balancer (EPLB) periodically performs load analysis to ensure balanced expert utilization across devices. However, in the current synchronous implementation, this rebalancing process blocks the decoding loop, introducing unpredictable latency spikes—especially under dynamic workloads where frequent rebalance decisions are required. This blocking behavior degrades end-to-end inference performance and undermines the predictability of token generation, which is critical for real-time or interactive applications.

To address this issue, we propose an asynchronous rebalancing mechanism that decouples the computationally intensive load analysis from the token generation pipeline. By offloading rebalance computation to a background thread, the main decoding loop remains non-blocking, enabling continuous token production while maintaining accurate load balancing. This enhancement improves latency stability and system responsiveness under dynamic load conditions, without compromising the correctness or convergence of the rebalancing logic.

Modifications

  • Introduced a new CLI argument --enable-eplb-rebalance-async to enable asynchronous rebalancing mode. When disabled (default), the original blocking behavior is preserved for backward compatibility.
  • Implemented an asynchronous rebalancing workflow using a dedicated background thread that:
  • Broadcasts the local logical_count across tensor parallel (TP) ranks.
  • Computes ExpertLocationMetadata based on global load information.
  • Stores the computed result in a shared _rebalance_result field for later application.
  • Integrated synchronization via TP-wide CPU barrier using Gloo's cpu_group, leveraging send_single_signal and recv_single_signal primitives to ensure all ranks atomically enter the counter-swap phase, avoiding race conditions.
  • Refactored the decoding loop into a yield-based generator pattern to maintain non-blocking execution; model state transfer is deferred until all ranks reach agreement through the _begin_transfer flag.
  • Preserved the original synchronous mode (async=False) with no changes to its single-threaded, blocking rebalance logic, ensuring consistency and ease of comparison.
  • These modifications enable seamless integration of async rebalancing into the existing EPLB framework while maintaining correctness, scalability, and ease of debugging.

Accuracy Tests

Benchmarking and Profiling

Checklist

Add support for asynchronous rebalancing in the Expert Parallel Load Balancer (EPLB) to avoid blocking the decoding loop during load analysis. This enables continuous token generation while rebalance computation runs in the background.

New CLI argument:
- --enable-eplb-rebalance-async: enables asynchronous rebalancing mode

Implementation details:
- Launch background thread to:
  - Broadcast logical_count
  - Compute ExpertLocationMetadata
  - Store result in _rebalance_result
- Use TP barrier via gloo cpu_group (send_single_signal / recv_single_signal) to ensure all ranks atomically enter the counter-swap phase
- Introduce yield-based generator to keep decoding loop non-blocking
- Model state transfer starts only after TP-wide agreement via _begin_transfer
- Sync mode remains unchanged: uses blocking single-thread rebalance

This change improves latency stability under dynamic load conditions in MoE models.
Zqy11 added a commit that referenced this pull request Sep 3, 2026
…-mem overlap

- #3 fail loudly: drop post-collective try/except silent fallback in
  maybe_fused_ag_shared_experts / maybe_fused_shared_add_rs; eligibility
  is decided before any collective entry
- #4 wrap the CP layer loop in try/finally so set_use_cp(False) always
  runs; set_use_cp(True) moves to the end of CP prep
- #6 thread missing kwargs through the use_cp branch of triton
  fused_experts: gate_up_interleaved / a1_q / fuse_swiglu_interleaved
- #7 size symm-mem buffers by max_prefill_buffer_tokens() instead of
  chunked_prefill_size; assert M bounds at the AG and RS call sites
- #8 require N % 512 == 0: MOE_RS_CHUNK_WIDTH constant, eligibility
  gate in maybe_fused_shared_add_rs, n_chunks derived from ctx.N
- #9 migrate AllGatherGemmContextSymmMem / MoEReduceRSSymmMemContext to
  msgspec.Struct; rendezvous moves into the create factory
- #10 drop defensive getattr for shared-expert weight scales; pass
  shared_experts_weight_block_size as the fp8-eligibility signal
- #11 reconcile fused AG/RS contexts on the attn CP group (the ranks
  dsa_cp_* operate on), shard divisor = attn_cp_size
- #12 ASCII-only comments; drop narration comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant