Commit Graph
1 Commits
Author SHA1 Message Date
911fa25c0c feat(moe): online expert rebalancing through the same-round gate (#1977)
## Summary

Online expert rebalancing (dynamic EPLB) on top of the static placement (#1975): periodically recompute the redundant-expert placement from recorded routing load and move expert weights between ranks without stopping the server.

- **Load**: the routing kernels' int64 counters count only real rows (a device-side live-row mask excludes CUDA-graph filler rows) and start serving at zero. `snapshot_expert_load` copies and resets them on the execution stream.
- **Algorithm**: the DeepSeek-style `rebalance_experts` made deterministic (`double`, stable sort) and run CPU-only in a spawned worker process on EP rank 0; the result is broadcast at commit, so every rank applies the same maps by construction.
- **Weights**: `plan_slot_moves` (pure, CPU, identical on every rank) decides per changed slot: same-GPU copy, free-rider, same-node or cross-node P2P; `apply_expert_placement` runs `batch_isend_irecv` into a startup-reserved staging buffer and copies into the existing slot tensors (CUDA-graph addresses stay stable), then switches that layer's tables in place.
- **Sequencing**: the rebalance is a sequence of internal control ops (`EplbSnapshot` → `EplbCommit` → `EplbApplyChunk(layer_ids)`) riding the same attention-DP same-round gate the RL weight update uses (second FIFO, gate widened 4→7 lanes, one blocking device op per round, chunk stall bounded by `--eplb-rebalance-layers-per-chunk`); `POST /rebalance_experts` triggers one manually. Memory-saver release is refused while a rebalance is in flight.
- `--enable-eplb` now accepted; `--eplb-rebalance-num-iterations`, `--eplb-rebalance-layers-per-chunk`, recorder mode and a static dispatch algorithm are required explicitly. Under a bitwise numerics envelope the placement-independent slot-order MoE combine is required (a rank-order fold would make the output depend on the placement). The dead expert-distribution recorder module is removed.

Builds on #1975 (static placement) and #1955 (the same-round gate), both merged.

## Tests

416 passed across `test/runtime/moe/*` (plan simulation over every rank, controller phases, 4-process gloo `batch_isend_irecv` application, live-row mask), `test_expert_location.py`, `test_eplb_algorithm.py`, `test_weight_update_dp_gate.py` (7 lanes), `test_event_loop_eplb_hooks.py`, `test_device_handle.py`, the MoE model/loader tests. Not verified on GPU/NCCL (P2P coalescing, stream ordering against graph replay, a live server rebalance).

Docs: `docs/design/event-loop.md`, `docs/serving/parallelism.md`, `docs/configuration/server.md`, `docs/design/numerics.md`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: FC-Li <robert_lexis@163.com>
Co-authored-by: longcat-ia-team <longcat_ia_team@meituan.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-10-04 20:11:48 +08:00