arXiv:2504.18857cs.CLcs.AI2025-04被引 1

无需训练即可扩展大模型上下文长度,效果优于现有方法。

Effective Length Extrapolation via Dimension-Wise Positional Embeddings Manipulation

  • 按维度分离位置编码,识别关键维度进行优化。
  • Llama3-8B实现128k上下文,70B模型长文本基准提升超18分。
  • 兼容Flash Attention 2,性能超越GPT-4-128K。

大型语言模型在输入令牌数超过预训练长度时,常出现处理与生成不连贯的问题。现有长上下文扩展方法虽显著扩大了模型上下文窗口,但需高昂的训练成本。本文提出维度级位置编码操纵(DPE),通过分析RoPE的不同隐藏维度,识别各维度的有效长度并定位关键维度用于上下文扩展。DPE复用预训练模型中的原始位置索引与嵌入,仅对关键维度的位置索引进行调整至其最优有效长度,实现最小修改下的模型优化。该方法在不进行持续训练的前提下,使Llama3-8B支持128k上下文,并可无缝集成Flash Attention 2。此外,对训练长度内的表现也大幅提升,如在RULER基准上,Llama3.1 70B模型得分提升超18点。相比商用模型,加了DPE的Llama3.1 70B甚至优于GPT-4-128K。

原文摘要 · Abstract (English)

Large Language Models (LLMs) often struggle to process and generate coherent context when the number of input tokens exceeds the pre-trained length. Recent advancements in long-context extension have significantly expanded the context window of LLMs but require expensive overhead to train the large-scale models with longer context. In this work, we propose Dimension-Wise Positional Embeddings Manipulation (DPE), a training-free framework to extrapolate the context window of LLMs by diving into RoPE's different hidden dimensions. Instead of manipulating all dimensions equally, DPE detects the effective length for every dimension and finds the key dimensions for context extension. We reuse the original position indices with their embeddings from the pre-trained model and manipulate the key dimensions' position indices to their most effective lengths. In this way, DPE adjusts the pre-trained models with minimal modifications while ensuring that each dimension reaches its optimal state for extrapolation. DPE significantly surpasses well-known baselines such as YaRN and Self-Extend. DPE enables Llama3-8k 8B to support context windows of 128k tokens without continual training and integrates seamlessly with Flash Attention 2. In addition to its impressive extrapolation capability, DPE also dramatically improves the models' performance within training length, such as Llama3.1 70B, by over 18 points on popular long-context benchmarks RULER. When compared with commercial models, Llama 3.1 70B with DPE even achieves better performance than GPT-4-128K.

长上下文位置编码无训练Llama3

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。