Moonshot AI Open-Sources MoonEP: A Perfectly Balanced Expert Parallelism Library for MoE Training
https://www.marktechpost.com/2026/07/29/moonshot-ai-open-sources-moonep-a-perfectly-balanced-expert-parallelism-library-for-moe-training/📌 【Moonshot AI 開源】MoonEP:解決 MoE 訓練中的專家不平衡,讓擴展效率提升 2.5 倍
TL;DR:Moonshot AI 開源 MoonEP 函式庫,透過冗餘專家機制解決 MoE 訓練中的路由不平衡問題。
在訓練超大規模混合專家模型(MoE)時,工程師常面臨一個棘手的問題:Router(路由器)分配給每個專家的 Token 數量極度不均。這不僅導致 GPU 效能閒置,更會因為動態的 Token 數量造成記憶體碎片化與頻繁的同步開銷。
🧩 MoE 訓練的痛點:路由不平衡與結構性成本
在專家並行(Expert Parallelism, EP)架構下,Router 會將每個 Token 導向前 K 個專家(top-k experts),而這些專家分佈在不同的 Rank(計算節點)上。然而,Router 的分配極少能達到完美平衡:
- 最大偏差量 (maxvio):作者使用
maxvio = max_e (T_e / T̄) − 1來定義不平衡程度(其中 $T_e$ 為專家 $e$ 收到的 Token 數,$\bar{T}$ 為預期平均值)。當maxvio為 0 時代表完美平衡。 - 結構性延遲:集體通訊(Collective)的延遲取決於最慢的參與者,因此「最熱」的 Rank 會決定整個迭代的時間。
- 記憶體與同步問題:每個 Step 之間 Token 數量的變化是動態的,這會導致 GPU 記憶體碎片化,並迫使每層都需要進行主機端(Host)同步。
🚀 MoonEP 的核心機制:透過冗餘專家實現完美平衡
MoonEP 的設計目標是維持一個硬性不變量(Hard Invariant):不論路由結果多麼傾斜,每個 Rank 接收到的 Token 數量必須精確等於 $S \times K$($S$ 為每 Rank 的輸入 Token 數,$K$ 為 top-k 專家數)。
其技術路徑如下:
- 線上規劃冗餘專家:直接根據當前的 Router 輸出,即時規劃少量的冗餘專家(Redundant experts)。
- 預取機制:在專家計算開始前,先將這些重複的專家進行預取(Prefetch)。
- 梯度聚合:在反向傳播(Backward pass)過程中,將這些冗餘專家的梯度重新聚合(Reduce)回它們原本的家園 Rank。
📊 助力 Kimi K3 實現 2.5 倍擴展效率提升
MoonEP 是 Moonshot AI 開發 Kimi K3 模型時的核心技術創新之一。Kimi K3 是一個擁有 2.8 兆參數的 MoE 模型,具備原生視覺能力與 1M Token 的長上下文窗口。透過 MoonEP 的優化,該模型在擴展效率(Scaling efficiency)上達到了 2.5 倍的顯著提升。
🎯 實務啟示
對於從事大規模分散式訓練的工程師而言,MoonEP 提供了一個處理動態負載不平衡的新思路:不再是被動地接受 Router 的分配,而是透過主動規劃冗餘計算來換取通訊與記憶體的穩定性。
🔗 來源
- 標題:Moonshot AI Open-Sources MoonEP: A Perfectly Balanced Expert Parallelism Library for MoE Training
- 作者/機構:Michal Sutter @ MarkTechPost
- 連結:https://www.marktechpost.com/2026/07/29/moonshot-ai-open-sources-moonep-a-perfectly-balanced-expert-parallelism-library-for-moe-training/
#MoonshotAI #MoE #ExpertParallelism #DistributedTraining #MachineLearning #OpenSource #KimiK3 #AIInfrastructure #ScalingEfficiency #DeepLearning
原始資料 MarkTechPost · 收集於 2026-07-30
摘要原文
Moonshot AI has open-sourced MoonEP , an Expert Parallelism (EP) communication library for distributed Mixture-of-Experts (MoE) workloads. The team announced the release as a library built to make expert-parallel communication more efficient at scale. It ships under an MIT license. MoonEP arrived as part of Kimi K3 Open Day. Alongside the K3 model weights and technical report, Moonshot released three infrastructure codebases: MoonEP, FlashKDA, and AgentEnv. FlashKDA had already been open-sourced; MoonEP and AgentEnv were published with this release. MoonEP is one of the innovations behind a claimed 2.5× improvement in scaling efficiency for Kimi K3 , a 2.8-trillion-parameter MoE model with native vision and a 1M-token context window. In expert parallelism, a router sends each token to its top-K experts, which live on different ranks. Routers are rarely balanced. Some experts get far more tokens than others. The repository quantifies skew with maxvio , defined as max_e (T_e / T̄) − 1 , where T_e is tokens routed to expert e and T̄ is the expected count under perfect balance. A maxvio of 0 means perfectly balanced. Imbalance costs are structural, not incidental. A collective’s latency is set by its slowest participant, so the hottest rank determines iteration time. Worse, token counts per rank change every step. Those dynamic activation shapes fragment GPU memory and force per-layer host synchronization. MoonEP’s main mention is a hard invariant. Every rank receives exactly S × K tokens, no matter how skewed the routing is — where S is input tokens per rank and K is routed top-k per token. It achieves this by planning a small number of redundant experts online, directly from the current router outputs. Those duplicated experts are prefetched before expert computation. In the backward pass, their gradients are reduced back to their home ranks. The design is set up into three properties: The interactive explainer below computes the resulting buffer and prefetch-pool siz
由 tencent/hy3:free 自動生成