提出新型位置编码方法,让大模型推理更长文本时表现更好
Mesa-Extrapolation: A Weave Position Encoding Method for Enhanced Extrapolation in LLMs
- 用分块三角注意力和阶梯位置编码,提升模型外推能力
- 在不增加计算成本下,显著降低内存占用并加快推理速度
- 适合需要处理超长文本的场景,如法律、科研文档分析
大语言模型虽已革新多个领域,但仍面临外推难题:当输入长度超过训练最大长度时,推理性能急剧下降。本文通过理论分析发现,传统无位置编码(NoPE)在有效范围外失效,而精心设计的位置编码(PE)可突破此限制。我们的定理证明,采用编织式位置编码(weave PE)的大模型可在无需额外开销的情况下实现更强的外推能力。为此,我们提出新方法Mesa-Extrapolation,其基于分块三角注意力矩阵,并对最后一块应用阶梯位置编码(Stair PE)。该方法不仅保持良好性能,还显著降低内存需求并加速推理。大量实验验证了其有效性,表明其具备成为可扩展解决方案的潜力。代码已开源。
原文摘要 · Abstract (English)
Large language models (LLMs), although having revolutionized many fields, still suffer from the challenging extrapolation problem, where the inference ability of LLMs sharply declines beyond their max training lengths. In this work, we conduct a theoretical analysis to better understand why No Position Encoding (NoPE) fails outside its effective range, as well as examining the power of Position Encoding (PE) in this context. Our findings reveal that with meticulous weave position, PE can indeed be extended beyond effective range. Our theorems establish that LLMs equipped with weave PE can achieve improved extrapolation performance without additional cost. Furthermore, we introduce a novel weave PE method, Mesa-Extrapolation, which utilizes a chunk-based triangular attention matrix and applies Stair PE to manage the final chunk. This method not only retains competitive performance but also offers substantial benefits such as significantly reduced memory demand and faster inference speed. Extensive experiments validate the effectiveness of Mesa-Extrapolation, demonstrating its potential as a scalable solution to enhancing LLMs applicative reach. Our code is available at \url{https://github.com/soacker/Mesa-Extrapolation}.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。