[{"data":1,"prerenderedAt":689},["ShallowReactive",2],{"content-query-tDE7jOMWg7":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"body":13,"_type":683,"_id":684,"_source":685,"_file":686,"_stem":687,"_extension":688},"/technology-blogs/zh/2773","zh",false,"","LLM终身学习的可能性——Mixture of Experts","在ChatGPT发布后的三个季度，人们对LLM的态度也从追捧到狂热再到冷静。随着开源社区不断的推陈出新，以及各个厂商各类Chat-LLM的不断发布，大家的目光也逐渐朝着LLM的实用性转移。","2023-09-15","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/09/15/506ae8f3ee37455caea47b74bd61a62f.png","technology-blogs",{"type":14,"children":15,"toc":673},"root",[16,24,30,37,53,58,63,68,73,78,83,88,93,98,103,108,113,118,123,128,133,137,142,146,151,156,160,164,169,173,178,183,187,192,197,201,205,210,214,218,223,228,233,239,246,260,269,277,285,290,296,310,315,323,328,333,338,343,351,356,364,369,374,379,384,389,394,399,404,409,414,419,424,429,434,442,447,452,457,462,467,472,477,482,490,495,500,505,510,518,523,528,533,538,543,548,553,558,563,568,573,578,583,588,593,598,603,614,625,630,635,646,657,662],{"type":17,"tag":18,"props":19,"children":21},"element","h1",{"id":20},"llm终身学习的可能性mixture-of-experts",[22],{"type":23,"value":8},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28],{"type":23,"value":29},"在ChatGPT发布后的三个季度，人们对LLM的态度也从追捧到狂热再到冷静。随着开源社区不断的推陈出新，以及各个厂商各类Chat-LLM的不断发布，大家的目光也逐渐朝着LLM的实用性转移。LLM的训练是一个非常耗费资源的事项，不管是出于降本增效还是环保的考虑，包括LLM高效预训练、高效参数微调、无损量化等等方向都广受关注。但是这次我们来看一个似乎没那么热门但又很水到渠成的话题——LLM lifelong learning。",{"type":17,"tag":31,"props":32,"children":34},"h2",{"id":33},"continual-lifelong-learning",[35],{"type":23,"value":36},"Continual lifelong learning",{"type":17,"tag":25,"props":38,"children":39},{},[40,42,51],{"type":23,"value":41},"Lifelong learning的概念其实很好理解，人工智能是为了构造拟人化的智能体，那么很自然地会想要让模型能够像人一样不断接受新的事物并学习，而非进行模型训练后仅能在一个或多个task使用，而无法持续更新的方法。和其他的学习范式一样，实际上在学术界Lifelong learning(Continual learning, CL)也算是个自成一脉的子领域，但是本身又和很多领域有很大程度的交叉，这里援引20年一篇survey",{"type":17,"tag":43,"props":44,"children":48},"a",{"href":45,"rel":46},"https://zhuanlan.zhihu.com/p/650394454#ref_1",[47],"nofollow",[49],{"type":23,"value":50},"[1]",{"type":23,"value":52},"来简要介绍下Lifelong learning的概念。",{"type":17,"tag":25,"props":54,"children":55},{},[56],{"type":23,"value":57},"持续学习的目标是在模型持续输入学习新数据的同时避免旧知识的遗忘，这里摘出几个性质及其定义：",{"type":17,"tag":25,"props":59,"children":60},{},[61],{"type":23,"value":62},"性质",{"type":17,"tag":25,"props":64,"children":65},{},[66],{"type":23,"value":67},"定义",{"type":17,"tag":25,"props":69,"children":70},{},[71],{"type":23,"value":72},"知识记忆(knowledge retention)",{"type":17,"tag":25,"props":74,"children":75},{},[76],{"type":23,"value":77},"模型不易产生遗忘灾难",{"type":17,"tag":25,"props":79,"children":80},{},[81],{"type":23,"value":82},"前向迁移(forward transfer)",{"type":17,"tag":25,"props":84,"children":85},{},[86],{"type":23,"value":87},"利用旧知识学习新任务",{"type":17,"tag":25,"props":89,"children":90},{},[91],{"type":23,"value":92},"后向迁移(backward transfer)",{"type":17,"tag":25,"props":94,"children":95},{},[96],{"type":23,"value":97},"新任务学习后提升旧任务",{"type":17,"tag":25,"props":99,"children":100},{},[101],{"type":23,"value":102},"在线学习(online learning)",{"type":17,"tag":25,"props":104,"children":105},{},[106],{"type":23,"value":107},"连续数据流学习",{"type":17,"tag":25,"props":109,"children":110},{},[111],{"type":23,"value":112},"无任务边界(No task boudaries)",{"type":17,"tag":25,"props":114,"children":115},{},[116],{"type":23,"value":117},"不需要明确的任务或数据定义",{"type":17,"tag":25,"props":119,"children":120},{},[121],{"type":23,"value":122},"固定模型容量(Fixed model capacity)",{"type":17,"tag":25,"props":124,"children":125},{},[126],{"type":23,"value":127},"模型大小不随任务和数据变化",{"type":17,"tag":25,"props":129,"children":130},{},[131],{"type":23,"value":132},"Survey里还列举了各学习范式具备的性质和常见的一些持续学习方法，由于是2020年的论文，这里就不再赘述，只使用同样的形式来看看LLM所具备的性质。",{"type":17,"tag":25,"props":134,"children":135},{},[136],{"type":23,"value":62},{"type":17,"tag":25,"props":138,"children":139},{},[140],{"type":23,"value":141},"说明",{"type":17,"tag":25,"props":143,"children":144},{},[145],{"type":23,"value":72},{"type":17,"tag":25,"props":147,"children":148},{},[149],{"type":23,"value":150},"√",{"type":17,"tag":25,"props":152,"children":153},{},[154],{"type":23,"value":155},"LLM预训练后，具备世界知识，小规模finetune不易对LLM造成遗忘灾难。但大规模数据续训会造成。",{"type":17,"tag":25,"props":157,"children":158},{},[159],{"type":23,"value":82},{"type":17,"tag":25,"props":161,"children":162},{},[163],{"type":23,"value":150},{"type":17,"tag":25,"props":165,"children":166},{},[167],{"type":23,"value":168},"基于世界知识的Zero shot、few shot、finetune。",{"type":17,"tag":25,"props":170,"children":171},{},[172],{"type":23,"value":92},{"type":17,"tag":25,"props":174,"children":175},{},[176],{"type":23,"value":177},"-",{"type":17,"tag":25,"props":179,"children":180},{},[181],{"type":23,"value":182},"Finetune后会可能会造成部分任务的性能下降。二次finetune会损失首次finetune性能。",{"type":17,"tag":25,"props":184,"children":185},{},[186],{"type":23,"value":102},{"type":17,"tag":25,"props":188,"children":189},{},[190],{"type":23,"value":191},"×",{"type":17,"tag":25,"props":193,"children":194},{},[195],{"type":23,"value":196},"离线预训练、微调。",{"type":17,"tag":25,"props":198,"children":199},{},[200],{"type":23,"value":112},{"type":17,"tag":25,"props":202,"children":203},{},[204],{"type":23,"value":150},{"type":17,"tag":25,"props":206,"children":207},{},[208],{"type":23,"value":209},"Unsupervised预训练、微调，不区分任务。",{"type":17,"tag":25,"props":211,"children":212},{},[213],{"type":23,"value":122},{"type":17,"tag":25,"props":215,"children":216},{},[217],{"type":23,"value":150},{"type":17,"tag":25,"props":219,"children":220},{},[221],{"type":23,"value":222},"LLM预训练后大小不变。",{"type":17,"tag":25,"props":224,"children":225},{},[226],{"type":23,"value":227},"从上表可以看出，LLM实际上已经满足了大部分持续学习的性质，百亿千亿级别的大模型经过充足的预训练后，具备大量世界知识以及涌现能力，基于此进行终身学习成为可能。",{"type":17,"tag":25,"props":229,"children":230},{},[231],{"type":23,"value":232},"那么LLM的终身学习应该使用什么方法呢？常见的持续学习方法，包括Rehearsal（排练）, Regularization（正则）, Architectural（结构改造）等方式在LLM的参数量和训练模式下其实都不太适用。而LLM本身为了增大参数量和减少推理成本的混合专家方法(Mixture of Experts, MoE) 似乎成了LLM终身学习的新途径。",{"type":17,"tag":31,"props":234,"children":236},{"id":235},"moe的前世今生",[237],{"type":23,"value":238},"MoE的前世今生",{"type":17,"tag":240,"props":241,"children":243},"h3",{"id":242},"vanilla-moe",[244],{"type":23,"value":245},"Vanilla MoE",{"type":17,"tag":25,"props":247,"children":248},{},[249,251,258],{"type":23,"value":250},"MoE是一个已经有30多年历史，且十分实用的技术。最早的MoE更多地类似于ensemble的概念，即：使用多个模型来共同提高任务性能。在实际的数据分布中，存在着很多天然的子集，如不同的domain、topic，不同的语言、不同的模态等等，在使用单个模型进行学习，且模型capacity较小的情况下，不同子集会起到噪声的作用，干扰模型的拟合，导致模型训练慢、泛化困难。MoE的思想就是构造多个模型（每个模型称为专家Expert），将不同子集的数据分发到不同模型进行训练，减少不同类型样本间的干扰。下图是经典的MoE",{"type":17,"tag":43,"props":252,"children":255},{"href":253,"rel":254},"https://zhuanlan.zhihu.com/p/650394454#ref_2",[47],[256],{"type":23,"value":257},"[2]",{"type":23,"value":259},"示意图：",{"type":17,"tag":25,"props":261,"children":262},{},[263],{"type":17,"tag":264,"props":265,"children":268},"img",{"alt":266,"src":267},"01.PNG","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/db4/56d/a8a/eec5c1d6d9db456da8a487db9c1c265b.20230915063815.53818458136910211411968980949245:50540914071323:2400:B97A7E9CA114F40BD6CCEBBFCDDA5CD24D145A7835F8ECDDEBC37BBD3D06DFD5.png",[],{"type":17,"tag":25,"props":270,"children":271},{},[272],{"type":17,"tag":264,"props":273,"children":276},{"alt":274,"src":275},"02.PNG","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/db4/56d/a8a/eec5c1d6d9db456da8a487db9c1c265b.20230915063826.75619758954473975525716348594764:50540914071323:2400:B75AB328F9E28D9D09702E597D96EAB598B50BBDDB39D9B920CA91427064BF81.png",[],{"type":17,"tag":25,"props":278,"children":279},{},[280],{"type":17,"tag":264,"props":281,"children":284},{"alt":282,"src":283},"03.PNG","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/db4/56d/a8a/eec5c1d6d9db456da8a487db9c1c265b.20230915063835.50324330089432085728080301507220:50540914071323:2400:AB0AF8E2DE9D66A601D364993B03DFDE7AAFD44300C67DDF4EFAB148BAFC3CA8.png",[],{"type":17,"tag":25,"props":286,"children":287},{},[288],{"type":23,"value":289},"彼时的MoE思路简单但有效，启发了后续诸多MoE相关工作。Expert的竞争或合作，以及Gating Network的分发方式，也成为了MoE演进过程中不断更迭演进的方向。时间很快到了2017年，当下MoE系统的雏形初现了。",{"type":17,"tag":240,"props":291,"children":293},{"id":292},"sparse-moe",[294],{"type":23,"value":295},"Sparse MoE",{"type":17,"tag":25,"props":297,"children":298},{},[299,301,308],{"type":23,"value":300},"在前Transformer时代，使用RNN构造的神经网络很难做到很大很深，且硬件利用率也不高。Google Brain的Shazeer, Noam, 等人",{"type":17,"tag":43,"props":302,"children":305},{"href":303,"rel":304},"https://zhuanlan.zhihu.com/p/650394454#ref_3",[47],[306],{"type":23,"value":307},"[3]",{"type":23,"value":309},"提出使用稀疏的MoE结构来将模型容量做大的方法，即：训练时使用海量Expert，推理时激活少数Expert。",{"type":17,"tag":25,"props":311,"children":312},{},[313],{"type":23,"value":314},"前文讲到的Vanilla MoE本身要达成的效果便是单样本单Expert处理，因此训练完成后的模型在推理时只会用到很少的Expert，这样在推理阶段实际上能够节省大量的算力资源。因此稀疏的MoE无疑是一种很经济的模型训练策略。下图是Sparse MoE的示例：",{"type":17,"tag":25,"props":316,"children":317},{},[318],{"type":17,"tag":264,"props":319,"children":322},{"alt":320,"src":321},"04.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/db4/56d/a8a/eec5c1d6d9db456da8a487db9c1c265b.20230915063955.30831814568965483450511698826027:50540914071323:2400:BC284F2256252B3C84851E945DFDC8C0FB649845FCBA51BAB3D909A95D25649D.png",[],{"type":17,"tag":25,"props":324,"children":325},{},[326],{"type":23,"value":327},"如图所示，模型共有n个Expert，Gating Network选择少数Expert进行计算。此外，该工作还发现了后续影响MoE研究的一大现象——赢者通吃：在训练过程中前期编号的expert会更容易被gating network选择，导致只有少数几个expert有用，这被称为Expert Balancing问题。这时的Sparse MoE目标方向是将模型做大，以及经济高效地进行训练推理。同年，能够并行训练的Transformer的出现将所有人的目光都汇聚了过去，大模型时代的序幕逐渐升起。",{"type":17,"tag":25,"props":329,"children":330},{},[331],{"type":23,"value":332},"Transformer MoE",{"type":17,"tag":25,"props":334,"children":335},{},[336],{"type":23,"value":337},"Transformer在NLP领域大杀四方，不论是Encoder结构BERT的刷榜，还是Decoder-only GPT在zero shot的大放异彩，大家不停地改进着Transformer模型的结构和效果，也逐渐提升着模型的参数量，直到再次触碰到硬件资源的瓶颈。",{"type":17,"tag":25,"props":339,"children":340},{},[341],{"type":23,"value":342},"当模型参数量到了千亿这个级别以后，再想向上扩展变得愈发困难，经济实用的MoE又被重启。还是Google，提出了GShard[4]，首个将MoE思想拓展到Transformer的工作，而后Siwtch Transformer[5]、GLaM[6]等工作持续改进着Transformer MoE的结构，也将LLM的参数量从千亿推向了万亿级别。",{"type":17,"tag":25,"props":344,"children":345},{},[346],{"type":17,"tag":264,"props":347,"children":350},{"alt":348,"src":349},"05.jpeg","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/db4/56d/a8a/eec5c1d6d9db456da8a487db9c1c265b.20230915064039.89621200841260753124316736631139:50540914071323:2400:B2C79428DC612785D9B36FA970AFE47ED90D7A585ABC53188D2AFA8BA18075E1.jpeg",[],{"type":17,"tag":25,"props":352,"children":353},{},[354],{"type":23,"value":355},"这里我们放一个GLaM的示意图，在Transformer的encoder和decoder中，间隔一个（every other）FFN层，替换成position-wise 的 MoE层。Gating network使用的Top-2路由，选择概率最高的两个expert。",{"type":17,"tag":25,"props":357,"children":358},{},[359],{"type":17,"tag":264,"props":360,"children":363},{"alt":361,"src":362},"06.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/db4/56d/a8a/eec5c1d6d9db456da8a487db9c1c265b.20230915064107.47755273436447931939171375625114:50540914071323:2400:9B72CBE729BC1D11978328BD28AB9C62BCB2AA93F38C8033A3CC16366ECE2F71.png",[],{"type":17,"tag":25,"props":365,"children":366},{},[367],{"type":23,"value":368},"凭借着MoE的稀疏激活能力，GLaM训练了1.2T（1.2万亿）参数，但在推理时仅需要96B(960亿)参数，比起GPT3大约节省了一半的资源，推理速度也大幅提升。后续的大量万亿级参数量的LLM均选择了MoE的方式，甚至近两个月在网络上盛传GPT4也是一个MoE结构。MoE也逐渐成为了LLM的一个重要发展方向。",{"type":17,"tag":25,"props":370,"children":371},{},[372],{"type":23,"value":373},"MoE和Lifelong learning",{"type":17,"tag":25,"props":375,"children":376},{},[377],{"type":23,"value":378},"讲了这么久的MoE，和Lifelong learning又有什么关系呢？这里我们再回顾一下Lifelong learning的目标：模型不断学习持续的信息流来获得在各种任务上都能适用的能力。而当下的LLM通常的做法是什么呢？Finetune或续训。虽然LLM在学习了大量世界知识后，不会因为finetune而产生明显的遗忘灾难问题，但是续训和二次finetune都会降低甚至损伤模型的backward transfer能力。",{"type":17,"tag":25,"props":380,"children":381},{},[382],{"type":23,"value":383},"让我们回过头看一下持续学习的几个性质，LLM本身唯一不具备的便是backward transfer能力。再来看MoE的特点：",{"type":17,"tag":25,"props":385,"children":386},{},[387],{"type":23,"value":388},"多个Expert分别处理不同分布（domain/topic）的数据。",{"type":17,"tag":25,"props":390,"children":391},{},[392],{"type":23,"value":393},"推理仅需要部分Expert。",{"type":17,"tag":25,"props":395,"children":396},{},[397],{"type":23,"value":398},"那么是否可以在LLM持续训练的过程中，通过不断地增添和删减Expert，来实现新知识的学习补充，同时还能保留旧知识训练得到的模型，来达到持续学习的目的，最终实现LLM的终身学习。答案是肯定的。",{"type":17,"tag":25,"props":400,"children":401},{},[402],{"type":23,"value":403},"如果想要实现LLM的终身学习，要满足以下几点：",{"type":17,"tag":25,"props":405,"children":406},{},[407],{"type":23,"value":408},"世界知识底座持续学习。实际上当前Transformer结构的MoE都是Vanilla Transformer的侵入式改造，不论是间隔进行FFN的替换还是Dense+Sparse的连接结构，都是为了保留一部分原始Transformer结构，来保证底层语义可以尽可能进行保持。",{"type":17,"tag":25,"props":410,"children":411},{},[412],{"type":23,"value":413},"Expert可插拔。这一点很好理解，老的Expert不需要的时候要移除，新的Expert要增加。",{"type":17,"tag":25,"props":415,"children":416},{},[417],{"type":23,"value":418},"Gating Network可增删。由于Gating Network本身影响输入的路由分发，实际上在去除Expert时也需要Gating Network进行相应的改变，否则会产生随机路由导致输出结果完全错误的问题。",{"type":17,"tag":25,"props":420,"children":421},{},[422],{"type":23,"value":423},"有了这几点目标后，我们选择两个思路完全不同但又都达成了LLM终身学习的两个工作进行深入解析。",{"type":17,"tag":25,"props":425,"children":426},{},[427],{"type":23,"value":428},"Lifelong-MoE",{"type":17,"tag":25,"props":430,"children":431},{},[432],{"type":23,"value":433},"没错，还是谷歌。MoE和Transformer的持续演进和结合都源于谷歌，Lifelong learning自然也是谷歌打头。Lifelong-MoE[7]是今年5月份的工作，其思路是将旧expert冻结，训练新expert。下图是其模型主要结构。",{"type":17,"tag":25,"props":435,"children":436},{},[437],{"type":17,"tag":264,"props":438,"children":441},{"alt":439,"src":440},"07.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/db4/56d/a8a/eec5c1d6d9db456da8a487db9c1c265b.20230915064220.97740837040394617289577070055013:50540914071323:2400:0777C15C8EFFEB409F8A9A3BE5BBE798DCE325F418F3E42A14C5B98D12C9CAEE.png",[],{"type":17,"tag":25,"props":443,"children":444},{},[445],{"type":23,"value":446},"模型的Lifelong learning策略包含以下步骤：",{"type":17,"tag":25,"props":448,"children":449},{},[450],{"type":23,"value":451},"扩增Expert数量及对应的Gating维度。",{"type":17,"tag":25,"props":453,"children":454},{},[455],{"type":23,"value":456},"冻结旧Expert和对应的Gating维度，只训练新Expert。",{"type":17,"tag":25,"props":458,"children":459},{},[460],{"type":23,"value":461},"使用Output Regularization方法来保证新Expert继承过去学习到的知识。",{"type":17,"tag":25,"props":463,"children":464},{},[465],{"type":23,"value":466},"该方法能够实现LLM终身学习的几个目标，但是由于Gating Network本身也是个可学习的神经网络层，不得不增加了Regularization来解决遗忘灾难问题。但是该工作还是为LLM的Lifelong learning打下了一个很好的基础。",{"type":17,"tag":25,"props":468,"children":469},{},[470],{"type":23,"value":471},"接下来介绍的是稍早一些且思路更加简单粗暴的工作——既然Gating Network可学习难以满足Expert增删的需要，那么手动Gating就好。",{"type":17,"tag":25,"props":473,"children":474},{},[475],{"type":23,"value":476},"PanGu-Sigma",{"type":17,"tag":25,"props":478,"children":479},{},[480],{"type":23,"value":481},"Pangu-sigma[8]是今年3月华为诺亚方舟实验室基于Pangu-alpha模型进行MoE扩充实现的Lifelong-MoE模型。其提出了随机路由专家（RRE）方法，使得Gating Network也可以随着Expert进行裁剪。下图是PanGu-Sigma的示意图：",{"type":17,"tag":25,"props":483,"children":484},{},[485],{"type":17,"tag":264,"props":486,"children":489},{"alt":487,"src":488},"08.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/db4/56d/a8a/eec5c1d6d9db456da8a487db9c1c265b.20230915064306.93869773599231860254499639377164:50540914071323:2400:EAAE5F66B7BBA3A3511E877FEEA3FBBC19AD951A76340424BF8A96277731AD09.png",[],{"type":17,"tag":25,"props":491,"children":492},{},[493],{"type":23,"value":494},"这里着重讲一下RRE的设计。前面提到既然可学习的Gating Network很难裁剪，那么可以简单粗暴地使用手动Gating地方式。RRE就是这样地思路，只是为了缓解过于粗暴的领域区分（持续学习的性质之一就是无任务边界，手动Gating一定程度上违背了这一点），RRE做了双层的设计：",{"type":17,"tag":25,"props":496,"children":497},{},[498],{"type":23,"value":499},"第一层，根据任务分配给不同的专家组（多个expert构成一个专家组，供一个task/domain使用）。",{"type":17,"tag":25,"props":501,"children":502},{},[503],{"type":23,"value":504},"第二层，使用组内随机Gating，让专家组的expert可以负载均衡。",{"type":17,"tag":25,"props":506,"children":507},{},[508],{"type":23,"value":509},"这样带来的好处是显而易见的，只要对专家组进行裁切，可以完全剥离出某个领域的子模型进行推理部署，同时也可以不断地更新迭代新的专家组，实现Lifelong-learning。下图是预训练好的MoE模型进行子模型抽取的示意图。",{"type":17,"tag":25,"props":511,"children":512},{},[513],{"type":17,"tag":264,"props":514,"children":517},{"alt":515,"src":516},"09.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/db4/56d/a8a/eec5c1d6d9db456da8a487db9c1c265b.20230915064432.21561735234688701818947506267714:50540914071323:2400:8AFA1625C6E3319B06BA67E997F7E22257F9423DE2E82120C994FD6C4AA44E2E.png",[],{"type":17,"tag":25,"props":519,"children":520},{},[521],{"type":23,"value":522},"通过这样的设计，PanGu-Sigma能够根据实际需求和场景提取和部署子模型，子模型参数量在百亿量级，可以实现性能、效率、可用性和部署的均衡。",{"type":17,"tag":25,"props":524,"children":525},{},[526],{"type":23,"value":527},"以上两个工作，是Lifelong-MoE的两个典型工作，也分别延续了两家公司LLM的能力。但值得额外一提的是，MoE LLM实际上从训练起点分为了两派，分别是from scratch和from pretrained，而GPT4据称是from scratch的8个Expert集合，某种意义上可能更像是回到了ensemble阶段，更多是为了业务效果而非LLM的持续演进。",{"type":17,"tag":25,"props":529,"children":530},{},[531],{"type":23,"value":532},"MoE的问题",{"type":17,"tag":25,"props":534,"children":535},{},[536],{"type":23,"value":537},"Lifelong-MoE看起来很好用，但是万事皆无完美，但MoE方法本身还是有一些问题，下面进行简单的介绍，也算是后续演进方向的探讨。很多人认为MoE难以训练，也跟这几个问题相关。",{"type":17,"tag":25,"props":539,"children":540},{},[541],{"type":23,"value":542},"MoE结构复杂度",{"type":17,"tag":25,"props":544,"children":545},{},[546],{"type":23,"value":547},"前文讲过，Transformer的MoE会对FFN层进行MoE扩展，但是Transformer结构本身还有Multihead Attention结构，这使得MoE扩展会变成Transformer结构的侵入式改造，而不管是训练前并行化的侵入式改造，还是训练完成后进行子模型的抽取，都会因为复杂的结构而需要投入大量人力（当然，这利好算法工程师）。同时由于结构的复杂，加上LLM的资源要求，可以预见学术界鲜有团队能够持续投入Lifelong-LLM的研究。",{"type":17,"tag":25,"props":549,"children":550},{},[551],{"type":23,"value":552},"Expert balancing",{"type":17,"tag":25,"props":554,"children":555},{},[556],{"type":23,"value":557},"然后回到MoE本身的缺陷，即Expert balancing问题。这个问题可以被归结为两个层面：",{"type":17,"tag":25,"props":559,"children":560},{},[561],{"type":23,"value":562},"物理世界规律造成的不均衡。2-8定律在此，总会有一部分任务或领域占据所有数据的大部分，也一定会有长尾数据，使用等参数量、随机Gating的方式进行强制的均衡分配，实际上也是在伤害模型对现实世界的拟合。",{"type":17,"tag":25,"props":564,"children":565},{},[566],{"type":23,"value":567},"神经网络特点决定的嬴者通吃。Gating Network可学习会很自然的朝着几个拟合较好的Expert进行数据分配，这一点仍需要大量的尝试和研究，也许可以缓解，也许可以解决。",{"type":17,"tag":25,"props":569,"children":570},{},[571],{"type":23,"value":572},"分布式通信问题",{"type":17,"tag":25,"props":574,"children":575},{},[576],{"type":23,"value":577},"最后是比较现实的系统问题，当下的LLM预训练必然是要使用分布式并行切分的，而MoE结构和普通的Dense模型的差异在于，其需要额外的AllToAll通信，来实现数据的路由(Gating)和结果的回收。而AllToAll通信会跨Node（服务器）、跨pod（路由），进而造成大量的通信阻塞问题。如何高效地实现AllToAll通信也成为了诸多框架的演进重点，当下包括Tutel、DeepSpeed-MoE、Fast-MoE、HetuMoE等框架都对其进行了额外的优化加速，如MindSpore等底层框架也加入了硬件耦合的AllToAll优化，但当下对于MoE结构需要的通信加速仍需要持续演进和发展。",{"type":17,"tag":25,"props":579,"children":580},{},[581],{"type":23,"value":582},"展望",{"type":17,"tag":25,"props":584,"children":585},{},[586],{"type":23,"value":587},"不知不觉写成了个小survey，虽然并没有把工作列全，但还是将Lifelong-MoE这一概念进行了较为深入的剖析。从ChatGPT出现到现在，LLM仍旧火热，甚至被奉为第四次工业革命，相信不论是工业界还是学术界，都会持续对LLM进行创新和突破，而LLM的Lifelong learning，也一定会称为LLM推陈出新的动力源泉。",{"type":17,"tag":25,"props":589,"children":590},{},[591],{"type":23,"value":592},"参考",{"type":17,"tag":25,"props":594,"children":595},{},[596],{"type":23,"value":597},"^Biesialska M, Biesialska K, Costa-Jussa M R. Continual lifelong learning in natural language processing: A survey[J]. arXiv preprint arXiv:2012.09823, 2020.",{"type":17,"tag":25,"props":599,"children":600},{},[601],{"type":23,"value":602},"^JACOBS R, JORDAN M, NOWLAN S, 等. Adaptive Mixture of Local Expert[J/OL]. Neural Computation, 1991, 3: 78-88. Adaptive Mixtures of Local Experts | Neural Computation | MIT Press",{"type":17,"tag":25,"props":604,"children":605},{},[606,608],{"type":23,"value":607},"^SHAZEER N, MIRHOSEINI A, MAZIARZ K, 等. Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer[M/OL]. arXiv, 2017[2023-08-15]. ",{"type":17,"tag":43,"props":609,"children":612},{"href":610,"rel":611},"http://arxiv.org/abs/1701.06538",[47],[613],{"type":23,"value":610},{"type":17,"tag":25,"props":615,"children":616},{},[617,619],{"type":23,"value":618},"^LEPIKHIN D, LEE H, XU Y, 等. GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding[M/OL]. arXiv, 2020[2023-08-15]. ",{"type":17,"tag":43,"props":620,"children":623},{"href":621,"rel":622},"http://arxiv.org/abs/2006.16668",[47],[624],{"type":23,"value":621},{"type":17,"tag":25,"props":626,"children":627},{},[628],{"type":23,"value":629},"^FEDUS W, ZOPH B, SHAZEER N. Switch transformers: scaling to trillion parameter models with simple and efficient sparsity[J]. The Journal of Machine Learning Research, 2022, 23(1): 120:5232-120:5270.",{"type":17,"tag":25,"props":631,"children":632},{},[633],{"type":23,"value":634},"^DU N, HUANG Y, DAI A M, 等. GLaM: Efficient Scaling of Language Models with Mixture-of-Experts[C/OL]//Proceedings of the 39th International Conference on Machine Learning. PMLR, 2022: 5547-5569[2023-08-15]. GLaM: Efficient Scaling of Language Models with Mixture-of-Experts",{"type":17,"tag":25,"props":636,"children":637},{},[638,640],{"type":23,"value":639},"^CHEN W, ZHOU Y, DU N, 等. Lifelong Language Pretraining with Distribution-Specialized Experts[M/OL]. arXiv, 2023[2023-08-15]. ",{"type":17,"tag":43,"props":641,"children":644},{"href":642,"rel":643},"http://arxiv.org/abs/2305.12281",[47],[645],{"type":23,"value":642},{"type":17,"tag":25,"props":647,"children":648},{},[649,651],{"type":23,"value":650},"^REN X, ZHOU P, MENG X, 等. PanGu-{\\Sigma}: Towards Trillion Parameter Language Model with Sparse Heterogeneous Computing[M/OL]. arXiv, 2023[2023-08-15]. ",{"type":17,"tag":43,"props":652,"children":655},{"href":653,"rel":654},"http://arxiv.org/abs/2303.10845",[47],[656],{"type":23,"value":653},{"type":17,"tag":25,"props":658,"children":659},{},[660],{"type":23,"value":661},"————————————————",{"type":17,"tag":25,"props":663,"children":664},{},[665,667],{"type":23,"value":666},"转载自：",{"type":17,"tag":43,"props":668,"children":671},{"href":669,"rel":670},"https://zhuanlan.zhihu.com/p/650394454",[47],[672],{"type":23,"value":669},{"title":7,"searchDepth":674,"depth":674,"links":675},4,[676,678],{"id":33,"depth":677,"text":36},2,{"id":235,"depth":677,"text":238,"children":679},[680,682],{"id":242,"depth":681,"text":245},3,{"id":292,"depth":681,"text":295},"markdown","content:technology-blogs:zh:2773.md","content","technology-blogs/zh/2773.md","technology-blogs/zh/2773","md",1776506123138]