我的征尘是星辰大海。。。
The dirt and dust from my pilgrimage forms oceans of stars...
-------当记忆的篇章变得零碎,当追忆的图片变得模糊,我们只能求助于数字存储的永恒的回忆
作者:黄教授
手机视频列表
别再误解MOE了它的专家根本不是你想像的那样
视频
音频
原始脚本
别再误解莫了,他的专家根本不是你想的那样。 当 ChatGPT、Claude 这些大语言模型惊艳世界时,一个问题始终萦绕在工程师心头,如何让模型在变得更强大的同时运行的更快、更省钱?混合专家模型 Moe 被视为解决这一矛盾的秘密武器,但它也常常被误解。 很多人把 Moe 简单理解为一群专家各做各的,以为有专门处理数学的专家、专门写代码的专家。 但事实果真如此吗?如果真是这样,为什么不直接训练一堆小模型拼在一起?在这篇文章中,我们将彻底揭开 Moe 的神秘面纱,澄清关于它的六大常见误解。 你将了解到专家是如何在训练中自发形成的。 门控网络如何智能调度?以及 MoE 是如何通过两大核心优化,在不损失性能的前提下,将计算效率提升数倍。 如果你想真正搞懂这个大模型领域的前沿技术,而不是停留在表面的比喻。 那么这篇文章将为你提供最清晰最深入的解读。 误解一,专家是按知识领域划分的,很多人会想当然的认为,猫中的专家就像现实世界中的专家一样,有负责数学的,有负责化学的。 但实际上,猫的专家分工要精细的多。 在训练过程中,专家们会自发形成对不同语言模式的偏好。 例如,某个专家可能擅长处理主谓宾的语法结构,另一个可能更精通情感色彩的表达,还有的可能专门优化长距离依赖关系。 他们学习的是语言的底层构建块,而不是特定的知识领域。 误解二,专家是预先设定好的,这与第一个误解紧密相关。 MOE 中的专家并不是由工程师预先编程设定的。 我们不会告诉模型,你负责处理动词,你负责处理名词。 相反,专家的专长是在海量数据的训练过程中自然而然形成的。 这是一个完全数据驱动的过程,模型通过自我学习自动分化出不同功能的专家。 误解三,训练方式是分开训练,再拼接另一个常见的误解是。 MOE 事先分别训练多个小模型,然后像拼积木一样把它们组合起来,再加上一个门控网络。 这其实是完全错误的,MOE 是一个端到端训练的整体系统。 门控网络和所有专家在整个训练过程中共同学习、共同进化。 门控网络学会判断在当前语境下应该激活哪个专家,而专家们也根据门控网络的选择信号不断优化自己。 误解四,专家共享同一个 F F N 层,这是一个非常关键的技术细节。 在茂中,每个专家都拥有自己独立的完整的 F F N 前馈网络层。 如果有16个专家,那就有16套完全独立的 F F N 参数矩阵,它们是并列存储和运行的。 这与传统模型只有一个巨大的 F F N 层形成对比。 MOE 通过将门控网络只激活少数专家,大大减少了每次计算的参数量。 误解五,计算量减少是因为减少了层数,这是一个最常见的误解。 有些人以为 MOE 是通过跳层来提速的,但事实并非如此。 MOE 模型的 Transformer 层数与传统模型完全相同,一层都不能少。 计算量的减少来自于单层内部的两大优化,而非减少层数。 计算量减少的两大来源:一、专家 F F N 的参数规模大幅缩减,传统模型的每一层只有一个巨大的 F F N。 假设输入输出维度为4096,升维到16384,其参数量约为1.34亿。 而 MoE 模型在同一层中并列放置多个规模更小的专家 FFM。 例如16个专家,每个专家升维仅到4096,单个专家参数量约3355万。 门控网络每次仅激活1~2个专家,实际计算量从1.34亿骤降至3355万。 这是因为矩阵乘法的计算量与参数数量直接相关,专家 F F N 的矩阵维度变小,计算量自然随之减少。 二,词汇表概率计算的维度被拆分。 在传统模型中,每个 token 都要计算词汇表中所有 token 的概率。 这通常涉及几万个 token 的 softmax 计算,非常耗时。 而 MoE 采用专家分工机制,让每个专家仅负责词汇表的一部分。 例如16个专家,每个只需计算自己负责的几千个 token 的概率。 这再一次大幅减少了最终概率计算的维度和工作量。 MOE 效率提升是双管齐下的结果,专家 F F N 的参数规模更小,且每个专家负责的词汇表范围更窄。 这两个优化共同作用,才实现了在不损失模型能力的前提下,大幅提升计算效率。 误解六,专家一旦被激活就负责所有层,这是一个很容易产生的误解。 很多人以为门控网络在模型入口处选择一个专家后,这个专家就会负责处理这个 token 的所有层。 但事实并非如此,在 MoE 模型中,每一层都是一个独立的 MoE 单元,都拥有自己的门控网络和专家。 当一个 token 流过模型的每一层时,该层的门控网络都会根据当前 token 的表示,独立的重新选择最适合的专家。 这意味着处理同一个 token 时,第一层可能激活专家 A,第二层可能激活专家 B,第三层又可能激活专家 A。 每一层的选择都是动态的,取决于当时 token 的具体状态。 这种机制确保了模型在处理的每个步骤都能获得最合适的专家支持。 总结 MoE 的精髓在于,它不是简单的分而治之,而是通过动态路由和专家分工,在保持模型能力的同时大幅提升计算效率。 他的专家是在训练中自发形成的语言模式处理专家,而非预先设定的知识领域专家。 每个专家都有自己独立的计算单元,通过门控网络的智能调度,共同协作完成语言生成任务。 理解了这些关键点,我们才能真正把握 MoE 的价值所在,避免被一些表面的比喻所误导。 在大模型追求效率的今天,梦无疑是一项里程碑式的技术。 它的核心思想让专业的人做专业的事,也为未来 AI 架构的发展提供了重要启示。
修正脚本
别再误解MoE了,它的专家根本不是你想的那样。 当 ChatGPT、Claude 这些大语言模型惊艳世界时,一个问题始终萦绕在工程师心头,如何让模型在变得更强大的同时运行得更快、更省钱?混合专家模型 Moe 被视为解决这一矛盾的秘密武器,但它也常常被误解。 很多人把 Moe 简单理解为一群专家各做各的,以为有专门处理数学的专家、专门写代码的专家。 但事实果真如此吗?如果真是这样,为什么不直接训练一堆小模型拼在一起?在这篇文章中,我们将彻底揭开 Moe 的神秘面纱,澄清关于它的六大常见误解。 你将了解到专家是如何在训练中自发形成的。 门控网络如何智能调度?以及 MoE 是如何通过两大核心优化,在不损失性能的前提下,将计算效率提升数倍。 如果你想真正搞懂这个大模型领域的前沿技术,而不是停留在表面的比喻。 那么这篇文章将为你提供最清晰最深入的解读。 误解一,专家是按知识领域划分的,很多人会想当然地认为,MoE中的专家就像现实世界中的专家一样,有负责数学的,有负责化学的。 但实际上,MoE的专家分工要精细得多。 在训练过程中,专家们会自发形成对不同语言模式的偏好。 例如,某个专家可能擅长处理主谓宾的语法结构,另一个可能更精通情感色彩的表达,还有的可能专门优化长距离依赖关系。 他们学习的是语言的底层构建块,而不是特定的知识领域。 误解二,专家是预先设定好的,这与第一个误解紧密相关。 MOE 中的专家并不是由工程师预先编程设定的。 我们不会告诉模型,你负责处理动词,你负责处理名词。 相反,专家的专长是在海量数据的训练过程中自然而然形成的。 这是一个完全数据驱动的过程,模型通过自我学习自动分化出不同功能的专家。 误解三,训练方式是分开训练再拼接,这是另一个常见的误解。 MOE 事先分别训练多个小模型,然后像拼积木一样把它们组合起来,再加上一个门控网络。 这其实是完全错误的,MOE 是一个端到端训练的整体系统。 门控网络和所有专家在整个训练过程中共同学习、共同进化。 门控网络学会判断在当前语境下应该激活哪个专家,而专家们也根据门控网络的选择信号不断优化自己。 误解四,专家共享同一个 F F N 层,这是一个非常关键的技术细节。 在MoE中,每个专家都拥有自己独立的完整的 F F N 前馈网络层。 如果有16个专家,那就有16套完全独立的 F F N 参数矩阵,它们是并列存储和运行的。 这与传统模型只有一个巨大的 F F N 层形成对比。 MOE 通过将门控网络只激活少数专家,大大减少了每次计算的参数量。 误解五,计算量减少是因为减少了层数,这是一个最常见的误解。 有些人以为 MOE 是通过跳层来提速的,但事实并非如此。 MOE 模型的 Transformer 层数与传统模型完全相同,一层都不能少。 计算量的减少来自于单层内部的两大优化,而非减少层数。 计算量减少的两大来源:一、专家 F F N 的参数规模大幅缩减,传统模型的每一层只有一个巨大的 F F N。 假设输入输出维度为4096,升维到16384,其参数量约为1.34亿。 而 MoE 模型在同一层中并列放置多个规模更小的专家 F F N。 例如16个专家,每个专家升维仅到4096,单个专家参数量约3355万。 门控网络每次仅激活1~2个专家,实际计算量从1.34亿骤降至3355万。 这是因为矩阵乘法的计算量与参数数量直接相关,专家 F F N 的矩阵维度变小,计算量自然随之减少。 二,词汇表概率计算的维度被拆分。 在传统模型中,每个 token 都要计算词汇表中所有 token 的概率。 这通常涉及几万个 token 的 softmax 计算,非常耗时。 而 MoE 采用专家分工机制,让每个专家仅负责词汇表的一部分。 例如16个专家,每个只需计算自己负责的几千个 token 的概率。 这再一次大幅减少了最终概率计算的维度和工作量。 MOE 效率提升是双管齐下的结果,专家 F F N 的参数规模更小,且每个专家负责的词汇表范围更窄。 这两个优化共同作用,才实现了在不损失模型能力的前提下,大幅提升计算效率。 误解六,专家一旦被激活就负责所有层,这是一个很容易产生的误解。 很多人以为门控网络在模型入口处选择一个专家后,这个专家就会负责处理这个 token 的所有层。 但事实并非如此,在 MoE 模型中,每一层都是一个独立的 MoE 单元,都拥有自己的门控网络和专家。 当一个 token 流过模型的每一层时,该层的门控网络都会根据当前 token 的表示,独立地重新选择最适合的专家。 这意味着处理同一个 token 时,第一层可能激活专家 A,第二层可能激活专家 B,第三层又可能激活专家 A。 每一层的选择都是动态的,取决于当时 token 的具体状态。 这种机制确保了模型在处理的每个步骤都能获得最合适的专家支持。 总结 MoE 的精髓在于,它不是简单地分而治之,而是通过动态路由和专家分工,在保持模型能力的同时大幅提升计算效率。 它的专家是在训练中自发形成的语言模式处理专家,而非预先设定的知识领域专家。 每个专家都有自己独立的计算单元,通过门控网络的智能调度,共同协作完成语言生成任务。 理解了这些关键点,我们才能真正把握 MoE 的价值所在,避免被一些表面的比喻所误导。 在大模型追求效率的今天,MoE无疑是一项里程碑式的技术。 它的核心思想让专业的人做专业的事,也为未来 AI 架构的发展提供了重要启示。
英文翻译
Stop Misunderstanding MoE: Its Experts Are Nothing Like You Think. When large language models like ChatGPT and Claude amazed the world, one question has always lingered in engineers’ minds: how to make models more powerful while running faster and cheaper? The Mixture of Experts (MoE) is seen as a secret weapon to resolve this contradiction, but it is also often misunderstood. Many people simplistically think of MoE as a group of experts each doing their own thing, believing there are experts specialized in math, experts specialized in writing code, and so on. But is that really the case? If so, why not just train a bunch of small models and stitch them together? In this article, we will thoroughly demystify MoE and clarify six common misconceptions about it. You will understand how experts emerge spontaneously during training. How does the gating network intelligently route? And how does MoE, through two core optimizations, multiply computational efficiency several times without sacrificing performance? If you truly want to grasp this cutting-edge technology in the large model domain, rather than staying at superficial analogies, then this article will provide you with the clearest and most in-depth interpretation. **Misconception 1: Experts are divided by knowledge domains.** Many people assume that experts in MoE are like experts in the real world—some handle math, some handle chemistry. But in reality, the division of labor among MoE experts is far more granular. During training, experts spontaneously develop preferences for different language patterns. For example, one expert might be good at handling subject-verb-object grammatical structures, another might be more adept at emotional expression, and yet another might specialize in long-distance dependencies. They learn the underlying building blocks of language, not specific knowledge domains. **Misconception 2: Experts are pre-defined.** This is closely related to the first misconception. Experts in MoE are not pre-programmed by engineers. We do not tell the model, "You handle verbs, you handle nouns." Instead, the specialization of experts naturally emerges during training on massive data. This is a completely data-driven process where the model automatically differentiates experts with different functions through self-learning. **Misconception 3: Training is done by separately training and then splicing.** This is another common misunderstanding. Some think MoE trains multiple small models separately, then combines them like building blocks, adding a gating network on top. This is entirely wrong. MoE is an end-to-end trained holistic system. The gating network and all experts learn and evolve together throughout the training process. The gating network learns to decide which expert to activate in a given context, while experts continually optimize themselves based on the selection signals from the gating network. **Misconception 4: Experts share the same FFN layer.** This is a very critical technical detail. In MoE, each expert has its own independent and complete FFN (Feed-Forward Network) layer. If there are 16 experts, there are 16 completely independent sets of FFN parameter matrices, stored and run in parallel. This contrasts with traditional models that have only one huge FFN layer. By using the gating network to activate only a few experts, MoE greatly reduces the number of parameters involved in each computation. **Misconception 5: The reduction in computation is due to fewer layers.** This is the most common misconception. Some people think MoE speeds up by skipping layers, but that is not the case. MoE models have exactly the same number of Transformer layers as traditional models—not a single layer can be omitted. The reduction in computation comes from two major optimizations within a single layer, not from reducing the number of layers. **Two sources of computation reduction:** 1. The parameter scale of expert FFNs is greatly reduced. In traditional models, each layer has only one huge FFN. Suppose the input/output dimension is 4096, and it is expanded to 16384; the number of parameters is about 134 million. In MoE, multiple smaller expert FFNs are placed in parallel in the same layer. For example, with 16 experts, each expert only expands to 4096, so a single expert has about 33.55 million parameters. The gating network activates only 1–2 experts at a time, reducing the actual computation from 134 million to 33.55 million. This is because the computation of matrix multiplication is directly related to the number of parameters; smaller FFN matrices naturally yield less computation. 2. The dimensionality of vocabulary probability calculation is split. In traditional models, each token must compute probabilities over all tokens in the vocabulary. This typically involves a softmax over tens of thousands of tokens, which is very time-consuming. MoE uses an expert division mechanism, where each expert is responsible for only a part of the vocabulary. For example, with 16 experts, each only computes probabilities over its own subset of a few thousand tokens. This again greatly reduces the dimensionality and workload of the final probability calculation. MoE’s efficiency improvement is a two-pronged result: the expert FFN parameters are smaller, and each expert’s responsibility for the vocabulary is narrower. These two optimizations work together to significantly improve computational efficiency without sacrificing model capability. **Misconception 6: Once an expert is activated, it handles all layers.** This is a misconception easily formed. Many people think that the gating network selects an expert at the entrance of the model, and that expert then handles all layers for that token. But this is not the case. In MoE models, each layer is an independent MoE unit, with its own gating network and experts. When a token flows through each layer of the model, the gating network of that layer independently re-selects the most suitable expert based on the current representation of the token. This means that for the same token, Layer 1 might activate Expert A, Layer 2 might activate Expert B, and Layer 3 might activate Expert A again. The selection for each layer is dynamic, depending on the specific state of the token at that moment. This mechanism ensures that the model gets the most appropriate expert support at every step of processing. **Summary:** The essence of MoE is not simply divide-and-conquer, but through dynamic routing and expert division of labor, it greatly improves computational efficiency while maintaining model capability. Its experts are spontaneously formed language-pattern-processing experts during training, not pre-defined knowledge-domain experts. Each expert has its own independent computational unit, and through the intelligent scheduling of the gating network, they collaborate to complete language generation tasks. Understanding these key points allows us to truly grasp the value of MoE and avoid being misled by superficial analogies. In today's pursuit of efficiency in large models, MoE is undoubtedly a milestone technology. Its core idea—letting professionals do professional work—also provides important inspiration for the future development of AI architectures.
back to top