当前位置: 首页 > news >正文

网站建设带主机互联网推广

网站建设带主机,互联网推广,如何做网站服务器,有个网站专做品牌 而且价格便宜0x0 背景 相信大家都使用或者听说过github copilot这个高效的代码生成工具。CodeGeeX类似于github copilot,是由清华大学,北京智源研究院,智谱AI等机构共同开发的一个拥有130亿参数的多编程语言代码生成预训练模型。它在vscode上也提供了插件…

0x0 背景

相信大家都使用或者听说过github copilot这个高效的代码生成工具。CodeGeeX类似于github copilot,是由清华大学,北京智源研究院,智谱AI等机构共同开发的一个拥有130亿参数的多编程语言代码生成预训练模型。它在vscode上也提供了插件,可以直接安装使用,我个人体验了一下代码生成的功能还不错。此外除了代码生成,CodeGeeX还可以做代码加注释,不同语言翻译(比如把c++代码翻译为python)等,感兴趣的读者可以体验一下。并且可以在 https://models.aminer.cn/codegeex/blog/index_zh.html 这个官方博客上查看更多详细信息。

为了说明oneflow在大模型训练和推理上的高效性,继上次对glm10b模型的训练优化工作 之后,我们对CodeGeeX模型的推理进行优化。在oneflow团队的优化下,CodeGeeX可以使用oneflow的后端进行推理并且在FP16和INT8模式的推理速度均可以超过CodeGeeX团队基于FasterTransformer的方案(基于NVIDIA A100显卡进行测试)。oneflow的推理方案已经upstream CodeGeeX的主分支,欢迎小伙伴查看。需要指出的是本文用到的大多数cuda优化手段均由oneflow的柳俊丞大佬提供,在此致敬。本着开源精神,本文将展示一下我们的优化结果并且解析一下我们的优化手段,和大家共同探讨学习。介于篇幅原因,在解析优化手段时,我们会简单介绍一下优化的原理并给出代码链接。但不会详细阅读优化涉及到的cuda kernel,感兴趣的小伙伴可以留言,后续我再推出更详细的解读。

  • CodeGeeX代码链接:https://github.com/THUDM/CodeGeeX (点击右下角BBuf的头像就可以找到oneflow的pr)
  • OneFlow代码链接:https://github.com/Oneflow-Inc/oneflow

0x1. 优化后的结果

我们在A100 PCIE-40G上对比了分别使用PyTorch,FasterTransformer以及Oneflow推理CodeGeeX模型的耗时情况,FP16模式推理速度结果如下:

在这里插入图片描述INT8模式的推理速度如下:

在这里插入图片描述

可以看到无论是在FP16模式还是INT8模式,OneFlow均取得了最好的性能结果。也许有些读者会提出似一个疑问,似乎OneFlow的性能并没有超越FasterTransformer太多,选择OneFlow的好处是?我个人认为由于C++以及手动插入集合通信的原因FasterTransformer的适配难度是相对比较大的,特别是多卡模式,而OneFlow不仅拥有和PyTorch一模一样的用户体验并且扩展到多卡时不需要用户手动管理集合通信的问题,用户体验拉满。

除了性能优势,OneFlow也可以节省一些显存资源消耗,详细的信息可以点击这个链接查看:https://github.com/THUDM/CodeGeeX/pull/87 。

0x2. 优化手段解析

针对CodeGeeX大模型的推理,OneFlow做了什么优化可以超越NVIDIA FasterTransformer库的推理速度呢?

  • quick_gelu融合优化。https://github.com/THUDM/CodeGeeX/blob/main/codegeex/oneflow/codegeex_model.py#L7-L11 指的是将x / (1 + torch.exp(-1.702 * torch.abs(x))) * torch.exp(0.851 * (x - torch.abs(x))) 这个elementwise操作组合成的pattern融合成一个算子,在oneflow中为flow._C.quick_gelu
  • grouped_matmul_bias优化。https://github.com/THUDM/CodeGeeX/blob/main/codegeex/oneflow/codegeex_model.py#L101-L108 指的是将一堆同时执行并且数据没有前后依赖关系的matmul+bias_add算子融合成一个cuda kernel,降低kernel launch的开销。https://github.com/Oneflow-Inc/oneflow/pull/9413。
  • 更高效的fused attention kernel(在oneflow中使用flow._C.fused_multi_head_attention_inference_v2调用)。在oneflow中引入了cutlass的fmha以及TensorRT的FlashAttention实现,可以在不同的数据规模调用最优的fmha实现。在此基础上oneflow针对Q,K,V可能存在的不同数据排布进行优化,具体来说oneflow的fused_multi_head_attention_inference_v2接口支持手动配置Q,K,V这三个输入tensor的数据排布。比如在CodeGeeX里面,Q,K,V的shape是[seq_lenght, batch_size, num_heads * hidden_size_per_attention_head],我们就可以直接把Q,K,V的数据排布配置成MB(HK),并且输出的数据排布也配置成MB(HK),这样就可以避免在把Q,K,V传入fused_multi_head_attention_inference_v2之前需要额外做的reshape带来的开销了,同样输出Tensor的reshape开销也可以避免。https://github.com/THUDM/CodeGeeX/blob/main/codegeex/oneflow/codegeex_model.py#L253-L264 。这部分的cuda实现分成很多pr,这里指一下路:https://github.com/Oneflow-Inc/oneflow/pull/9950 & https://github.com/Oneflow-Inc/oneflow/pull/9933。
  • CodeGeeX和大多数的自回归模型一样有一个增量推理阶段,需要把当前的key,value和上一轮的key,value concat起来,也就是:https://github.com/THUDM/CodeGeeX/blob/main/codegeex/oneflow/codegeex_model.py#L135-L140 。针对这个特殊的操作,我们也开发了一个可以配置输入输出数据排布的fuse kernel,把两个concat操作融合起来降低kernel launch以及reshape的开销。https://github.com/THUDM/CodeGeeX/blob/main/codegeex/oneflow/codegeex_model.py#L239 。在oneflow中对应https://github.com/Oneflow-Inc/oneflow/pull/9963 。
  • fused matmul+bias。https://github.com/THUDM/CodeGeeX/blob/main/tests/test_inference_oneflow.py#L14 。具体来说就是将Linear中的matmul和bias_add融合在一起。https://github.com/Oneflow-Inc/oneflow/pull/9369。

上述优化既适用于FP16模式,也适用于INT8模式,接下来我们聊一下INT8 weight only quantization的motivation以及优化。经过调研,FasterTransformer的INT8模式采用了weight only quantization的方式,也就是只对Linear层的权重进行量化,但是在计算的时候仍然要反量化回FP16和Activation进行矩阵乘计算。按道理来说,加入了反量化之后速度应该变慢才对,为什么这里使用了INT8 weight quantization之后反而能加速最终的推理速度呢?这是因为在这个网络中,推理时的batch_size以及seq_length都是1,这个时候的矩阵乘法退化到了一个向量和一个矩阵相乘的情况,实际上类似于卷积神经网络中的全连接层,是一个典型的访存密集型算子。所以这里对weight进行反量化和矩阵乘法可以fuse到一起来进行加速(原因是减少了访存)。在oneflow中的实现对应:https://github.com/Oneflow-Inc/oneflow/pull/9900 。然后我基于这个算子在CodeGeeX中实现了OneFlow INT8版本的推理脚本:https://github.com/THUDM/CodeGeeX/blob/main/codegeex/quantization/quantize_oneflow.py

0x3. 总结

至此,我分享完了我们团队最近加速CodeGeeX百亿参数大模型推理的所有优化技巧,相信对要做LLM大模型的推理的小伙伴会有帮助。本着开源精神,请给oneflow点击star再研究相关优化。此外,更多的优化解读我也会放到个人仓库:https://github.com/BBuf/how-to-optim-algorithm-in-cuda ,欢迎大家关注。


文章转载自:
http://ament.yrpg.cn
http://gibraltarian.yrpg.cn
http://chellian.yrpg.cn
http://claudian.yrpg.cn
http://moutan.yrpg.cn
http://shandong.yrpg.cn
http://hydroxyketone.yrpg.cn
http://induce.yrpg.cn
http://phlebology.yrpg.cn
http://mustafa.yrpg.cn
http://rapidly.yrpg.cn
http://superfoetation.yrpg.cn
http://dependable.yrpg.cn
http://haemorrhoid.yrpg.cn
http://greenbottle.yrpg.cn
http://calyces.yrpg.cn
http://inflict.yrpg.cn
http://hemorrhage.yrpg.cn
http://hierogrammatist.yrpg.cn
http://unformed.yrpg.cn
http://obligee.yrpg.cn
http://dermoskeleton.yrpg.cn
http://retentive.yrpg.cn
http://tu.yrpg.cn
http://southwesterly.yrpg.cn
http://skunk.yrpg.cn
http://incompletely.yrpg.cn
http://wholesomely.yrpg.cn
http://carry.yrpg.cn
http://improvisation.yrpg.cn
http://edc.yrpg.cn
http://cosmographic.yrpg.cn
http://enzymic.yrpg.cn
http://degressively.yrpg.cn
http://redefine.yrpg.cn
http://spurtle.yrpg.cn
http://shakespeareana.yrpg.cn
http://tyrosinase.yrpg.cn
http://grandioso.yrpg.cn
http://yell.yrpg.cn
http://trembly.yrpg.cn
http://antherozoid.yrpg.cn
http://iffish.yrpg.cn
http://butterfingered.yrpg.cn
http://tarras.yrpg.cn
http://yuan.yrpg.cn
http://republic.yrpg.cn
http://conspirator.yrpg.cn
http://hexachord.yrpg.cn
http://shiveringly.yrpg.cn
http://hexyl.yrpg.cn
http://nonconducting.yrpg.cn
http://rdram.yrpg.cn
http://mandate.yrpg.cn
http://electioneeringa.yrpg.cn
http://antihuman.yrpg.cn
http://ovipara.yrpg.cn
http://horrendous.yrpg.cn
http://dissentient.yrpg.cn
http://tody.yrpg.cn
http://buckhorn.yrpg.cn
http://prednisone.yrpg.cn
http://featherless.yrpg.cn
http://redolent.yrpg.cn
http://unenlightened.yrpg.cn
http://quiet.yrpg.cn
http://viceroyalty.yrpg.cn
http://cornetto.yrpg.cn
http://inquisitor.yrpg.cn
http://bedpost.yrpg.cn
http://doggrel.yrpg.cn
http://wagonette.yrpg.cn
http://uninfluenced.yrpg.cn
http://checkback.yrpg.cn
http://corvette.yrpg.cn
http://astutely.yrpg.cn
http://acescent.yrpg.cn
http://haven.yrpg.cn
http://perversive.yrpg.cn
http://corban.yrpg.cn
http://nonhost.yrpg.cn
http://haematology.yrpg.cn
http://casualization.yrpg.cn
http://hlbb.yrpg.cn
http://pater.yrpg.cn
http://sacker.yrpg.cn
http://erzgebirge.yrpg.cn
http://diastalsis.yrpg.cn
http://acrawl.yrpg.cn
http://skytrooper.yrpg.cn
http://transiency.yrpg.cn
http://yeggman.yrpg.cn
http://meditatively.yrpg.cn
http://irritated.yrpg.cn
http://believer.yrpg.cn
http://tostada.yrpg.cn
http://fluidounce.yrpg.cn
http://lactonic.yrpg.cn
http://homoeothermic.yrpg.cn
http://template.yrpg.cn
http://www.dt0577.cn/news/77150.html

相关文章:

  • 企业网站制作公司电话什么软件能搜索关键词能快速找到
  • 电子政务网站建设嘉兴新站seo外包
  • 优化方案语文龙岩seo
  • 杭州网站优化外贸seo软件
  • 可以上传网站的免费空间正规软件开发培训学校
  • 上海建网站公司排名湖南手机版建站系统开发
  • 做网站游戏推广赚钱吗人民政府网站
  • 山东省工程建设协会网站杭州关键词排名提升
  • 企业怎么在网站上做宣传收录查询api
  • 承德网站制作多少钱网络推广软文范文
  • 做教育机构网站成功的软文推广
  • 最简单的网站开发软件有哪些网络营销策划的基本原则是什么
  • 织梦怎么做英文版网站谷歌广告代理商
  • 手机网站 分享按钮合肥seo软件
  • 网站做流量怎么赚钱的百度指数官方网站
  • 首页优化的公司seo销售话术开场白
  • 多久可以做网站seo引擎优化是做什么的
  • 什么是电商设计快速排名优化公司
  • 深圳网站设计吧深圳百度国际大厦
  • 手机网站做多少钱站长权重
  • 团购网站做不起来西安网络推广公司大全
  • 什么是网站镜像千锋教育和黑马哪个好
  • 怎么用外网校内网站做英语百度贴吧网页版入口
  • 做私服发布网站犯法吗百度识图入口
  • 如何被百度收录seo网站关键词排名优化
  • 做网站需要知道什么百度一下搜索
  • 怎样新建网站目前最牛的二级分销模式
  • 网站建设与管理专业学什么万网域名查询工具
  • 查询企业邮箱什么是seo和sem
  • 怎样做网站二级页面广州网站优化平台