Sparsity & Pruning advanced 8 min read 12 flashcards

Second-Order and Activation-Aware Pruning

How the Hessian of the loss gives a principled importance score, why the exact version is intractable, and the two approximations that made one-shot pruning of large language models work.

Magnitude pruning asks how large a weight is. The better question is how much the loss would increase if the weight were removed, and that quantity has a closed form. The gap between the two questions is the whole content of second-order pruning, and closing it is what made it possible to remove half the weights from a 175B-parameter model in a few hours without retraining.

The Taylor expansion

Expand the loss around trained weights \(w^*\). The gradient is approximately zero at a converged solution, so the first-order term drops and the leading term is quadratic:

\[\Delta \mathcal{L} \approx \tfrac{1}{2}\,\delta w^\top H\,\delta w\]

Optimal Brain Damage assumes \(H\) is diagonal, giving the saliency \(\tfrac{1}{2} H_{ii} w_i^2\) per weight: magnitude weighted by curvature. Optimal Brain Surgeon keeps the off-diagonal terms and derives both the saliency and the optimal update to the remaining weights that compensates for the removal:

\[\text{saliency}_q = \frac{w_q^2}{2\left[H^{-1}\right]_{qq}}, \qquad \delta w = -\frac{w_q}{\left[H^{-1}\right]_{qq}}\left(H^{-1}\right)_{:,q}\]

That compensation is the important part. Removing a weight and adjusting its correlated neighbours costs far less loss than removing it alone, which is why second-order methods can prune one-shot where magnitude pruning needs retraining.

The obstacle is that \(H\) is \(n \times n\) in the number of parameters. For a billion-parameter model, storing it is impossible, let alone inverting it.

Making it tractable

SparseGPT (Frantar and Alistarh, 2023, arXiv:2301.00774) restricts the objective from the full loss to per-layer reconstruction error, \(\lVert WX - \hat{W}X\rVert^2\). For that objective the Hessian is \(2XX^\top\), of size \(d_{\text{in}} \times d_{\text{in}}\), computable from a few hundred calibration samples. It then prunes column by column with the OBS compensation applied to remaining weights, reusing one Hessian inverse across all output rows. This prunes a 175B model to 50 percent sparsity in a few GPU-hours with modest perplexity loss, and it is the same machinery as GPTQ with a different rounding target, which is why the two compose into one pass.

Wanda (Sun et al., 2024, arXiv:2306.11695) makes a sharper simplification. Score each weight by \(|w_{ij}| \cdot \lVert x_j \rVert_2\), the weight magnitude times the norm of the corresponding input activation across the calibration set. There is no Hessian, no inverse, and no weight update at all: it is a ranking and a mask. It matches SparseGPT closely on language models at 50 percent sparsity and runs in seconds rather than hours.

Wanda's success is informative. It says most of what the Hessian contributes on these models is the activation scale, which the diagonal already captures, and that transformer activation magnitudes vary enough across input channels that ignoring them is the dominant error in magnitude pruning.

When it breaks

Layer-wise reconstruction is not the loss. Both methods minimise per-layer output error against the original model's inputs, so errors compounding across layers are invisible to the objective. At high sparsity this matters, and sequential variants that propagate already-pruned activations do better.

The calibration set carries the whole method. The Hessian and the activation norms both come from a few hundred samples. Calibrating on one domain and deploying on another prunes for the wrong correlations, and the calibration perplexity will not show it.

One-shot at 50 percent is not one-shot at 80 percent. These methods degrade sharply above roughly 50 to 60 percent unstructured sparsity on language models without retraining. Beyond that, some fine-tuning is required and the "no retraining" selling point disappears.

Saliency assumes convergence. The Taylor expansion drops the first-order term because the gradient is zero at a minimum. On a model that is not converged, or one pruned mid-training, that term is not negligible and the saliency is wrong in a way the formula does not signal.

Check yourself

12 flashcards for this concept

Click a card to reveal the answer.

Drill the whole track