Beyond Linear Approximations: A Novel Pruning Approach for Attention Matrix

Yingyu Liang, Jiangxuan Long, Zhenmei Shi, Zhao Song, Yufa Zhou

TL;DR

Most Large Language Model (LLM) pruning methods treat weight matrices as simple linear operators. However, this ignores the highly sensitive, non-linear Softmax function at the heart of the Transformer's attention mechanism. This paper introduces a novel pruning approach that directly optimizes for the final attention matrix using gradient descent. The method offers a solid theoretical convergence guarantee and significant performance gains over state-of-the-art linear methods like Wanda and SparseGPT.

The Problem with Linear Approximation

LLMs are massive—even smaller models like Llama 3.1 8B require over 16GB of GPU memory just to load. To deploy these models on edge devices with strict memory and computational constraints, we must "prune" them by removing unnecessary weights.

The current gold standard for pruning relies on linear approximation. Methods like Wanda and SparseGPT try to find a sparse weight matrix $\tilde{W}$ such that the linear output $X\tilde{W}$ is as close as possible to the original dense output $XW$.

The authors argue this is a fundamental mistake when applied to the attention layer. The attention mechanism is not linear; it relies on a Softmax function, which is incredibly sensitive to large values due to its exponential nature. A tiny error in the linear approximation can be exponentially magnified by the Softmax operation, leading to a completely different attention distribution and severely degrading the model's reasoning capabilities.

Comparison of the proposed Softmax-aware pruning versus traditional linear pruning.

A Non-Linear Pruning Method

To address this, the researchers propose a non-linear pruning approach that directly targets the Attention Matrix rather than the isolated weight matrices.

  1. Direct Optimization: Instead of minimizing the error of the linear projection, the authors define a loss function based on the difference between the original Softmax attention matrix and the pruned version.
  2. Fused Weights: Standard methods prune the Query ($W_Q$) and Key ($W_K$) matrices separately. This new method evaluates the fused attention weight matrix $W = W_Q W_K^\top$, capturing the interaction between queries and keys.
  3. Gradient Descent for Masks: The pruning mask $M$ is treated as a continuous variable optimized via Gradient Descent (GD). After optimization, the real-valued mask is converted into a binary mask (0s and 1s) based on the target sparsity level.
  4. Theoretical Rigor: Unlike many heuristic-based pruning papers, this work provides a formal proof of convergence. By utilizing the Polyak–Łojasiewicz (PL) inequality, the authors demonstrate that their GD-based algorithm will converge to a near-optimal pruning mask despite the non-convex nature of the optimization problem.

Key Results and Insights

The authors validated their approach using synthetic data (random Gaussian matrices) to test theoretical predictions, the C4 corpus for calibration, and Llama 3.2-1B as a primary testbed for real-world application.

Relative error comparison across varying regularization, sequence lengths, and sparsity ratios.
  • Superior Accuracy: In synthetic tests, the proposed method consistently achieved a lower relative error than Wanda and SparseGPT across various sequence lengths ($n$) and pruning ratios ($\rho$).
  • The "Softmax Sensitivity" Gap: The results confirm that linear pruning methods fail to account for the exponential scaling in Softmax. By focusing on the attention matrix (the "kernel" of the Transformer), the proposed method preserves the actual behavior of the model.
  • U-Shaped Regularization: As seen in the empirical evaluations, the regularization parameter $\lambda$ follows a U-shaped curve. There is a distinct "sweet spot" for regularization that yields the lowest relative error.
  • Robustness to Sequence Length: As the input sequence length increases, the performance gap between this non-linear method and traditional linear methods widens. This suggests the approach is particularly well-suited for modern, long-context LLMs.
  • Perplexity Gains: On the Llama 3.2-1B model, the method significantly outperformed the competition. When combined with SparseGPT for the MLP layers, this non-linear attention pruning achieved an end-to-end Perplexity (PPL) of 34.946, compared to 45.435 for SparseGPT alone.

Limitations and Future Work

While highly effective, the method does have limitations. Using Gradient Descent to find a pruning mask is computationally more expensive than the "one-shot" analytical solutions provided by methods like Wanda. Although accelerated with JAX, it remains a slower pre-processing step.

Furthermore, the paper focuses heavily on the attention mechanism. While the authors demonstrate compatibility with existing linear methods for MLP (Feed-Forward) layers, developing a unified non-linear theory for the entire Transformer block remains an open challenge. Finally, scaling these experiments from 1B-parameter models to massive 70B+ parameter architectures will be a critical next step to verify if these non-linear benefits compound at scale.

Summary updated

BibTeX
@inproceedings{liang2025beyond,
  author = {Yingyu Liang and Jiangxuan Long and Zhenmei Shi and Zhao Song and Yufa Zhou},
  title = {{Beyond Linear Approximations: A Novel Pruning Approach for Attention Matrix}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=sgbI8Pxwie},
}
Figure