Unifying Depth and Width Pruning for LLMs via Binary Knapsack Optimization
A two-stage dual-axis pruning framework that first solves a 0/1 knapsack optimization objective over coarse-granularity components, and follows it with a width pruning stage to fill the residual compression budget.
Introduction
Modern LLMs are HUGE!#
Developments in AI have given Large Language Models (LLMs) exceptional linguistic skills and reasoning capabilities. Unfortunately, these abilities come at a significant cost: modern LLMs have grown to enormous sizes (sometimes containing trillions of parameters!), making them quite expensive to run. In fact, many models are simply too large to fit on everyday devices such as laptops & phones, and require specialized hardware to run.
LLM Pruning, A Solution#
Researchers have figured out a neat idea to reduce the size of these huge models: simply remove components from the model that are relatively unimportant in a way that preserves as much performance as possible. This is called Structured Pruning.
Structured pruning methods can be broadly classified into 3 categories based on the axis along which they prune models.
Irrespective of the pruning axis, many methods follow a similar operational recipe:
- Compute an importance score for each prunable component
- Remove the components with the lowest importance scores (or equivalently, retain components with the highest importance scores)
Limitations#
While the aforementioned modus operandi is simple enough, the authors argue that there are some problems with it.
- Local Heuristics: Several methods tend to rely on importance scores that only represent how good a component is in isolation without measuring how good it is in the presence of other components. As a result, a component that works well in combination with other components might still get a low importance score if it is individually weak.
- Myopic Component Selection: The decision to remove or retain a component depends solely upon whether its importance scores is among the lowest or not. However, such greedy decisions do not account for cases where retaining a weaker component (which would otherwise be removed) can lead to a stronger pruned model down the line. In other words, greedy decisions are short-sighted.
- Imprecise Adherence to Target Budget: Many existing pruners suffer from a practical and fundamental problem - they don't meet the target compression ratio precisely! Asking the existing tools to compress a model by 35% can yield a model that is 19-30% smaller. If you have 16 GB of memory to fit a model into, a tool that quietly leaves the model 30% larger than requested is not much use.
- Calibration-Induced Deviations: Most existing pruners use some data (aka. calibration data) to compute importance scores. However, they often tend to rely so much on this data that the pruned model often exhibits inconsistencies in performance across a variety of tasks, performing well at some but disproportionately bad at others.
This paper proposes SNIPER, a novel Structured Knapsack-optimization-based Pruner that aims to resolves these limitations.
Methodology
SNIPER is a dual-axis approach that first prunes along the model's depth and then uses width pruning to meet the target compression ratio precisely.
Stage 1: Depth Pruning#
SNIPER's depth pruning strategy can be thought of as packing a suitcase while ensuring its weight limit is not exceeded.
Every component of the model has a weight (how many parameters it costs) and a value (how important it is). The compression budget gives you a fixed capacity for the pruned model (the suitcase). You want the most valuable set of components that fits.
Mathematically, SNIPER aims to solve the following optimization problem: S^* = \argmax_{\mathcal{S} \subseteq \mathcal{X}} \sum_{x \in \mathcal{S}} v(x) \quad \text{s.t.} \quad \sum_{x \in \mathcal{S}} w(x) \leq C
where \mathcal{X} is the set of prunable components, v(x) and w(x) are the value and weight of component x, respectively, and C is the pruned model's capacity.
This objective is exactly the knapsack problem and has a known, exact solution via dynamic programming (DP).
DP recursively combines solutions to intermediate subproblems to reach the optimal solution to a larger problem. A recurrence relation formally defines how these solutions are combined. SNIPER's recurrence relation can be given as:
\htmlClass{eq-t eq-t-now}{f(i, j)} = \begin{cases} \htmlClass{eq-t eq-t-skip}{f(i-1, j)} & \text{if } \htmlClass{eq-t eq-t-fit}{w(x_i) > j} \\ \htmlClass{eq-t eq-t-pick}{\max} \left(\htmlClass{eq-t eq-t-skip}{f(i-1, j)}, \htmlClass{eq-t eq-t-take}{\Delta}\right) & \text{if } \htmlClass{eq-t eq-t-fit}{w(x_i) \le j} \end{cases}
- f(i, j) — the maximum importance we can keep from the first i components if the budget is j.
- w(x_i) > j — the only question asked at each step. Is there still room for this component?
- f(i-1, j) — leave it out. The answer is the one already worked out for the components before it, budget untouched. It appears in both branches because it is always an option.
- \max — the one real decision, taken only when the component fits: keep whichever of the two is worth more.
- \Delta — take it. Spend w(x_i) of the budget and collect its importance: \Delta = f(i-1, j-w(x_i)) + v(x_i).
This algorithm runs in O(NC) time, where N = |\mathcal{X}|. Since C is usually huge by default (can run into billions!), this algorithm becomes intractable. To make it manageable, the authors divide each parameter count (all w(x_i)'s and C) by a discretizing factor, \alpha, reducing the time complexity to O\big(\lfloor \frac{NC}{\alpha} \rfloor\big). Here is a detailed analysis of the same.
Unlike greedy methods which only pick the locally best choice at each step, DP explores all available choices to ensure that future results are optimal.
The prunable components are the attention block and the feed-forward block of each layer, plus the option of keeping the layer whole. Keeping a whole layer and keeping its two halves are mutually exclusive choices, so they're grouped into a single decision.
The solution is optimal given the importance scores it is handed — the paper calls this conditionally optimal. Since the scores are still estimates, this is not a guarantee of the globally best possible pruned model. It is, however, strictly more than greedy methods offer, which is no guarantee at all.
Importance Estimation#
While computing a component's weight is easy (simply count how many parameters it holds), the harder question to answer is: how do you compute each component's importance?
A popular answer is marginal degradation (aka. leave-one-out scoring). From the original model, temporarily delete one component, and measure the drift in the model's predictions. Put it back, and repeat for each remaining component. The bigger the drift, the more important the component must have been.
By scoring each component in isolation, no score ever knows what any other score is doing. The failure shows up whenever two components do overlapping work. Delete either one and the model barely flinches, because the other one is still there to cover for it. Both therefore look cheap individually, and get low scores. Pruning using those scores causes both to be removed, along with their shared capabilities, which neither score ever reflected as important.
SNIPER uses the model's logits to measure this drift. Let \mathbb{Z} be the logits the original model produces on a batch of calibration data. For component x_i, it compares two versions of the model: one where the component is retained, one where it is dropped. The authors take the difference in how far each has drifted from \mathbb{Z} to quantify how important x_i is:
v(x_i) = \lVert \mathbb{Z} - \mathbb{Z}^{(i)}_{\text{drop}} \rVert_2^2 - \lVert \mathbb{Z} - \mathbb{Z}^{(i)}_{\text{retain}} \rVert_2^2
This formulation might seem similar to marginal degradation and if x_i is kept/removed from the original model, then \mathbb{Z} = \mathbb{Z}^{(i)}_{\text{retain}} and the equation becomes:
v(x_i) = \lVert \mathbb{Z} - \mathbb{Z}^{(i)}_{\text{drop}} \rVert_2^2
which is exactly, a marginal degradation-style formulation. However, SNIPER differs at exactly this assumption: it doesn't just use the original model to compute its heuristics.
Scoring on the model as it is actually being pruned#
SNIPER estimates importance iteratively: the score for component x_i is measured not on the original model but on M^{(i-1)}, the model as pruned up to the first i components. Each score is therefore conditioned on the decisions already made, and a component whose partner has just been removed immediately becomes expensive rather than staying cheap.
When computing the importance score of component x_i, f(i-1, C) must have already been computed. This means that we have the optimal pruning configuration for the first i-1 components given our compression budget, C.
M^{(i-1)} is exactly this configuration: the first i-1 components are pruned optimally according to f(i-1, C) while the rest are retained as it is.
The result is an importance estimation scheme that evolves with various pruning decisions instead of comparing against a stationary model.
Yes, notably. The paper ablates exactly this choice: SNIPER-LeaveOneOut is SNIPER with the iterative scoring swapped out for marginal degradation-based scoring, everything else held fixed. On Qwen3-8B compressed by 25%:
| Scoring scheme | Avg. retained performance (%) | Task-wise std (%) |
|---|---|---|
| Leave-one-out | 62.01 | 23.30 |
| Iterative | 82.64 | 12.20 |
That is a 20-point gap in average retained performance, and nearly double the task-wise deviation which ties straight back to Limitation #4: scores that look at components in isolation yield a model that is erratic across tasks, not merely a worse one.
Unfortunately, this method does not come without its limitations. Conditioning importance estimates on iterative pruning decisions makes these scores indirectly dependent on the model's compression ratio. This means that unlike marginal degradation-style heuristics which can be computed once for each model and re-used at any compression ratio, iterative importance estimates must be computed separately at each ratio, making them more computationally expensive. The authors provide an analysis wherein they show that it is practically viable to bypass this limitation to an extent.
Stage 2: Width Pruning#
Stage 1 operates on discrete components of fixed sizes. As a result, it leaves some of the compression budget unused. In order to fill this residual capacity, SNIPER prunes each MLP's width by removing individual neurons from it. This offers much finer control over the number of pruned parameters.
However, for this stage to be successful, two questions need to be answered:
- How do we rank each MLP's neurons?
- How many neurons do we remove from each MLP?
Neuron-Importance Estimation#
While SNIPER's iterative importance estimation step is quite useful in stage 1, it relies on the number of prunable components being relatively small (often <100). The number of neurons, however, is multiple orders of magnitude higher, making it infeasible to gauge the effect of removing each neuron one at a time.
Therefore, SNIPER resorts to a more straightforward heuristic to rank neurons. The authors define each neuron's sensitivity as the magnitude of its contribution to the MLP's output. The idea is simple: the higher a neuron's sensitivity is, the more important that neuron must be.
In modern LLMs, MLPs use up (\mathbf{U}), gate (\mathbf{G}) and down (\mathbf{D}) projection matrices to compute their outputs. Mathematically, \text{MLP}(\mathbf{X}) = (\sigma(\mathbf{X}\mathbf{G}^T) \odot (\mathbf{X}\mathbf{U}^T))\mathbf{D}^T The j^{th} neuron exists as the j^{th} column of U and G and the corresponding row of D. Its sensitivity is computed as: \Omega_j = |D_{j,:} \cdot (G_{:,j} \odot U_{:,j})|
This is an extremely cheap-to-compute heuristic since its computation does not require any data (only raw weights are multiplied) and can easily be vectorized.
The authors pit their sensitivity heuristic against a magnitude-based heuristic (only column magnitude is used) and an activation-based one (magnitude of activation produced by neuron; requires some data).
| Width Pruning Heuristic | Avg. retained performance (%) | Task-wise std (%) |
|---|---|---|
| Magnitude | 78.87 | 13.80 |
| Activation | 80.87 | 13.80 |
| Neuron Sensitivity | 82.64 | 12.20 |
Neuron sensitivity dominates the two alternatives by about 2-4\%. Its 13\% lower standard deviation across tasks also indicates more stable performance.
Budget Allocation#
Having ranked all neurons, the only thing left to do is to compute how many neurons must be removed from each MLP. To do so, the authors make use of each layer's importance score, as computed via iterative importance estimation.
The intuition: layers that are more important receive less of the total compression budget, i.e., are pruned less.
Let \mathbf{u} \in \mathbb{R}^L be the vector containing each layer's importance scores. Each MLP's individual compression ratio is then computed as: \rho_l = \frac{\exp(-u_l / \tau)}{\sum_{k=1}^L \exp(-u_k / \tau)} where l is the index of the layer containing the MLP and \tau is a temperature parameter.
The number of columns to prune from the MLP in layer l is given simply as: N_l = \lfloor \rho_l \cdot N_{total} \rfloor where N_{total} is the total number of columns to remove from all MLPs across all layers.
For the l^{th} layer, the bottom N_l neurons with respect to sensitivity are removed from its MLP.
Experimental Setup
Models Used#
The authors conduct experiments on 4 diverse model architectures:
- Qwen3-8B: Reasoning-oriented model
- Llama-3.1-8B-Instruct: Instruction-tuned model
- Phi4-14B: Fused MLP projections used instead of separate projection matrices
- GPT-OSS-20B: Mixture-of-Experts (MoE) model
Qwen3-8B and Llama-3.1-8B are tested under pruning ratios of 25% and 35% while Phi4-14B and GPT-OSS-20B, being bigger models, are tested only under the more aggression 35% compression.
Baselines#
The authors compare SNIPER's performance with that of the following baselines:
Evaluation Criteria#
In the absence of a single evaluation setup for pruning methodologies, the authors evaluate all methods against a comprehensive set of metrics, spanning 5 diverse domains.
| Domain | Tasks | Metric |
|---|---|---|
| Generative | Wikitext, Lambada | Log-Perplexity |
| World Understanding | PIQA, PROST, CommonsenseQA | Accuracy |
| Domain Knowledge | OpenbookQA, MathQA, ARC, MedQA | Accuracy |
| Linguistic Understanding | BLIMP, BoolQ, Lambada, Winogrande, COQA | Accuracy & F1 |
| Safety, Bias, and Ethics | Winogender, TruthfulQA, Moral Stories | Accuracy |
Results & Analysis
Many pruning methods benefit from a small post-compression fine-tuning phase to allow the model to recover from the significant distributional shift induced by the removal of its components. This is known as recovery fine-tuning (RFT). The authors test SNIPER under both no-RFT and RFT settings.
Performance Retention#
SNIPER wins at 9 out of 10 tested configurations. The only configuration where it doesn't win is when pruning LLaMA-3.1-8B-Instruct by 25% with RFT, where it is only marginally outperformed by ReplaceMe and ShortGPT.
It adapts better to larger and more complex architectures. It consistently outperforms its competitors by margins of up to 11.42\% and 16.48\% on Phi-4-14B and GPT-OSS-20B, respectively.
Performance Consistency#
In addition to demonstrating excellent performance retention, SNIPER demonstrates unparalleled consistency in its performance.
Unlike its baselines, SNIPER never collapses. Each baseline has at least one configuration where it disintegrates completely, falling to being one of the worst performing methods for that configuration. SNIPER, on the other hand, tops the rankings at a nearly perfect mean ranking of 1.25, sliding down to a rank of 3 at its worst.
| Method | Mean rank ↓ | Best ↓ | Worst ↓ |
|---|---|---|---|
| ReplaceMe | 4.75 | 1 | 7 |
| SliceGPT | 6.50 | 5 | 7 |
| LLM-Pruner | 4.00 | 2 | 6 |
| SLEB | 3.63 | 3 | 5 |
| ShortGPT | 3.70 | 2 | 7 |
| 2SSP | 3.55 | 1 | 6 |
| SNIPER | 1.25 | 1 | 3 |
It is also steadier across tasks. A pruned model may perform well on average while being disproportionately bad on a few specific tasks. Measuring the spread across tasks, SNIPER is the most consistent method in every configuration, including the ones where it doesn't win on average.
Ablation Study#
To analyze whether each of component of SNIPER is even required or not, the authors conduct an ablation study where they test its performance after removing components one at a time.
Depth pruning (stage 1) alone demonstrates strong performance. However, it lags behind SNIPER since its removal of large components can end up removing important individual neurons that are present in them. This leads to noticeably higher instability in the form of its higher standard deviation across tasks.
In contrast, width pruning (stage 2) alone is relatively more precise and stable with lower standard deviation. When both stages are operating together, stage 1's conditionally optimal decisions are likely able to balance the greedy decisions made by stage 2. However, in the absence of the first stage, the pruning pipeline ends up relying too much on these greedy decisions, leading to subpar performance.
Efficiency Gains#
Apart from reducing model size, pruning has another important benefit: it oftens produces models that perform faster than their base counterparts. Therefore, the authors analyze the speed-ups that each pruning method induces.
SNIPER yields competitive inference speed-ups, sitting right between width and depth pruning methods. Interestingly, 2SSP is able to beat even depth pruners but that's likely because even during its width pruning phase, it bypasses the irregular tensor shape problem by simply pruning the same number of neurons from each MLP. Unfortunately, this is a cost that SNIPER has to bear due to its dynamic budget allocation.
Additional Analyses
While the main results have been summarized in the previous section, there are some other interesting details that the authors analyse.
Runtime Analysis#
The authors also analyze the time it takes for SNIPER to prune a model. Firstly, as discussed earlier, SNIPER divides all parameter counts by a discretizing factor, \alpha. This reduces its time complexity to O(\lfloor \frac{NC}{\alpha} \rfloor).
However, this comes with a tradeoff to manage: if \alpha is too big, parameter counts may end up being scaled down so much that components of vastly different sizes can end up being assigned the same weight. On the other hand, if it's too big, it won't reduce stage 1's time complexity enough, making it slow and impractical.
A simple sweep of different values of \alpha reveals 32 to be a good enough conservative estimate that balances this tradeoff fairly well.
Next, they compare SNIPER's runtime with a width pruner (SliceGPT) and a depth pruner (SLEB). They find that SNIPER is only marginally slower than SLEB with most of its time going towards computing the importance estimates from stage 1.
importance estimation pruning itself — 56 s of SNIPER's 1572
Transferability of Importance Scores#
Seeing how importance estimation is the most computationally expensive step in SNIPER's pipeline, the question arises: can we re-use importance estimates across compression ratios?
Turns out, the answer is yes! While transferring scores across compression ratios leads to weaker performance than using the compression-specific scores, the drop in performance is not catastrophic by any means. This makes it viable to compute importance scores once on a compression ratio and re-use them as required.
Interpretable Importance Patterns Across Layers#
Quite interestingly, the scores computed via iterative estimation show a clear intuitive structure where early and late layers are given higher importance and intermediate layers are deemed relatively less important.
Moreover, there is a substantial overlap in the layers that are evicted across multiple compression ratios. This indicates that these importance estimates truly capture architectural importance rather than being influenced purely by the available budget.
Consistency Across Different Calibration Setups#
Limitation #4 points out that several pruners tend to over-rely on the calibration data used by them, causing them to perform disproportionately badly on out-of-distribution tasks. To analyze whether SNIPER also suffers from this issue, this paper observes how its performance changes with changes in:
- The number of calibration samples
- The calibration data distribution
SNIPER maintains excellent consistency across all calibration paradigms, with its average performance across each configuration differing by less than 1\%. Its per-task standard deviation is also consistently the lowest and does not peak significantly when changing the number of calibration samples or their distribution.