# 专家并行

**专家并行**（Expert Parallelism，EP）是混合专家（MoE）模型的一种并行策略：每个专家的前馈层部署在不同的硬件加速器上，由路由器将词元分发至相应的专家并收集结果<sup>[1](https://huggingface.co/docs/transformers/expert_parallelism)</sup>。由于MoE模型在相同算力预算下参数量远超稠密模型，这些参数必须分布到大量设备上；而每个词元只激活少量专家，使得参数总量可以大幅增长而计算开销保持不变。<sup>[1](https://huggingface.co/docs/transformers/expert_parallelism)</sup> 它是数据并行、张量并行、流水线并行、上下文并行等诸多并行维度之一，现代训练框架会将它们组合使用<sup>[2](https://openai.com/index/techniques-for-training-large-neural-networks/)</sup>。

| 关键事实 | 详情 |
|---|---|
| 定义 | 每个专家的前馈层驻留在不同的加速器上；路由器分发词元并收集结果<sup>[1](https://huggingface.co/docs/transformers/expert_parallelism)</sup> |
| 首次大规模应用 | GShard（2020）将MoE Transformer扩展至6000亿参数，仅将MoE层拆分到TPU设备上，其余层则完全复制<sup>[2](https://openai.com/index/techniques-for-training-large-neural-networks/)</sup> |
| 所引规模纪录 | Switch Transformer预训练了多达1.6万亿参数、2048个专家，2048块TPU上每设备一个专家<sup>[3](https://www.jmlr.org/papers/v23/21-0998.html)</sup><sup> • </sup><sup>[4](https://github.com/qfc-network/ai-infra/blob/main/foundational/switch-gshard/en.md)</sup> |
| 主要开销 | 将词元路由至远程专家的全对全通信；在大规模训练中可占用超过40%的运行时间<sup>[5](https://arxiv.org/abs/2505.13345)</sup> |
| 路由方式 | GShard采用top-2路由；Switch Transformer将每个词元路由至单个专家（top-1），减少了路由器计算、每专家批大小和通信量<sup>[4](https://github.com/qfc-network/ai-infra/blob/main/foundational/switch-gshard/en.md)</sup><sup> • </sup><sup>[6](https://github.com/huggingface/blog/blob/main/moe.md)</sup> |
| 现代实例 | DeepSeek-V3：6710亿参数的MoE模型，每词元激活370亿参数，采用专家并行训练<sup>[7](https://arxiv.org/abs/2412.19437)</sup> |
| 组合规则 | 在vLLM推理服务中，EP_SIZE = TP × DP 决定参与专家分布的GPU数量<sup>[8](https://docs.aws.amazon.com/prescriptive-guidance/latest/gen-ai-inference-architecture-and-best-practices-on-aws/system-optimizations.html)</sup> |

## 工作原理

一个MoE层包含许多独立的专家网络和一个路由器，路由器将每个词元只发送给其中一小部分专家<sup>[9](https://www.zyphra.com/our-work/expert-coupling-in-moe-pretraining)</sup>。在专家并行下，每个rank分发自己的词元，通过全对全集合通信将每个“词元–专家”对传输到持有该专家的rank；本地专家处理传入的词元后，再通过第二次全对全通信取回输出，并按路由权重加权合并。传输的只有被路由的激活值和专家输出，每个rank对自己收到的词元（包括来自其他rank的词元）计算本地专家<sup>[10](https://github.com/huggingface/transformers/blob/main/docs/source/en/expert_parallelism.md)</sup><sup> • </sup><sup>[19](https://nvidia.github.io/TransformerEngine/features/mixture_of_experts/mixture_of_experts.html)</sup>。

路由器本身开销很小，通常在每个GPU上复制一份，在全对全通信之前于本地计算路由决策<sup>[8](https://docs.aws.amazon.com/prescriptive-guidance/latest/gen-ai-inference-architecture-and-best-practices-on-aws/system-optimizations.html)</sup>。专家容量限制了每个专家每批接受的词元数，计算方式为（每批词元数除以专家数）乘以容量因子；[Switch Transformer](https://www.edgepedia.org/zh/switch-transformer)在1至1.25的低容量因子下表现良好，提高容量因子会增加设备间通信开销<sup>[6](https://github.com/huggingface/blog/blob/main/moe.md)</sup>。

## 起源与扩展里程碑

MoE的思想可追溯至雅各布斯等人（1991），沙泽尔等人2017年的稀疏门控MoE使其复兴，但该工作受训练不稳定性困扰，从未实现完整的生产部署<sup>[4](https://github.com/qfc-network/ai-infra/blob/main/foundational/switch-gshard/en.md)</sup>。2020年，TPU pod已能容纳数百个高带宽互连设备，GShard展示了首个在TPU pod上运行的6000亿参数MoE模型，依赖top-2路由、局部分组分发和容量因子来管理专家溢出。<sup>[4](https://github.com/qfc-network/ai-infra/blob/main/foundational/switch-gshard/en.md)</sup><sup> • </sup><sup>[11](https://arxiv.org/abs/2006.16668)</sup> 在GShard的方案中，只有MoE层跨设备拆分，其他层完全复制<sup>[2](https://openai.com/index/techniques-for-training-large-neural-networks/)</sup>。

随后Switch Transformer将路由算法简化为top-1，规避了许多不稳定性，同时在质量上保持竞争力<sup>[4](https://github.com/qfc-network/ai-infra/blob/main/foundational/switch-gshard/en.md)</sup>。JMLR论文报告，在相同计算资源下，预训练速度最高达到T5-Base和T5-Large设计的7倍，在万亿参数规模下达到T5-XXL的4倍，2048个专家分布于2048块TPU，每设备一个专家<sup>[3](https://www.jmlr.org/papers/v23/21-0998.html)</sup><sup> • </sup><sup>[4](https://github.com/qfc-network/ai-infra/blob/main/foundational/switch-gshard/en.md)</sup>。

## 全对全通信瓶颈

专家并行固有的全对全通信是其标志性开销，随着模型增大而削弱MoE效率<sup>[12](https://arxiv.org/abs/2404.05019)</sup>。据GShard分析，其开销随设备数量以O(√D)的温和速率增长；当专家数从128增至2048（16倍）时，分发–合并的执行时间增至原来的约3.75倍，其在MoE和Transformer执行时间中的占比从16%升至36%<sup>[11](https://arxiv.org/abs/2006.16668)</sup>。后来的综述报告称，在大规模训练中全对全通信占用超过40%的运行时间<sup>[5](https://arxiv.org/abs/2505.13345)</sup>。

**缓解措施**从多个方向攻克该瓶颈。ScMoE架构将通信与其常规序列解耦，允许与计算实现70%至100%的重叠<sup>[12](https://arxiv.org/abs/2404.05019)</sup>。[DeepSeek-V3](https://www.edgepedia.org/zh/deepseek-v3)通过算法、框架与硬件的协同设计，在跨节点MoE训练中几乎实现了计算–通信的完全重叠，并开源了DeepEP——一个提供高吞吐、低延迟全对全分发与合并内核、支持FP8的通信库<sup>[7](https://arxiv.org/abs/2412.19437)</sup>。MegaScale-MoE在1440块NVIDIA Hopper GPU上训练3520亿参数的MoE模型，达到每秒141万词元，效率达到[Megatron-LM](https://www.edgepedia.org/zh/megatron-lm)的1.88倍，主要归功于全面的通信重叠<sup>[13](https://arxiv.org/abs/2505.11432)</sup>。

## 负载不均衡

路由偏斜是第二个结构性问题。某些专家吸引大部分词元，形成“富者愈富”的路由坍缩，使其他专家闲置，并在分布式训练中产生掉队者<sup>[4](https://github.com/qfc-network/ai-infra/blob/main/foundational/switch-gshard/en.md)</sup>。训练时的辅助损失鼓励均匀路由<sup>[6](https://github.com/huggingface/blog/blob/main/moe.md)</sup>，但即便是训练良好的MoE模型，在推理和后训练阶段也表现出显著不均衡的路由，而此时显式负载均衡往往不适用；在极端不均衡下，EP可能将过多词元汇聚到少数专家，导致过载设备出现计算和内存瓶颈故障<sup>[14](https://proceedings.mlr.press/v306/nguyen26m.html)</sup>。最少负载专家并行（LLEP）方法通过将工作分配给负载最轻的设备来解决这一问题，在各模型规模下相比标准EP实现最高5倍加速，并将峰值内存用量降至原来的四分之一<sup>[14](https://proceedings.mlr.press/v306/nguyen26m.html)</sup>。

## 与其他并行的结合

在GShard、Switch Transformer和DeepSpeed-MoE中，专家并行被视为混合并行的一个正交维度<sup>[15](https://doi.org/10.1007/s44336-026-00038-z)</sup>。Megatron Core支持将其与张量并行、数据并行、流水线并行和上下文并行结合，且当EP与张量并行结合时需要序列并行<sup>[16](https://docs.nvidia.com/megatron-core/developer-guide/latest/user-guide/parallelism-guide.html)</sup>。其推荐的MoE配置包括：[Mixtral 8x7B](https://www.edgepedia.org/zh/mixtral-8x7b)在64块GPU上以EP=8运行，DeepSeek-V3（6710亿参数，256个专家）在1024块GPU上以EP=64运行<sup>[16](https://docs.nvidia.com/megatron-core/developer-guide/latest/user-guide/parallelism-guide.html)</sup>。

由于注意力和MoE层具有不同的计算特性，对两者采用统一的并行策略可能并非最优。MoE并行折叠将注意力层和MoE层的并行化解耦，使各自采用自己的配置，在H100 GPU上Mixtral 8x22B达到49.3%的模型浮点利用率，Qwen2-57B-A14B达到39.0%，并可扩展至1024块GPU和最长128K词元的序列长度<sup>[17](https://arxiv.org/abs/2504.14960)</sup>。

在推理服务中，同样的组合规则适用。在vLLM中启用EP后，完整专家分布到EP网格上，而路由器则复制；示例拓扑包括8块GPU上TP=1、DP=8、启用EP的MoE模型，以及跨2个节点16块GPU上TP=1、DP=16的大型MoE<sup>[8](https://docs.aws.amazon.com/prescriptive-guidance/latest/gen-ai-inference-architecture-and-best-practices-on-aws/system-optimizations.html)</sup>。进一步的改进——分离式专家并行——将注意力和FFN模块放在不同的GPU上，使各自可以独立扩展和部署；基于此思想的MegaScale-Infer系统报告称，每GPU吞吐量最高达到最先进方案的1.90倍<sup>[18](https://arxiv.org/abs/2504.02263)</sup>。

## 近期变化

两个趋势标志着该技术的当前状态。第一，通信工程已成为一等要务：DeepEP等专用库、适应不均衡MoE流量的偏斜感知可变长全对全通信算法，以及在跨节点传输中去除冗余词元的分发器变体，都直接针对全对全通信开销<sup>[7](https://arxiv.org/abs/2412.19437)</sup>。第二，EP所基于的均衡路由假设正在被放宽：生产模型在设计上就是非均衡路由的，LLEP和语义并行等系统现在将专家放置与词元调度协同安排，把专家及其激活词元共置于同一设备，以减少通信而非强制均匀路由<sup>[14](https://proceedings.mlr.press/v306/nguyen26m.html)</sup>。

## References

1. [Expert parallelism, Hugging Face Transformers documentation](https://huggingface.co/docs/transformers/expert_parallelism)
2. [Techniques for training large neural networks, OpenAI](https://openai.com/index/techniques-for-training-large-neural-networks/)
3. [Fedus, W., Zoph, B., Shazeer, N. (2022). Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity. JMLR 23(120)](https://www.jmlr.org/papers/v23/21-0998.html)
4. [Switch Transformers & GShard — Scaling MoE to Trillions of Parameters, qfc-network/ai-infra](https://github.com/qfc-network/ai-infra/blob/main/foundational/switch-gshard/en.md)
5. [Occult: Optimizing Collaborative Communication across Experts for Accelerated Parallel MoE Training and Inference, arXiv:2505.13345](https://arxiv.org/abs/2505.13345)
6. [Mixture of Experts Explained, Hugging Face Blog](https://github.com/huggingface/blog/blob/main/moe.md)
7. [DeepSeek-V3 Technical Report, arXiv:2412.19437](https://arxiv.org/abs/2412.19437)
8. [System-level optimizations, AWS Prescriptive Guidance](https://docs.aws.amazon.com/prescriptive-guidance/latest/gen-ai-inference-architecture-and-best-practices-on-aws/system-optimizations.html)
9. [Expert Coupling in MoE Pretraining, Zyphra](https://www.zyphra.com/our-work/expert-coupling-in-moe-pretraining)
10. [Expert parallelism, Hugging Face Transformers docs (GitHub source)](https://github.com/huggingface/transformers/blob/main/docs/source/en/expert_parallelism.md)
11. [GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding, arXiv:2006.16668](https://arxiv.org/abs/2006.16668)
12. [Cai, W. et al. (2024). Shortcut-connected Expert Parallelism for Accelerating Mixture-of-Experts, arXiv:2404.05019](https://arxiv.org/abs/2404.05019)
13. [MegaScale-MoE: Large-Scale Communication-Efficient Training of Mixture-of-Experts Models in Production, arXiv:2505.11432](https://arxiv.org/abs/2505.11432)
14. [Nguyen, X.-P. et al. (2026). Least-Loaded Expert Parallelism: Load Balancing An Imbalanced Mixture-of-Experts, ICML, PMLR v306](https://proceedings.mlr.press/v306/nguyen26m.html)
15. [Efficient training of large language models on distributed infrastructures: a survey, Vicinagearth (Springer Nature)](https://doi.org/10.1007/s44336-026-00038-z)
16. [Parallelism Strategies Guide, NVIDIA Megatron Core](https://docs.nvidia.com/megatron-core/developer-guide/latest/user-guide/parallelism-guide.html)
17. [MoE Parallel Folding: Heterogeneous Parallelism Mappings for Efficient Large-Scale MoE Model Training with Megatron Core, arXiv:2504.14960](https://arxiv.org/abs/2504.14960)
18. [MegaScale-Infer: Serving Mixture-of-Experts at Scale with Disaggregated Expert Parallelism, arXiv:2504.02263](https://arxiv.org/abs/2504.02263)
19. [Mixture of Experts, Transformer Engine 2.22.0.dev0](https://nvidia.github.io/TransformerEngine/features/mixture_of_experts/mixture_of_experts.html)

---
*Initially written Oct 15, 2026 · Edited: Oct 25, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Neural networks and deep learning › Deep learning software and hardware › Distributed and large-scale training

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/expert-parallelism

English original: https://www.edgepedia.org/expert-parallelism
