arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.01485cs.CL
收藏

少量即可走得很远:利用部分上下文实现高效长上下文训练与推理

A Little Goes a Long Way: Efficient Long Context Training and Inference with Partial Contexts

University of Illinois Urbana-Champaign(伊利诺伊大学厄巴纳-香槟分校);Microsoft(微软公司)

Suyu Ge, Xihui Lin, Yunan Zhang, Jiawei Han, Hao Peng

AI总结:

针对长上下文LLM训练和部署开销大的问题,提出LongGen,将长度扩展与GPU友好的KV缓存缩减架构结合,通过混合注意力层和轻量训练,实现训练加速、内存减少及性能提升。

摘要:

训练和部署长上下文大型语言模型(LLMs)会产生大量开销。为解决这一问题,通常需要两个关键步骤:预训练LLM一般会通过在长上下文数据上训练,经历一个单独的上下文长度扩展阶段,随后进行架构修改以减少部署期间KV缓存的开销。本文认为,将长度扩展与GPU友好的KV缓存缩减架构相结合,不仅能降低长度扩展期间的训练开销,还能获得更好的长上下文性能。这促成了我们提出的LongGen,它在长度扩展期间将预训练LLM微调为高效架构。LongGen基于三个关键见解:(1)稀疏注意力模式,如窗口注意力(关注最近的token)、注意力汇聚(初始token)和块式稀疏注意力(跨步token块),非常适合构建高效长上下文模型,主要因为它们具有GPU友好的内存访问模式,不仅在理论上,在实践中也能实现效率提升。(2)模型必须能够直接访问所有token。包含1/3全注意力层和2/3高效层的混合架构,在效率和长上下文性能之间实现了平衡的权衡。(3)在5B长上下文数据上进行轻量级训练,足以将混合模型的上下文长度从4K扩展到128K。我们在Llama-2 7B和Llama-2 70B上评估了LongGen,证明其在不同规模下的有效性。在128K长上下文训练期间,与全注意力基线相比,LongGen实现了1.55倍的训练加速,并将挂钟时间减少了36%。在推理期间,LongGen将KV缓存内存减少了62%,实现了1.67倍的预填充加速和1.41倍的解码加速。

英文摘要:

Training and serving long-context large language models (LLMs) incurs substantial overhead. To address this, two critical steps are often required: a pretrained LLM typically undergoes a separate stage for context length extension by training on long-context data, followed by architectural modifications to reduce the overhead of KV cache during serving. This paper argues that integrating length extension with a GPU-friendly KV cache reduction architecture not only reduces training overhead during length extension, but also achieves better long-context performance. This leads to our proposed LongGen, which finetunes a pretrained LLM into an efficient architecture during length extension. LongGen builds on three key insights: (1) Sparse attention patterns, such as window attention (attending to recent tokens), attention sink (initial ones), and blockwise sparse attention (strided token blocks) are well-suited for building efficient long-context models, primarily due to their GPU-friendly memory access patterns, enabling efficiency gains not just theoretically but in practice as well. (2) It is essential for the model to have direct access to all tokens. A hybrid architecture with 1/3 full attention layers and 2/3 efficient ones achieves a balanced trade-off between efficiency and long-context performance. (3) Lightweight training on 5B long-context data is sufficient to extend the hybrid model's context length from 4K to 128K. We evaluate LongGen on both Llama-2 7B and Llama-2 70B, demonstrating its effectiveness across different scales. During training with 128K-long contexts, LongGen achieves 1.55x training speedup and reduces wall-clock time by 36%, compared to a full-attention baseline. During inference, LongGen reduces KV cache memory by 62%, achieving 1.67x prefilling speedup and 1.41x decoding speedup.

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

↑