# 词元丢弃

词元丢弃是稀疏混合专家（MoE）训练中的一种技术：被路由到某个专家、但该专家已填满其固定容量的词元，会被排除在该专家的计算之外，并通过残差连接（让输入绕过某一层、原样通过的捷径路径）原封不动地穿过该层。一种同名但不同的相关技术则通过从中间层丢弃不重要的词元来加速 BERT 预训练。<sup>[1](https://arxiv.org/abs/2203.13240)</sup><sup> • </sup><sup>[2](https://vibeengines.com/paper/switch-transformer)</sup>

| 关键事实 | 详情 |
|---|---|
| 专家容量 | \( (\text{每批词元数} / \text{专家数}) \times \text{容量因子} \)；超出此缓冲区的词元会被丢弃<sup>[3](https://paper-graph-ui.vercel.app/p/moe/2101.03961-Switch-Transformers-Scaling-to-Trillion-Parameter-Models-with-Simple-and-Efficie)</sup><sup> • </sup><sup>[18](https://jmlr.org/papers/volume23/21-0998/21-0998.pdf)</sup> |
| 典型容量因子 | 1.0 至 1.25；Switch Transformer 在 1.0 和 1.25 时表现最佳<sup>[4](https://llm-tutorial.darvinyi.com/ch11-moe/)</sup><sup> • </sup><sup>[5](https://ai.thesatyajit.com/architectures/mixture-of-experts)</sup> |
| 被丢弃词元的去向 | 完全跳过该专家，通过残差连接原样通过<sup>[2](https://vibeengines.com/paper/switch-transformer)</sup> |
| 观测到的丢弃率 | Switch 发现配合其均衡损失时丢弃率通常低于 1%；现代训练会调整容量，将丢弃率保持在 1–2% 以下<sup>[5](https://ai.thesatyajit.com/architectures/mixture-of-experts)</sup><sup> • </sup><sup>[4](https://llm-tutorial.darvinyi.com/ch11-moe/)</sup> |
| 无丢弃替代方案 | MegaBlocks 将 MoE 计算重构为块稀疏操作，从不丢弃词元，训练速度比 Tutel 库快至多 40%，速度为 Megatron-LM 稠密训练的 2.4 倍<sup>[6](https://arxiv.org/abs/2211.15841)</sup> |
| 框架默认行为 | DeepSpeed 的 MoE 层默认启用词元丢弃（`drop_tokens=True`），同时也启用随机词元选择（`use_rts=True`）<sup>[7](https://deepspeed.readthedocs.io/en/latest/moe.html)</sup> |
| BERT 语境下的含义 | 从某一中间层开始丢弃不重要的词元，再由最后一层接回，因此模型仍能产出全长序列<sup>[1](https://arxiv.org/abs/2203.13240)</sup> |

## 词元丢弃为何存在

在混合专家层中，一个小型路由器网络将每个词元发送给一个或少数几个专家，而不是发送给单个稠密前馈网络。每个专家接收的词元数量在不同批次之间会不可预测地变化，但 TPU 等加速器要求张量形状在编译时固定，而 GPU 在规整的矩形计算上才能达到最佳吞吐量。<sup>[3](https://paper-graph-ui.vercel.app/p/moe/2101.03961-Switch-Transformers-Scaling-to-Trillion-Parameter-Models-with-Simple-and-Efficie)</sup><sup> • </sup><sup>[8](https://developer.nvidia.com/blog/accelerating-dropless-moe-training-in-jax-with-nvidia-transformer-engine/)</sup>

标准解决方案随 GShard 中的容量因子引入，并由 [Switch Transformer](https://www.edgepedia.org/zh/switch-transformer) 推广开来：为每个专家分配一个固定大小的词元槽缓冲区。容量按每批词元数除以专家数、再乘以容量因子计算。<sup>[3](https://paper-graph-ui.vercel.app/p/moe/2101.03961-Switch-Transformers-Scaling-to-Trillion-Parameter-Models-with-Simple-and-Efficie)</sup><sup> • </sup><sup>[9](https://aiwiki.ai/wiki/switch_transformer)</sup> 如果路由发送给某个专家的词元多于其缓冲区容量，溢出的词元就会被丢弃：该专家不处理它们，它们通过残差连接原样进入下一层。<sup>[2](https://vibeengines.com/paper/switch-transformer)</sup>

## 容量因子的权衡

**容量控制丢弃率。** 容量因子大于 1 会增加余量、减少丢弃，代价是为接收词元数少于缓冲区容量的专家做填充而浪费计算和内存；因子小于 1 则节省计算，但会丢弃更多词元。<sup>[2](https://vibeengines.com/paper/switch-transformer)</sup> 一个例子说明了计算方式：给定 4,096 个词元、64 个专家、top-8 路由和 1.0 的容量因子，每个专家获得 4,096 × 8 / 64 = 512 个槽位；当某个专家被选中 600 次时，它会丢弃其中 88 个词元。<sup>[5](https://ai.thesatyajit.com/architectures/mixture-of-experts)</sup>

Switch Transformer 发现，配合其辅助均衡损失时，丢弃率通常保持在 1% 以下，且模型在容量因子为 1.0 和 1.25 时表现最佳。<sup>[5](https://ai.thesatyajit.com/architectures/mixture-of-experts)</sup> 现代 MoE 训练会调整容量，使丢弃率保持在 1–2% 以下，推理框架通常配置 1.0 的容量因子，接受少量丢弃以换取吞吐量收益。<sup>[4](https://llm-tutorial.darvinyi.com/ch11-moe/)</sup> 丢弃率取决于路由均衡程度：在 GShard 风格的 top-2 路由中，对训练后模型的分析发现，被分配到其首选专家的词元很少被丢弃，而大约 35% 被路由到其次选专家的词元会遭遇丢弃。<sup>[10](https://aclanthology.org/2025.findings-acl.653.pdf)</sup> 当不均衡严重时，问题会加剧：专家选择路由的研究者在词元选择路由下观察到某些专家的超容量比例达到 20%–40%，意味着路由到这些专家的词元中有相当一部分会被丢弃。<sup>[11](https://proceedings.neurips.cc/paper_files/paper/2022/file/2f00ecd787b432c1d36f3de9800728eb-Paper-Conference.pdf)</sup>

残差连接限制了被丢弃词元的损害，因为其隐藏状态仍能到达下一层，但质量代价是真实的：该词元在该层没有得到任何专家处理。<sup>[4](https://llm-tutorial.darvinyi.com/ch11-moe/)</sup> 因此丢弃率也充当训练健康度的指标；Switch Transformer 论文报告称，在健康的训练运行中，大约 99% 或更多的词元被成功路由。<sup>[12](https://papermap.vercel.app/paper/Switch_Transformers_Scaling_to_Trillion_Parameter_Models.html)</sup>

## 变体与缓解措施

**随机词元选择。** [DeepSpeed](https://www.edgepedia.org/zh/deepspeed) 的 MoE 实现默认启用词元丢弃，并搭配随机词元选择，据其描述，这解决了 MoE 训练中的有偏选择问题并改善了收敛；该功能默认启用，无需配置。<sup>[7](https://deepspeed.readthedocs.io/en/latest/moe.html)</sup><sup> • </sup><sup>[13](https://github.com/deepspeedai/DeepSpeed/blob/master/docs/_tutorials/mixture-of-experts.md)</sup> DeepSpeed 还提供了用于训练和评估容量因子、最小容量的标志，以及一个 `--disable-moe-token-dropping` 选项，可完全移除每个专家的词元限制。<sup>[14](https://github.com/deepspeedai/DeepSpeed/blob/master/docs/_tutorials/mixture-of-experts-nlg.md)</sup>

**无丢弃 MoE。** MegaBlocks 通过将 MoE 计算重构为使用自定义 GPU 内核的块稀疏矩阵乘法，彻底消除了丢弃，因此每个专家可以在不丢弃、不填充的情况下处理可变数量的词元。这消除了容量因子超参数，并实现了端到端训练加速：比用 Tutel 库训练的 MoE 快至多 40%，速度为用 [Megatron-LM](https://www.edgepedia.org/zh/megatron-lm) 训练的稠密模型的 2.4 倍。<sup>[6](https://arxiv.org/abs/2211.15841)</sup> 该方法此后得到推广：NVIDIA 的 Transformer Engine 为 JAX 中的无丢弃 MoE 提供了分组 GEMM 内核，Megatron Core 提供了支持词元丢弃和无词元丢弃训练的词元级调度器。<sup>[8](https://developer.nvidia.com/blog/accelerating-dropless-moe-training-in-jax-with-nvidia-transformer-engine/)</sup><sup> • </sup><sup>[15](https://arxiv.org/abs/2504.14960)</sup>

**路由替代方案。** 专家选择路由反转了分配方式：不是每个词元选择专家，而是每个专家选择其排名最靠前的词元，因此可以预先确定固定的专家容量，容量不再需要超额配置以避免缓冲区溢出。<sup>[16](https://www.research.google/blog/mixture-of-experts-with-expert-choice-routing/)</sup> 迭代重路由也被提出，其中从已满专家处被丢弃的词元会被重新分配给仍有剩余容量的专家。<sup>[10](https://aclanthology.org/2025.findings-acl.653.pdf)</sup>

## MoE 之外的词元丢弃

同一名称还描述了另一种加速 BERT 预训练的技术。在该技术中，从某一中间层开始丢弃不重要的词元，使模型将计算集中在重要词元上；被丢弃的词元由最后一层重新接回，因此模型仍能产出全长序列，下游性能不会下降。<sup>[1](https://arxiv.org/abs/2203.13240)</sup> 一种相关的 DeepSpeed 方法 random-LTD（随机逐层词元丢弃）在所有中间层只处理一部分词元以节省计算，使用纯随机的逐层选择，适用于编码器和解码器模型。<sup>[17](https://www.deepspeed.ai/2022/12/11/data-efficiency.html)</sup>

## References

1. [Token Dropping for Efficient BERT Pretraining, arXiv:2203.13240](https://arxiv.org/abs/2203.13240)
2. [Switch Transformer, Explained, Vibe Engines](https://vibeengines.com/paper/switch-transformer)
3. [Switch Transformers: Scaling to Trillion Parameter Models, Paper Graph](https://paper-graph-ui.vercel.app/p/moe/2101.03961-Switch-Transformers-Scaling-to-Trillion-Parameter-Models-with-Simple-and-Efficie)
4. [Mixture of Experts, LLM Tutorial ch. 11](https://llm-tutorial.darvinyi.com/ch11-moe/)
5. [Mixture-of-Experts, from the router to the all-to-all, thesatyajit.com](https://ai.thesatyajit.com/architectures/mixture-of-experts)
6. [MegaBlocks: Efficient Sparse Training with Mixture-of-Experts, arXiv:2211.15841](https://arxiv.org/abs/2211.15841)
7. [Mixture of Experts (DeepSpeed MoE), DeepSpeed documentation](https://deepspeed.readthedocs.io/en/latest/moe.html)
8. [Accelerating Dropless MoE Training in JAX with NVIDIA Transformer Engine, NVIDIA Technical Blog](https://developer.nvidia.com/blog/accelerating-dropless-moe-training-in-jax-with-nvidia-transformer-engine/)
9. [Switch Transformer, AI Wiki](https://aiwiki.ai/wiki/switch_transformer)
10. [Different top-2 routing paradigms analysis, Findings of ACL 2025](https://aclanthology.org/2025.findings-acl.653.pdf)
11. [Mixture-of-Experts with Expert Choice Routing, NeurIPS 2022](https://proceedings.neurips.cc/paper_files/paper/2022/file/2f00ecd787b432c1d36f3de9800728eb-Paper-Conference.pdf)
12. [Switch Transformers Interactive Guide, Papermap](https://papermap.vercel.app/paper/Switch_Transformers_Scaling_to_Trillion_Parameter_Models.html)
13. [DeepSpeed MoE tutorial, GitHub](https://github.com/deepspeedai/DeepSpeed/blob/master/docs/_tutorials/mixture-of-experts.md)
14. [DeepSpeed MoE NLG tutorial, GitHub](https://github.com/deepspeedai/DeepSpeed/blob/master/docs/_tutorials/mixture-of-experts-nlg.md)
15. [MoE Parallel Folding, arXiv:2504.14960](https://arxiv.org/abs/2504.14960)
16. [Mixture-of-Experts with Expert Choice Routing, Google Research blog](https://www.research.google/blog/mixture-of-experts-with-expert-choice-routing/)
17. [DeepSpeed Data Efficiency, deepspeed.ai](https://www.deepspeed.ai/2022/12/11/data-efficiency.html)
18. [jmlr.org](https://jmlr.org/papers/volume23/21-0998/21-0998.pdf)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 现代人工智能：基础模型、生成式人工智能与人工智能产业 › Foundation-model methods and training › Large language model architecture and scaling

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/token-dropping

English original: https://www.edgepedia.org/token-dropping
