专栏名称: oldpan博客
老潘的博客,程序员眸中的fantasy life,分享AI技术干货,让大家少走弯路~
目录
相关文章推荐
今天看啥  ›  专栏  ›  oldpan博客

Transformer推理结构简析(Decoder + MHA)

oldpan博客  · 公众号  ·  · 2024-09-09 11:32
    

文章预览

不涉及transformer原理,只看transform结构的具体运行过程,涉及到推理。关于原理细节可参考这篇或者查阅其他相关优秀文章。 0x10 Transformer 基本结构 Transformer由encoder和decoder组成,其中: encoder主要负责理解(understanding)  The encoder’s role is to generate a rich representation (embedding) of the input sequence, which the decoder can use if needed decoder主要负责生成(generation) The decoder outputs tokens one by one, where the current output depends on the previous tokens. This process is called auto-regressive generation 基本结构如下: encoder结构和decoder结构基本一致(除了mask),所以主要看decoder即可: 每个核心的Block包含: Layer Norm Multi headed attention A skip connection Second layer Norm Feed Forward network Another skip connection 看下llama decoder部分代码,摘自 transformers/models/llama/modeling_llama.py ,整个forward过程和上图过程一模 ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照
总结与预览地址:访问总结与预览