[{"data":1,"prerenderedAt":403},["ShallowReactive",2],{"content-query-WnzIpNChPy":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"body":13,"_type":397,"_id":398,"_source":399,"_file":400,"_stem":401,"_extension":402},"/news/zh/2880","zh",false,"","【昇思MindSpore技术公开课】请查收第三讲ChatGLM2知识点回顾","昇思MindSpore公开课大模型专题第二季课程火爆来袭！","2023-11-15","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/11/25/6b2de079e17a416b8c03cab5f935d65b.png","news",{"type":14,"children":15,"toc":389},"root",[16,24,36,48,53,61,69,77,96,106,113,118,123,128,133,141,158,163,168,175,183,188,198,214,224,236,244,249,254,264,269,274,279,284,292,304,309,316,324,332,342,347,356,361,369,377],{"type":17,"tag":18,"props":19,"children":21},"element","h1",{"id":20},"昇思mindspore技术公开课请查收第三讲chatglm2知识点回顾",[22],{"type":23,"value":8},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28,30],{"type":23,"value":29},"昇思MindSpore公开课大模型专题第二季课程火爆来袭！未报名的小伙伴抓紧时间扫描下方二维码参与课程，并同步加入课程群，有免费丰富的课程资源在等着你。",{"type":17,"tag":31,"props":32,"children":33},"strong",{},[34],{"type":23,"value":35},"课程同步赋能华为ICT大赛2023-2024，欢迎大家报名参与！",{"type":17,"tag":25,"props":37,"children":38},{},[39],{"type":17,"tag":31,"props":40,"children":41},{},[42],{"type":17,"tag":43,"props":44,"children":47},"img",{"alt":45,"src":46},"image.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231124033333.40940094066986794994713636696191:50541124055719:2400:ACD974FD9894500476F3049E4352DED5D5B81E1F59F6B92B5C897B1ED62F1072.png",[],{"type":17,"tag":25,"props":49,"children":50},{},[51],{"type":23,"value":52},"上周六的第三节课程中，我们讲解了从ChatGLM到ChatGLM2的技术改进点，同时带领大家在OpenI启智社区云脑算力上，使用Ascend+ModelArts+MindSpore部署ChatGLM2聊天机器人，并且介绍了最近开源的ChatGLM3的相关特性。下面我们对本节课程知识点进行简单总结，迎接下一节课程的继续深入。",{"type":17,"tag":25,"props":54,"children":55},{},[56],{"type":17,"tag":31,"props":57,"children":58},{},[59],{"type":23,"value":60},"一、",{"type":17,"tag":25,"props":62,"children":63},{},[64],{"type":17,"tag":31,"props":65,"children":66},{},[67],{"type":23,"value":68},"课程回顾",{"type":17,"tag":25,"props":70,"children":71},{},[72],{"type":17,"tag":31,"props":73,"children":74},{},[75],{"type":23,"value":76},"1、ChatGLM2技术改进点解析",{"type":17,"tag":25,"props":78,"children":79},{},[80,82,87,89,94],{"type":23,"value":81},"ChatGLM2在ChatGLM基础上，除了使用更大的训练数据达到更好的模型效果，以及使用了更开源的协议外，最重要两点便是引入了",{"type":17,"tag":31,"props":83,"children":84},{},[85],{"type":23,"value":86},"Multi-Query Atttention",{"type":23,"value":88},"和",{"type":17,"tag":31,"props":90,"children":91},{},[92],{"type":23,"value":93},"FlashAttention",{"type":23,"value":95},"算法。",{"type":17,"tag":97,"props":98,"children":100},"h3",{"id":99},"_11-multi-query-attentionmqa",[101],{"type":17,"tag":31,"props":102,"children":103},{},[104],{"type":23,"value":105},"1.1 Multi-Query Attention（MQA）",{"type":17,"tag":25,"props":107,"children":108},{},[109],{"type":17,"tag":43,"props":110,"children":112},{"alt":45,"src":111},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231124033409.39198527976519713008163735189615:50541124055719:2400:5664A8F90E8858C4CFA08237FB7F247E4185F4BEDD82BB299C6CC7CAAD448552.png",[],{"type":17,"tag":25,"props":114,"children":115},{},[116],{"type":23,"value":117},"**Motivation：**为了解决Transformer结构的模型decoder进行incremental inference推理性能较慢的问题。",{"type":17,"tag":25,"props":119,"children":120},{},[121],{"type":23,"value":122},"**Method：**在Multi-Head Attention（MHA）上做出了微小调整，所有头共享一对key和value，从而减少keys和values的缓存。",{"type":17,"tag":25,"props":124,"children":125},{},[126],{"type":23,"value":127},"**Result：**有效提升了decoder推理速度，但在模型效果上稍差于MHA。",{"type":17,"tag":25,"props":129,"children":130},{},[131],{"type":23,"value":132},"**Development：**后续演变出了Grouped-Query Attention，多个query一组，共享一对key和value，这种方式下模型推理速度高于MHA，但模型效果优于MQA。",{"type":17,"tag":25,"props":134,"children":135},{},[136],{"type":17,"tag":31,"props":137,"children":138},{},[139],{"type":23,"value":140},"1.2 FlashAttention",{"type":17,"tag":25,"props":142,"children":143},{},[144,156],{"type":17,"tag":31,"props":145,"children":146},{},[147,149,154],{"type":23,"value":148},"Motivation：",{"type":17,"tag":31,"props":150,"children":151},{},[152],{"type":23,"value":153},"更侧重",{"type":23,"value":155},"硬件层面",{"type":23,"value":157},"的优化，为了解决Transformer结构的模型时间和空间复杂度会随输入序列长度增长而进行二次增长的问题。",{"type":17,"tag":25,"props":159,"children":160},{},[161],{"type":23,"value":162},"**Previous work：**自注意力计算矩阵稀疏化（sparse transformer）、降维（low-rank transformer）等，但计算出的attention并不是精确值。",{"type":17,"tag":25,"props":164,"children":165},{},[166],{"type":23,"value":167},"**Method：**减少访问GPU显存的时间，原本为访问HBM，调整为访问SRAM。",{"type":17,"tag":25,"props":169,"children":170},{},[171],{"type":17,"tag":43,"props":172,"children":174},{"alt":45,"src":173},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231124033426.48057139286810958637734182328538:50541124055719:2400:051D29DEEBAA3D4C428FE561D05A506E319B40A26DC065F5CDDE50F78F966386.png",[],{"type":17,"tag":25,"props":176,"children":177},{},[178],{"type":17,"tag":43,"props":179,"children":182},{"alt":180,"src":181},"cke_5338.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231124033519.92396604688200465265656456146221:50541124055719:2400:341054BDAF7958D9B28C9D4E069548054C1E8A86B1E67BEC075C8E8B53E9865A.png",[],{"type":17,"tag":25,"props":184,"children":185},{},[186],{"type":23,"value":187},"**Result：**训练速度同比提升了到了3倍以上。",{"type":17,"tag":25,"props":189,"children":190},{},[191,193],{"type":23,"value":192},"**2、**",{"type":17,"tag":31,"props":194,"children":195},{},[196],{"type":23,"value":197},"使用NPU+MindSpore Transformers试用ChatGLM2推理部署",{"type":17,"tag":25,"props":199,"children":200},{},[201,203,212],{"type":23,"value":202},"环境配置：MindSpore 2.0.0， MindSpore Transformers dev（具体操作与ChatGLM的推理相似，此处不做赘述，详见",{"type":17,"tag":204,"props":205,"children":209},"a",{"href":206,"rel":207},"http://mp.weixin.qq.com/s?__biz=MzkxMTM2MjMzNg==&mid=2247610125&idx=1&sn=e9d82d50cf0feb5d658d97bf21d421b9&chksm=c11e3f42f669b6543635140c0b534bda95abafbfa5c6f18f1a1e0d79fa8c3ff1024c5eb68bff&scene=21#wechat_redirect",[208],"nofollow",[210],{"type":23,"value":211},"第一讲ChatGLM课程回顾",{"type":23,"value":213},"）",{"type":17,"tag":25,"props":215,"children":216},{},[217,219],{"type":23,"value":218},"**3、**",{"type":17,"tag":31,"props":220,"children":221},{},[222],{"type":23,"value":223},"ChatGLM3特性介绍",{"type":17,"tag":25,"props":225,"children":226},{},[227,229,234],{"type":23,"value":228},"ChatGLM3相比ChatGLM2，使用了",{"type":17,"tag":31,"props":230,"children":231},{},[232],{"type":23,"value":233},"全新的prompt设计",{"type":23,"value":235},"，并且可以原生支持**工具调用（Function Call）、代码执行（Code Interpreter）**和 Agent 任务等复杂场景。",{"type":17,"tag":25,"props":237,"children":238},{},[239],{"type":17,"tag":31,"props":240,"children":241},{},[242],{"type":23,"value":243},"3.1 全新的prompt设计",{"type":17,"tag":25,"props":245,"children":246},{},[247],{"type":23,"value":248},"**Previous work：**自然语言prompt格式，但不好进行多轮训练，并且无法进行原生工具调用。",{"type":17,"tag":25,"props":250,"children":251},{},[252],{"type":23,"value":253},"**Method：**引入了4种special tokens。",{"type":17,"tag":25,"props":255,"children":256},{},[257],{"type":17,"tag":31,"props":258,"children":259},{},[260],{"type":17,"tag":43,"props":261,"children":263},{"alt":45,"src":262},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231124033540.32566946414903290713094822348805:50541124055719:2400:DD15D09002882DD8EDCA064EEE661A0BB4F8D4C880A722C0C2120804940AA658.png",[],{"type":17,"tag":25,"props":265,"children":266},{},[267],{"type":23,"value":268},"**\u003C|system|>：**系统信息，模型设定扮演的角色。",{"type":17,"tag":25,"props":270,"children":271},{},[272],{"type":23,"value":273},"**\u003C|user|>：**用户输入，可以用于定位模型生成结束。",{"type":17,"tag":25,"props":275,"children":276},{},[277],{"type":23,"value":278},"**\u003C|assistant|>：**AI 助手，模型输出，在出现之前必须有一个来自 \u003C|user|> 的信息。",{"type":17,"tag":25,"props":280,"children":281},{},[282],{"type":23,"value":283},"**\u003C|observation|>：**外部（例如调用工具）的返回结果，\u003C|assistant|> 信息之后，同样可以用于定位模型生成结束。",{"type":17,"tag":25,"props":285,"children":286},{},[287],{"type":17,"tag":31,"props":288,"children":289},{},[290],{"type":23,"value":291},"3.2 工具调用模式与代码解释器模式",{"type":17,"tag":25,"props":293,"children":294},{},[295,297,302],{"type":23,"value":296},"**工具模式：",{"type":17,"tag":31,"props":298,"children":299},{},[300],{"type":23,"value":301},"模型可进行工具调用，通过",{"type":23,"value":303},"\u003C|system|>**中指定模型可调用的工具，可自行添加注册新的工具。",{"type":17,"tag":25,"props":305,"children":306},{},[307],{"type":23,"value":308},"**代码解释器模式：**提供代码运行环境，可进行图案绘画、数学计算等复杂运算。",{"type":17,"tag":25,"props":310,"children":311},{},[312],{"type":17,"tag":43,"props":313,"children":315},{"alt":45,"src":314},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231124033601.11457971730139074464930260521976:50541124055719:2400:5CDC220D66718DA4F4074DB8CBB339D05D631CB262AEAA1541CD0C5C4C8C596E.png",[],{"type":17,"tag":25,"props":317,"children":318},{},[319],{"type":17,"tag":31,"props":320,"children":321},{},[322],{"type":23,"value":323},"二、",{"type":17,"tag":25,"props":325,"children":326},{},[327],{"type":17,"tag":31,"props":328,"children":329},{},[330],{"type":23,"value":331},"课后练习",{"type":17,"tag":333,"props":334,"children":336},"h2",{"id":335},"_1-chatglm2推理部署代码试运行",[337],{"type":17,"tag":31,"props":338,"children":339},{},[340],{"type":23,"value":341},"1、 ChatGLM2推理部署代码试运行",{"type":17,"tag":25,"props":343,"children":344},{},[345],{"type":23,"value":346},"运行ChatGLM2推理部署代码，尝试和模型进行对话（如果出现回复不理想的情况，也欢迎在代码仓issue中进行反馈）",{"type":17,"tag":333,"props":348,"children":350},{"id":349},"_2-chatglm3试用",[351],{"type":17,"tag":31,"props":352,"children":353},{},[354],{"type":23,"value":355},"2、 ChatGLM3试用",{"type":17,"tag":25,"props":357,"children":358},{},[359],{"type":23,"value":360},"尝试ChatGLM3的各种模式对话",{"type":17,"tag":25,"props":362,"children":363},{},[364],{"type":17,"tag":31,"props":365,"children":366},{},[367],{"type":23,"value":368},"三、",{"type":17,"tag":25,"props":370,"children":371},{},[372],{"type":17,"tag":31,"props":373,"children":374},{},[375],{"type":23,"value":376},"下节课预告",{"type":17,"tag":25,"props":378,"children":379},{},[380,382,387],{"type":23,"value":381},"昇思MindSpore技术公开课第二期的第四讲将在",{"type":17,"tag":31,"props":383,"children":384},{},[385],{"type":23,"value":386},"11月25日（周六）14：00-15：30",{"type":23,"value":388},"与大家见面。为大家带来文本生成解码原理（包括采样、Beam search等）的讲解与代码演示，敬请期待！",{"title":7,"searchDepth":390,"depth":390,"links":391},4,[392,394,396],{"id":99,"depth":393,"text":105},3,{"id":335,"depth":395,"text":341},2,{"id":349,"depth":395,"text":355},"markdown","content:news:zh:2880.md","content","news/zh/2880.md","news/zh/2880","md",1776506075086]