CLEX: Continuous Length Extrapolation for Large Language Models

📄 arXiv: 2310.16450v3 📥 PDF

作者: Guanzheng Chen, Xin Li, Zaiqiao Meng, Shangsong Liang, Lidong Bing

分类: cs.CL

发布日期: 2023-10-25 (更新: 2024-03-24)

备注: ICLR 2024

🔗 代码/项目: GITHUB


💡 一句话要点

提出CLEX以解决长语言模型上下文窗口限制问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 长文本处理 位置嵌入 上下文窗口 长语言模型 自然语言处理 微分方程 性能优化

📋 核心要点

  1. 现有的PE扩展方法在上下文窗口的外推能力上存在显著局限,影响了长文本处理的效果。
  2. CLEX通过普通微分方程建模长度扩展因子的动态,能够实现上下文长度的连续外推,克服了现有方法的限制。
  3. 实验表明,CLEX在长文本基准测试中表现出色,能够将上下文窗口扩展至训练长度的4倍或8倍,且性能与最先进的模型相当。

📝 摘要(中文)

基于Transformer的大型语言模型(LLMs)在许多自然语言处理任务中取得了显著进展,但其能力受到预设上下文窗口的限制。虽然位置嵌入(PE)扩展方法在将上下文窗口扩展到特定长度方面有效,但在外推能力上存在显著局限,或在上下文窗口内牺牲部分性能。为了解决这些挑战,本文提出了连续长度外推(CLEX)方法,通过普通微分方程对长度扩展因子的动态进行建模,从而克服现有PE扩展方法的限制。CLEX能够在实际任务中以优异的性能实现上下文长度的外推,实验结果表明,CLEX可以有效将上下文窗口扩展至训练长度的4倍或近8倍,且性能未出现下降。

🔬 方法详解

问题定义:本文旨在解决大型语言模型在上下文窗口长度上的限制,现有的PE扩展方法在外推能力上存在不足,导致长文本处理效果不佳。

核心思路:CLEX通过普通微分方程对长度扩展因子的动态进行建模,提供了一种连续的长度外推方法,能够在不牺牲性能的情况下扩展上下文窗口。

技术框架:CLEX的整体架构包括对位置嵌入的动态建模,结合Rotary Position Embedding的LLMs(如LLaMA和GPT-NeoX),实现了无缝集成。

关键创新:CLEX的主要创新在于将PE扩展方法推广到连续长度外推,突破了现有方法的限制,使得上下文长度可以灵活扩展。

关键设计:CLEX在参数设置上进行了优化,确保在训练和推理延迟上几乎没有影响,同时在损失函数和网络结构上进行了适当调整,以支持长文本的有效处理。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果显示,CLEX能够将上下文窗口扩展至训练长度的4倍或近8倍,且在LongBench基准测试中表现出与最先进的开源模型相当的竞争力,展现了其在长文本处理中的有效性。

🎯 应用场景

CLEX的研究成果具有广泛的应用潜力,特别是在需要处理长文本的自然语言处理任务中,如文档摘要、长篇对话生成和信息检索等领域。其优越的性能能够提升这些应用的效果,推动相关技术的发展。

📄 摘要(原文)

Transformer-based Large Language Models (LLMs) are pioneering advances in many natural language processing tasks, however, their exceptional capabilities are restricted within the preset context window of Transformer. Position Embedding (PE) scaling methods, while effective in extending the context window to a specific length, demonstrate either notable limitations in their extrapolation abilities or sacrificing partial performance within the context window. Length extrapolation methods, although theoretically capable of extending the context window beyond the training sequence length, often underperform in practical long-context applications. To address these challenges, we propose Continuous Length EXtrapolation (CLEX) for LLMs. We generalise the PE scaling approaches to model the continuous dynamics by ordinary differential equations over the length scaling factor, thereby overcoming the constraints of current PE scaling methods designed for specific lengths. Moreover, by extending the dynamics to desired context lengths beyond the training sequence length, CLEX facilitates the length extrapolation with impressive performance in practical tasks. We demonstrate that CLEX can be seamlessly incorporated into LLMs equipped with Rotary Position Embedding, such as LLaMA and GPT-NeoX, with negligible impact on training and inference latency. Experimental results reveal that CLEX can effectively extend the context window to over 4x or almost 8x training length, with no deterioration in performance. Furthermore, when evaluated on the practical LongBench benchmark, our model trained on a 4k length exhibits competitive performance against state-of-the-art open-source models trained on context lengths up to 32k. Our code is available at https://github.com/DAMO-NLP-SG/CLEX.