arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2503.09579cs.CLcs.AIcs.LG
收藏

长上下文建模中的成本最优分组查询注意力

Cost-Optimal Grouped-Query Attention for Long-Context Modeling

NLP Group, DCST, IAI, BNRIST, Tsinghua University, Beijing, China(自然语言处理组、国防科技大学、人工智能院、北京理工大学、清华大学、北京、中国);SIST, University of Science and Technology Beijing, Beijing, China(软件学院、北京科技大学、北京、中国)

Yingfa Chen, Yutong Wu, Chenyang Song, Zhen Leng Thai, Xingyu Shen, Xu Han, Zhiyuan Liu, Maosong Sun

AI总结:

本文提出成本最优分组查询注意力配置方法,通过解耦头大小与隐藏大小并联合优化模型规模,在长上下文场景下减少超50%内存和FLOPs且不损失模型能力。

摘要:

分组查询注意力(GQA)是一种被广泛采用的策略,用于降低大型语言模型(LLM)中注意力层的计算成本。然而,当前的GQA配置往往不是最优的,因为它们忽略了上下文长度对推理成本的影响。由于推理成本随上下文长度增长,最具成本效益的GQA配置也应随之变化。在这项工作中,我们分析了上下文长度、模型大小、GQA配置和模型损失之间的关系,并引入了两项创新:(1)我们将总头大小与隐藏大小解耦,从而能够更灵活地控制注意力FLOPs;(2)我们联合优化模型大小和GQA配置,以在注意力层和其他组件之间实现更好的推理资源分配。我们的分析表明,常用的GQA配置在长上下文场景中高度次优。更重要的是,我们提出了一种推导成本最优GQA配置的方法。我们的结果表明,对于长上下文场景,应使用更少的注意力头,同时扩大模型规模。根据我们的方法选择的配置,与Llama-3的GQA相比,可以将内存使用量和FLOPs减少超过50%,且模型能力没有任何下降。我们的发现为设计高效的长上下文LLM提供了宝贵的见解。代码可在 https://www.github.com/THUNLP/cost-optimal-gqa 获取。

英文摘要:

Grouped-Query Attention (GQA) is a widely adopted strategy for reducing the computational cost of attention layers in large language models (LLMs). However, current GQA configurations are often suboptimal because they overlook how context length influences inference cost. Since inference cost grows with context length, the most cost-efficient GQA configuration should also vary accordingly. In this work, we analyze the relationship among context length, model size, GQA configuration, and model loss, and introduce two innovations: (1) we decouple the total head size from the hidden size, enabling more flexible control over attention FLOPs; and (2) we jointly optimize the model size and the GQA configuration to arrive at a better allocation of inference resources between attention layers and other components. Our analysis reveals that commonly used GQA configurations are highly suboptimal for long-context scenarios. More importantly, we propose a recipe for deriving cost-optimal GQA configurations. Our results show that for long-context scenarios, one should use fewer attention heads while scaling up model size. Configurations selected by our recipe can reduce both memory usage and FLOPs by more than 50% compared to Llama-3's GQA, with *no degradation in model capabilities*. Our findings offer valuable insights for designing efficient long-context LLMs. The code is available at https://www.github.com/THUNLP/cost-optimal-gqa .

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

↑