从LLM角度学习和了解MoE架构

MoE是目前国内LLM采用的技术路线,Deepseek R1、Qwen3、GLM4都采用了MoE架构。

这里尝试理解什么是MoE,以及MoE有哪些优点和缺点,后续分析为什么这么多LLM采用MoE。

1 什么是MoE

MoE,全称为Mixed Expert Models,1991年论文Adaptive Mixture of Local Exports提出。

1.1 MoE示例

在相同计算资源和参数量条件下,MoE模型与Dense模型相比,训练速度更快。

也就是说,MoE由于训练效率的提升,可以是更大的模型。

比如Google Switch Transformer模型,大小是T5-XXL的15倍,相比T5-XXL模型快4倍达到固定困惑度PPL。

In deep learning, models typically reuse the same parameters for all inputs. Mixture of Experts (MoE) models defy this and instead select different parameters for each incoming example. The result is a sparsely-activated model---with an outrageous number of parameters---but a constant computational cost. However, despite several notable successes of MoE, widespread adoption has been hindered by complexity, communication costs, and training instability. We address these with the introduction of the Switch Transformer. We simplify the MoE routing algorithm and design intuitive improved models with reduced communication and computational costs. Our proposed training techniques mitigate the instabilities, and we show large sparse models may be trained, for the first time, with lower precision (bfloat16) formats. We design models based off T5-Base and T5 Large (Raffel et al., 2019) to obtain up to 7x increases in pre-training speed with the same computational resources. These improvements extend into multilingual settings where we measure gains over the mT5-Base version across all 101 languages. Finally, we advance the current scale of language models by pre-training up to trillion parameter models on the "Colossal Clean Crawled Corpus", and achieve a 4x speedup over the T5-XXL model.

https://arxiv.org/pdf/2101.03961

在相同计算预算条件下,MoE可以显著扩大模型的规模。特别是在预训练阶段,与稠密模型相比,混合专家模型通常能够更快地达到相同的质量水平。

1.2 MoE架构

MoE基于Transformer架构,主要由两部分组成:稀疏MoE层、token路由。

稀疏 MoE 层,MoE 层包含若干"专家"(如 8 个),每个专家本身是一个独立的神经网络,用于代替经典Transformer模型的前馈网络 (FFN) 层。实际应用中,这些专家通常是更简单的FFN,也可以是其他网络。

token路由,用于决定哪些token激活哪个专家。如下图所示,token "More"可能激活第二个专家,而"Parameters" 被激活第一个专家。一个 token 甚至能激活多个专家。token路由是MoE的一个关键点,路由器包含学习参数,与网络其他部分一同进行训练。

2 MoE优点

MoE与Dense模型相比,训练速度更快,可以训练更大的模型,如Google的Switch Transformer。

DeepSeek的16B MoE模型,仅消耗**40%**计算预算,就达到与LLaMA2 7B差不多的效果。

MoE优点总结如下:

1)训练速度更快,效果更好

2)推理成本低,只需要激活部分的参数参数运算

3)可以较容易扩展到更大的模型,计算预算不变,可以增加参数量。

4)多任务学习,如Switch Transformer在101种语言获得性能提升,具备较好的多任务学习能力。

3 MoE缺点

当然MoE也有缺点,总结如下

1)训练稳定性差,这与MoE的架构有关,在训练中可能会遇到稳定性问题。

2)通信开销大,MoE的专家路由机制,可能会增加通信成本,特别是在分布式训练环境中。

3)模型复杂,模型参数增加,嫌贵那贵的模型设计就会相对复杂,需要均衡和取舍。

4)下游任务容易过拟合,MoE由于其稀疏性,在微调时更容易过拟合,当然这不一定全是坏处,需要依据具体问题取舍和优化。

reference


Switch Transformers: Scaling to Trillion Parameter Models

https://arxiv.org/pdf/2101.03961

MoE(Mixture-of-Experts)大模型架构的优势是什么?为什么?

https://www.zhihu.com/tardis/bd/ans/3364787819

Adaptive Mixtures of Local Experts

https://www.cs.toronto.edu/~hinton/absps/jjnh91.pdf

相关推荐
冬奇Lab14 分钟前
让 AI Agent 更可靠:Harness Engineering 与多 Agent 系统工程实践
人工智能·llm·agent
放下华子我只抽RuiKe514 分钟前
React 从入门到生产(四):自定义 Hook
前端·javascript·人工智能·深度学习·react.js·自然语言处理·前端框架
想你依然心痛15 分钟前
HarmonyOS 6(API 23)实战:基于悬浮导航、沉浸光感与HMAF的“文思智脑“——PC端AI智能体沉浸式智能写作工作台
人工智能·ar·harmonyos·ai写作
冬奇Lab16 分钟前
一天一个开源项目(第108篇):Andrej Karpathy Skills - 用一个 CLAUDE.md 文件修复 LLM 编码的四个顽疾
人工智能·开源·资讯
涛声依旧-底层原理研究所17 分钟前
残差连接与层归一化通俗易懂的详解
人工智能·python·神经网络·transformer
fantasy_arch1 小时前
pytorch人脸匹配模型
人工智能·pytorch·python
科技那些事儿1 小时前
实时洞察,视觉赋能:国内情绪识别API公司推荐及计算机视觉流派深度解析
人工智能·计算机视觉
LuminousCPP1 小时前
数据结构 - 线性表第四篇:C 语言通讯录优化升级全记录(踩坑 + 思考)
c语言·开发语言·数据结构·经验分享·笔记·学习
魔法阵维护师1 小时前
从零开发游戏需要学习的c#模块,第十四章(保存和加载)
学习·游戏·c#