Abstract
Large Language Models (LLMs) face significant deployment challenges due to the quadratic computational complexity of self-attention. While pruning techniques offer a path to efficiency, they often necessitate expensive fine-tuning to recover performance. This paper introduces Neural Block Linearization (NBL), a novel post-training compression method that replaces redundant attention layers with optimal linear approximations. By leveraging Canonical Correlation Analysis (CCA) to identify layers with high linear redundancy and Linear Minimum Mean Squared Error (LMMSE) estimation for weight derivation, NBL achieves substantial inference speedups and memory savings with minimal impact on model accuracy. Experimental results on models like Mistral-7B and Llama-3.1-8B demonstrate up to a 32% increase in throughput and significant KV-cache reduction without any gradient-based fine-tuning.
Introduction
The transformer architecture has revolutionized natural language processing, yet its reliance on self-attention creates a bottleneck during inference, particularly as sequence lengths grow. The quadratic scaling of attention with respect to context length leads to high latency and massive memory requirements for the Key-Value (KV) cache.
Existing approaches to mitigate these costs, such as structured pruning, often involve removing layers or heads entirely. However, such "hard" deletions disrupt the model's internal representations, typically requiring extensive retraining to maintain performance. Neural Block Linearization (NBL) addresses this by performing "soft" compression: instead of deleting a layer, it replaces the complex attention mechanism with a computationally efficient linear layer that preserves the essential information flow.
Methodology: Neural Block Linearization
NBL operates on the principle that certain layers in a pre-trained LLM exhibit high linear redundancy. The process involves two primary steps: identifying candidate layers for linearization and calculating the optimal linear weights.
Identifying Redundant Layers via CCA
To determine which layers can be safely linearized, the authors employ Canonical Correlation Analysis (CCA). CCA measures the linear relationship between the input $X$ and output $Y$ of a transformer block. By deriving a theoretical upper bound on the approximation error, NBL identifies layers where the mapping is "most linear."
As shown in the analysis of Mistral and Llama models, the CCA bound tends to decrease in later layers, suggesting that the network's representations become more stable and linearly predictable towards the output.
Optimal Linear Approximation with LMMSE
Once a block is selected for linearization, its Multi-Head Attention (MHA) component is replaced by a linear layer. The weights $W$ and bias $b$ of this layer are determined using a Linear Minimum Mean Squared Error (LMMSE) estimator. This approach treats the linearization as a channel estimation problem, finding the mathematically optimal linear mapping based on a small calibration dataset.
The resulting linear layer eliminates the need for KV-cache storage for that specific block and replaces the $O(N^2)$ attention operation with an $O(N)$ linear transformation. Crucially, this process is entirely closed-form and requires no gradient-based fine-tuning.
Experimental Evaluation
The authors evaluated NBL across several state-of-the-art LLMs, including Mistral-7B, Llama-3.1-8B, and DeepSeek-R1-Distill-Llama-8B.
Datasets and Benchmarks
- Calibration: Weights were calculated using 256 samples from the C4 dataset.
- Reasoning Tasks: Performance was measured across standard benchmarks such as MMLU, ARC, BoolQ, and HellaSwag.
- Efficiency Metrics: Throughput, prefill speedup, and KV-cache memory usage were tracked.
Key Results
The empirical results highlight NBL's ability to balance efficiency and accuracy:
- Throughput Gains: For the DeepSeek-R1-Distill-Llama-8B model, linearizing 12 layers resulted in a 32% increase in inference throughput with a negligible accuracy drop (from 63.6% to 62.4%).
- Memory Efficiency: In Llama-3.1-8B, replacing 12 layers reduced the KV-cache footprint from 32 GB to 20 GB at a 4096 context length, a significant reduction for long-context tasks.
- Synergy with Speculative Decoding: When combined with EAGLE-3, NBL achieved a cumulative speedup of up to 4.07x on the DeepSeek model.
Discussion and Insights
A critical insight from this work is that "approximation is better than deletion." By maintaining a linear path for information rather than cutting it off, NBL avoids the catastrophic failures seen in zero-shot pruning. Furthermore, the use of CCA provides a more robust selection metric than simpler heuristics like cosine similarity, as it accounts for the variance and multi-dimensional nature of the hidden states.
The observation that later layers are more amenable to linearization aligns with the theory that early layers focus on feature extraction and complex non-linear transformations, while later layers refine these features into a more linear subspace for the final prediction head.
Conclusion
Neural Block Linearization offers a powerful, "plug-and-play" method for accelerating LLM inference. By replacing redundant attention blocks with optimal linear layers, it provides significant gains in speed and memory efficiency without the need for costly retraining. Future work may extend this linearization to MLP blocks or individual attention heads, further pushing the boundaries of efficient LLM deployment.
Summary updated