arXiv:2409.14595cs.CLcs.LG2024-09被引 2

通过共享相似注意力矩阵,让大模型推理更快更省资源。

EchoAtt: Attend, Copy, then Adjust for More Efficient Large Language Models

  • 分析多层注意力模式相似性,动态共享非关键层的注意力矩阵。
  • 在TinyLLaMA-1.1B上实现推理提速15%、训练提速25%、参数量降4%。
  • 适合部署在资源受限或需实时响应的场景,如移动端和边缘计算。

大型语言模型(LLMs)因规模扩大,在自然语言处理任务中表现出色,但其计算开销也随之增加,尤其在推理与微调阶段。为应对这一挑战,本文提出EchoAtt框架,通过分析并利用变压器模型中各层间注意力模式的相似性来优化性能。研究发现,大型模型中的许多中间层具有高度相似的注意力矩阵。基于此,EchoAtt允许在非关键层共享注意力矩阵,显著降低计算需求而无需牺牲性能。该方法被集成至知识蒸馏框架中,由预训练教师模型指导较小学生模型的训练,学生模型选择性共享高相似度层的注意力矩阵,并继承教师模型的关键参数。在使用TinyLLaMA-1.1B的最佳实验中,EchoAtt实现了推理速度提升15%、训练速度提升25%,参数量减少约4%,同时提升零样本性能。结果表明,注意力矩阵共享是提升大模型效率的有效手段,使其更适用于实时及资源受限的应用场景。

原文摘要 · Abstract (English)

Large Language Models (LLMs), with their increasing depth and number of parameters, have demonstrated outstanding performance across a variety of natural language processing tasks. However, this growth in scale leads to increased computational demands, particularly during inference and fine-tuning. To address these challenges, we introduce EchoAtt, a novel framework aimed at optimizing transformer-based models by analyzing and leveraging the similarity of attention patterns across layers. Our analysis reveals that many inner layers in LLMs, especially larger ones, exhibit highly similar attention matrices. By exploiting this similarity, EchoAtt enables the sharing of attention matrices in less critical layers, significantly reducing computational requirements without compromising performance. We incorporate this approach within a knowledge distillation setup, where a pre-trained teacher model guides the training of a smaller student model. The student model selectively shares attention matrices in layers with high similarity while inheriting key parameters from the teacher. Our best results with TinyLLaMA-1.1B demonstrate that EchoAtt improves inference speed by 15\%, training speed by 25\%, and reduces the number of parameters by approximately 4\%, all while improving zero-shot performance. These findings highlight the potential of attention matrix sharing to enhance the efficiency of LLMs, making them more practical for real-time and resource-limited applications.

大模型优化注意力共享知识蒸馏推理加速

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