Skip to main content
QUICK REVIEW

[论文解读] Beyond Linear Approximations: A Novel Pruning Approach for Attention Matrix

Yingyu Liang, Jun Long|arXiv (Cornell University)|Oct 15, 2024
Neural Networks and ApplicationsComputer Science被引用 3
一句话总结

本文提出了一种针对大语言模型(LLMs)注意力矩阵的新型非线性剪枝方法,直接优化 Softmax 注意力输出的近似,而非线性投影。通过构建可微分损失函数并应用具有理论收敛保证的梯度下降法,该方法在性能上优于基于线性近似的剪枝方法,在保持模型精度的同时显著降低计算成本。

ABSTRACT

Large Language Models (LLMs) have shown immense potential in enhancing various aspects of our daily lives, from conversational AI to search and AI assistants. However, their growing capabilities come at the cost of extremely large model sizes, making deployment on edge devices challenging due to memory and computational constraints. This paper introduces a novel approach to LLM weight pruning that directly optimizes for approximating the attention matrix, a core component of transformer architectures. Unlike existing methods that focus on linear approximations, our approach accounts for the non-linear nature of the Softmax attention mechanism. We provide theoretical guarantees for the convergence of our Gradient Descent-based optimization method to a near-optimal pruning mask solution. Our empirical results demonstrate the effectiveness of our non-linear pruning approach in maintaining model performance while significantly reducing computational costs, which is beyond the current state-of-the-art methods, i.e., SparseGPT and Wanda, by a large margin. This work establishes a new theoretical foundation for pruning algorithm design in LLMs, potentially paving the way for more efficient LLM inference on resource-constrained devices.

研究动机与目标

  • 解决现有 LLM 剪枝方法因聚焦于注意力权重的线性近似而效率低下的问题。
  • 开发一种直接针对核心的非线性 Softmax 注意力机制进行优化的剪枝方法,该机制对 Transformer 性能至关重要。
  • 为所提出的剪枝框架中的优化过程提供理论收敛保证。
  • 通过减小模型大小和计算成本,实现更高效的 LLM 推理,适用于资源受限的边缘设备。

提出的方法

  • 构建一个可微分损失函数,直接最小化原始注意力矩阵与剪枝后注意力矩阵之间的差异,即 $ \| \mathrm{Softmax}(XWX^\top) - \mathrm{Softmax}(X(M \circ W)X^\top) \|_F $。
  • 应用梯度下降法优化剪枝掩码 $ M \in [0,1]^{d \times d} $,其中 $ M \circ W $ 表示剪枝后的权重矩阵。
  • 利用矩阵微积分推导注意力近似损失的闭式梯度,实现高效优化。
  • 通过 Polyak-Łojasiewicz(PL)不等式建立理论收敛性,证明在温和假设下梯度下降可收敛至近似最优解。
  • 引入 $ \ell_2 $-范数正则化项作用于 $ M $,以提升优化过程中的泛化能力与稳定性。
  • 基于对输入数据的假设(如 $ XX^\top \succeq \beta I $)和注意力矩阵的正性,确保梯度有界并保障收敛性。
Figure 1: Comparison of our Attention Weights Pruning method and Linear Pruning method such as Wanda and SparseGPT. The top figure illustrates our proposed method of the attention matrix approximation, where pruning is applied directly to the fused attention weight matrix $W$ , using only one prunin
Figure 1: Comparison of our Attention Weights Pruning method and Linear Pruning method such as Wanda and SparseGPT. The top figure illustrates our proposed method of the attention matrix approximation, where pruning is applied directly to the fused attention weight matrix $W$ , using only one prunin

实验结果

研究问题

  • RQ1能否设计一种直接优化非线性 Softmax 注意力矩阵的剪枝方法,使其在保持模型性能方面优于基于线性近似的剪枝方法?
  • RQ2在非线性注意力剪枝设置下,梯度下降的收敛性可提供哪些理论保证?
  • RQ3Softmax 函数对大正数值的敏感性如何影响线性与非线性剪枝方法的有效性?
  • RQ4能否设计一种可微分、基于梯度的剪枝框架,在保持高精度的同时减小模型大小和推理成本?

主要发现

  • 所提方法在注意力矩阵近似方面优于 Wanda 和 SparseGPT 等线性剪枝方法,如图 2 所示的定性比较结果所示。
  • 理论分析证明,在温和条件下,所提损失函数的梯度下降满足 Polyak-Łojasiewicz(PL)不等式,确保收敛至近似最优剪枝掩码。
  • 该方法在显著降低计算成本的同时保持了模型性能,初步的实证评估已验证此结论。
  • 损失函数的梯度被证明为 Lipschitz 连续,支持具有有界梯度的稳定优化。
  • 梯度的 Frobenius 范数下界由剪枝误差和掩码范数的函数决定,进一步支持收敛性保证。
  • 该方法是首个直接针对 Softmax 注意力矩阵进行优化的工作,为 LLM 中的非线性剪枝建立了新的理论基础。
(a) Varying $\lambda$ .
(a) Varying $\lambda$ .

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。