TL;DR
This paper introduces LayerMerge, a novel depth pruning technique that significantly reduces the size of large foundation models by merging layers, achieving up to 90% depth reduction with minimal performance loss. Unlike existing methods, LayerMerge is modality-agnostic and offers linear improvements in inference speed and memory usage, making efficient deployment of LLMs more feasible.
What Problem Does This Paper Address?
Deploying massive foundation models, especially Large Language Models (LLMs), is a major challenge due to their immense computational and memory requirements. This makes them impractical for resource-constrained environments. While various pruning techniques exist, depth pruning (removing entire layers) has been less explored and often evaluated at lower compression rates (under 50%). Existing depth pruning methods can also be complex or require extensive retraining. Width pruning (removing weights within layers) is more common but doesn't always offer the same linear speedups as depth pruning. This paper aims to bridge this gap by proposing a simple yet effective depth pruning method that achieves high compression rates while preserving model capabilities and offering significant efficiency gains.
Methods
LayerMerge employs a two-pronged approach to depth pruning:
- LayerCluster (K-Medoids Clustering): This method identifies representative layers within a specified range by clustering their parameter space using K-Medoids. The most representative layers (cluster centers) are kept, effectively reducing the number of layers.
- LayerMerge (PCA-Based Merging): This technique uses Principal Component Analysis (PCA) to synthesize new layers from existing ones. For each module type (e.g., self-attention, MLP) within a selected range, PCA is applied to the stacked parameters of the layers to be merged. The principal components are then used to generate synthetic layers that replace the original set, effectively merging them.
- LayerMergeAct (Activation-Guided Adaptive Merging): This is an extension that incorporates activation patterns from calibration data. It uses cosine similarity of activations to identify blocks of layers that can be merged. This method uses a hyperparameter to control the variance retained by the PCA components, offering more adaptive pruning.
Crucially, LayerMerge operates by merging layers rather than eliminating them, preserving learned knowledge. It only requires forward passes and does not need specialized sparse kernels, making it hardware-agnostic and simplifying deployment.
Datasets
The paper evaluates LayerMerge on:
- LLMs: Llama-2 and Llama-3.1.
- Time Series Forecasting Model: MOMENT [1], to demonstrate modality-agnostic compression.
- Leaderboard-Lite: A curated subset of 15 challenges from the Open LLM Leaderboard v2, used for evaluating emergent abilities under aggressive compression. This benchmark is designed for rapid evaluation and focuses on challenges with high performance variance.
Key Insights and Ideas
- Depth Pruning Can Be Competitive: Contrary to common assumptions, depth pruning, when done effectively, can achieve performance comparable to or even better than width pruning at high sparsity levels.
- Layer Merging Preserves Knowledge: Instead of simply removing layers, merging them intelligently (using PCA or activation similarity) allows the model to retain its learned representations and emergent abilities.
- Modality Agnosticism is Achievable: LayerMerge's effectiveness on both LLMs and time series models highlights its general applicability across different domains and model architectures.
- Linear Efficiency Gains: The depth pruning approach naturally leads to linear reductions in inference time and memory, a significant advantage over width pruning which might not offer the same scalability.
- Aggressive Pruning is Feasible: The paper demonstrates that reducing model depth by up to 90% (to as few as 3 layers) can still preserve critical emergent abilities, challenging the notion that extreme sparsity inherently degrades performance.
Key Results
- Performance Preservation: LayerMerge and LayerMergeAct achieve performance comparable to the base model on Leaderboard-Lite, even at 90% depth reduction. They often outperform other depth pruning methods.
- Efficiency Gains: LayerMerge offers linear reductions in inference time and memory. For example, at 50% sparsity on Llama-2-7b, it reduces FLOPs by 70% and memory usage by 69% compared to state-of-the-art width pruning methods.
- Emergent Abilities: LayerMergeAct shows strong retention of emergent abilities, particularly in graduate-level domain knowledge and multistep soft reasoning. While some natural language understanding tasks see drops, LayerMergeAct shows better retention than other methods.
- Modality-Agnostic Validation: On time series forecasting with MOMENT, pruned models consistently outperformed shallow baselines trained from scratch, with minimal performance differences (<0.01 MAE) compared to the original models.
Limitations and Future Work
- Llama-3.1 Sparsity: The paper notes that Llama-3.1-8b may be less "prunable" than Llama-2-7b-hf, with pruned models not showing performance improvements at the same sparsity levels. This suggests that newer, more advanced LLMs might be harder to scale down.
- Task-Agnostic Pruning Limits: The lack of clear trends between performance and depth retention beyond 50% pruning might indicate that task-agnostic pruning methods may not retain specific emerging capabilities.
- Future Work: The authors plan to develop targeted, task-specific methods for scaling down LLMs to achieve greater compression with even lower performance loss. They also aim to develop more systematic benchmarks for evaluating emergent abilities at finer resolutions to guide future method development.
Summary updated