arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.04211cs.CLcs.AI
收藏

面向高效微调与上下文长度扩展的相关性感知选择合并注意力机制

Correlation-Aware Select and Merge Attention for Efficient Fine-Tuning and Context Length Extension

Institute of Automation, Chinese Academy of Sciences(中国科学院自动化研究所);University of Chinese Academy of Sciences(中国科学院大学);Beijing Academy of Artificial Intelligence(北京智源人工智能研究院)

Ning Wang, Zekun Li, Tongxin Bai, Guoqi Li

AI总结:

本研究提出相关性感知选择合并注意力架构与位置编码增强技术,以更低资源实现大语言模型的高效微调与超长上下文扩展,性能具备竞争力。

摘要:

长序列建模对各类大规模模型至关重要,但将现有架构扩展以处理更长序列面临着巨大的技术与资源挑战。本文提出了一种高效灵活的注意力架构,与其他优秀方法相比,该架构能够以更少的计算资源和更短的微调时间实现大语言模型的上下文长度扩展。具体而言,我们引入了相关性感知选择与合并机制,以实现高效的稀疏注意力。此外,我们还提出了一种涉及位置编码的新型数据增强技术,以提升模型对未见过位置的泛化能力。实验结果如下:第一,仅使用单张A100显卡,我们就实现了序列长度为32K的Llama2-7B模型微调,效率高于其他依赖子集回归的方法。第二,我们提出了一套覆盖预训练、微调和推理阶段的上下文长度扩展综合方法。在预训练阶段,我们的注意力机制在token选择过程中会部分打破平移不变性,因此我们仅对选中的token应用位置编码。该方法实现了较高的性能与显著的外推能力。在微调阶段,我们提出了循环随机截断动态增长NTK位置编码(CRD NTK)。这种设计仅需16K序列长度即可完成微调,让Llama2-7B、Mistral-7B等模型能够在最高1M甚至任意长度的上下文下进行推理。我们的方法在4M上下文长度的passkey任务上达到了100%的准确率,在1M上下文长度下保持了稳定的困惑度。与传统的全注意力机制相比,该方法的资源需求至少降低了64倍,同时仍能取得具有竞争力的性能。

英文摘要:

Modeling long sequences is crucial for various large-scale models; however, extending existing architectures to handle longer sequences presents significant technical and resource challenges. In this paper, we propose an efficient and flexible attention architecture that enables the extension of context lengths in large language models with reduced computational resources and fine-tuning time compared to other excellent methods. Specifically, we introduce correlation-aware selection and merging mechanisms to facilitate efficient sparse attention. In addition, we also propose a novel data augmentation technique involving positional encodings to enhance generalization to unseen positions. The results are as follows: First, using a single A100, we achieve fine-tuning on Llama2-7B with a sequence length of 32K, which is more efficient than other methods that rely on subsets for regression. Second, we present a comprehensive method for extending context lengths across the pre-training, fine-tuning, and inference phases. During pre-training, our attention mechanism partially breaks translation invariance during token selection, so we apply positional encodings only to the selected tokens. This approach achieves relatively high performance and significant extrapolation capabilities. For fine-tuning, we introduce Cyclic, Randomly Truncated, and Dynamically Growing NTK Positional Embedding (CRD NTK). This design allows fine-tuning with a sequence length of only 16K, enabling models such as Llama2-7B and Mistral-7B to perform inference with context lengths of up to 1M or even arbitrary lengths. Our method achieves 100\% accuracy on the passkey task with a context length of 4M and maintains stable perplexity at a 1M context length. This represents at least a 64-fold reduction in resource requirements compared to traditional full-attention mechanisms, while still achieving competitive performance.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑