Introduction
Deploying Large Language Models (LLMs) is notoriously expensive due to their massive computational and memory requirements. While "static pruning"—permanently removing parts of the model—can save resources, it often severely degrades accuracy because different inputs require different parts of the model to be active.
"Contextual sparsity" solves this by deciding which neurons to use on-the-fly for each input. However, existing approaches face two major hurdles:
- Predictor Overhead: Previous methods used small neural networks at every layer to predict what to prune, which adds significant latency.
- Suboptimal Pruning Rules: Most methods rely on simple "magnitude-based" criteria (pruning whatever has the smallest activation values), which is a poor proxy for actual importance to the model's output.
Methods: The Shadow Predictor and Plainact
ShadowLLM introduces two primary innovations to overcome these hurdles: the Unified Shadow Predictor and the Plainact criterion.
The Unified Shadow Predictor
Instead of placing a predictor at every layer, ShadowLLM uses a single predictor at the very first layer of the model. By looking at the initial attention output, this "shadow" model predicts the entire sparsity pattern for all subsequent layers at once. This drastically reduces the computational overhead of the prediction process itself.
Plainact Criterion and Global Pruning
Moving beyond simple magnitudes, the authors found that a gradient-informed sensitivity metric called plainact ($||A \cdot \frac{\partial L}{\partial A}||_1$) is far more effective. It measures how much the loss actually changes if a neuron is removed, making it a better target for the shadow model to learn. Additionally, ShadowLLM employs Global Pruning, allowing some layers to be pruned more aggressively than others based on their relative importance for a specific input.
Key Results
The researchers validated ShadowLLM using the OPT family (1.3B to 66B) and Llama-2-7b across WikiText2 and seven downstream tasks (PIQA, COPA, OpenBookQA, etc.).
ShadowLLM achieved over a 15% improvement in end-to-end accuracy compared to magnitude-based pruning methods. It delivered up to a 20.6% speedup over the previous state-of-the-art (DejaVu) and reduced predictor-related FLOPs by approximately 20%.
On the OPT-13B model at 50% sparsity, ShadowLLM provided 14% lower latency with nearly 2% higher accuracy than the DejaVu-style baseline. These performance gains were consistent across model sizes, scaling up to 66B parameters.
Insights and Limitations
A key insight from this work is that the first layer's activations contain enough information to predict important neurons 30 layers later. Furthermore, magnitude is deceptive; neurons with large activations aren't necessarily the most important for the final output. The authors also observed that contextual sparsity is most critical at the early and late layers, while middle layers remain more stable.
While ShadowLLM shows clear algorithmic gains, future research is needed to test performance on models with different activation functions (e.g., SwiGLU), use larger calibration datasets, and develop specialized sparse-matrix kernels to fully realize hardware-level latency benefits.
Summary updated