发现微调时值矩阵最重要,仅优化查询和值矩阵就能高效达优。
Theoretical Insights into Fine-Tuning Attention Mechanism: Generalization and Optimization
- 只微调查询与值权重,性能接近全量微调。
- 值权重用更高学习率,收敛更快、效果更好。
- 适合追求高效微调的模型部署者参考。
大型语言模型(LLMs)基于Transformer架构,在多种任务中表现出色。然而,针对特定任务进行微调仍因参数量庞大而资源消耗高。本文研究了微调过程中注意力机制的两个显著现象:一是‘注意力矩阵重要性不均’,表明优化值权重($oldsymbol{W}_v$)比优化键权重($oldsymbol{W}_k$)效果更显著;仅微调$oldsymbol{W}_q$与$oldsymbol{W}_v$即可在计算效率上大幅降低,同时性能媲美甚至优于全量微调($oldsymbol{W}_q, oldsymbol{W}_k, oldsymbol{W}_v$)。二是‘定制学习率提升收敛性’,即对$oldsymbol{W}_v$采用更高学习率,能加速收敛并提升表现。基于此,我们提出一种新策略,在存储与时间成本上均实现高效优化。在基准数据集上的实验验证了该方法的有效性,支持理论分析。本研究为大模型微调算法的配置与改进提供了理论基础。
原文摘要 · Abstract (English)
Large Language Models (LLMs), built on Transformer architectures, exhibit remarkable generalization across a wide range of tasks. However, fine-tuning these models for specific tasks remains resource-intensive due to their extensive parameterization. In this paper, we explore two remarkable phenomena related to the attention mechanism during the fine-tuning of LLMs (where $\mathbf{W}_q$, $\mathbf{W}_k$, and $\mathbf{W}_v$ denote the weights of the query, key, and value layers, respectively). The first phenomenon, termed "Unequal Importance of Attention Matrices", highlights the impact of fine-tuning different weight matrices. It shows that optimizing the $\mathbf{W}_v$ matrix yields significantly better performance than optimizing the $\mathbf{W}_k$ matrix. Fine-tuning only the $\mathbf{W}_q$ and $\mathbf{W}_v$ matrices is computationally efficient while delivering results comparable to, or even better than fine-tuning all three matrices ($\mathbf{W}_q$, $\mathbf{W}_k$, and $\mathbf{W}_v$). The second phenomenon,"Attention Matrices with Customized Learning Rate Lead to Better Convergence", emphasizes the importance of assigning distinct learning rates to these matrices. Specifically, a higher learning rate for the $\mathbf{W}_v$ matrix compared to $\mathbf{W}_q$ and $\mathbf{W}_k$ accelerates convergence and improves performance. Building on these insights, we propose a new strategy that improves fine-tuning efficiency in terms of both storage and time. Experimental results on benchmark datasets validate the effectiveness of this approach, supporting our theoretical findings. Our analysis lays the theoretical groundwork for configuring and improving algorithms in LLMs fine-tuning.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。