Weight Pruning in Large Language Models: Mathematical Foundations of Magnitude Pruning, Wanda, SparseGPT, and Semi-Structured 2:4 Sparsity
As frontier transformer models expand past hundreds of billions of parameters, model serving is constrained by memory capacity and memory bandwidth. In autoregressive token generation, memory bandwidth dominates latency because memory-bound matrix-vector operations require streaming entire weight matrices from High Bandwidth Memory (HBM) to on-chip SRAM for every single generated token.
Weight pruning reduces model size and memory bandwidth pressure by setting a fraction of weight parameters to zero. While classical pruning methods relied on iterative magnitude thresholding followed by extensive retraining, trillion-parameter foundation models cannot easily undergo compute-intensive fine-tuning cycles after compression. Modern post-training pruning techniques focus on one-shot, calibration-guided algorithms that sparsify models without backpropagation or parameter retraining.

The Mathematical Framework of Weight Pruning
Consider a single linear layer in a transformer network parameterized by weight matrix . Given an input activation tensor collected over calibration tokens, the layer computes output .
The goal of post-training weight pruning is to find a sparse weight matrix subject to a target sparsity constraint such that the layer output reconstruction error is minimized:
where denotes the Frobenius norm and counts non-zero entries.
Second-Order Taylor Approximations: OBD and OBS
The foundation of analytical pruning traces to Optimal Brain Damage (LeCun et al., 1989) and Optimal Brain Surgeon (Hassibi and Stork, 1992). Expanding the loss function around an optimized parameter vector via Taylor expansion:
where $g = \nabla_w \mathcal{L}(w^)$ is the gradient vector and $H = \nabla_w^2 \mathcal{L}(w^)$ is the Hessian matrix of second derivatives. Because pre-trained models reside near a local minimum, the first-order gradient , leaving the quadratic term .
When pruning parameter to zero (), Optimal Brain Damage assumes a diagonal Hessian, yielding the saliency score:
Optimal Brain Surgeon removes the diagonal assumption. By solving the constrained optimization problem subject to the constraint , OBS derives both the optimal parameter removal score and the compensatory weight update for remaining unpruned parameters:
where is the standard basis vector with 1 at index and is the -th diagonal element of the inverted Hessian matrix.
Magnitude Pruning and Its Breakdown in LLMs
Classical magnitude pruning ranks parameter importance purely by absolute magnitude:
In vision networks and smaller language models, magnitude pruning paired with iterative fine-tuning achieved high sparsity ratios. However, in modern decoder-only transformers (such as LLaMA, OPT, and BLOOM), one-shot magnitude pruning without retraining collapses perplexity at 20% to 30% sparsity.
The breakdown of magnitude pruning in large language models stems from emergent activation outliers. Research by Dettmers et al. (2022) revealed that once transformer models scale beyond 6.7 billion parameters, specific hidden dimensions develop activation magnitudes up to 100 times larger than average features. In linear transformations , a weight with small magnitude paired with an outlier input channel contributes heavily to output activations. Magnitude pruning drops these small weights, destroying critical signal pathways.
Wanda: Pruning by Weights and Activations
To address the activation outlier bottleneck without computing expensive second-order derivatives, Sun et al. (2023) proposed Wanda (Pruning by Weights and activations).
Wanda evaluates weight saliency by scaling the absolute weight magnitude by the -norm of the corresponding input activation column across calibration tokens:
Per-Output Row-Wise Comparison
Unlike global or whole-matrix sorting, Wanda evaluates pruning scores independently for each output channel (each row of ):
- Compute input activation norms for all input features over calibration samples.
- Form the saliency matrix where .
- For each row , sort entries and set the lowest elements to zero.
Wanda requires zero second-order Hessian inversions and zero parameter updates on remaining weights. Despite its simplicity, Wanda achieves 50% unstructured sparsity on LLaMA models with near-baseline perplexity, executing up to 300 times faster than full Hessian reconstruction methods.
SparseGPT: Large-Scale Second-Order Reconstruction
Frantar and Alistarh (2023) introduced SparseGPT, demonstrating that massive language models up to 175 billion parameters can be pruned to 50%–60% sparsity in one shot using exact second-order error compensation.
SparseGPT casts layer-wise pruning into a constrained least-squares problem over empirical activation covariance. For layer weights and calibration inputs , the empirical Hessian is given by:
where acts as a dampening factor to ensure numerical stability during matrix inversion.
Column-Wise Elimination and Batched Updates
Direct application of Optimal Brain Surgeon requires operations per pruned parameter, which is computationally intractable for matrices with or larger. SparseGPT reduces complexity through three architectural mechanics:
- Cholesky Inversion: SparseGPT computes the inverse Hessian once per layer using Cholesky factorization .
- Fixed Pruning Sequence: Parameters are evaluated column by column rather than searching globally across all remaining matrix entries.
- Lazy Batched Updates: Weight updates are accumulated across blocks of columns (e.g., block size ) and applied as matrix-matrix multiplications rather than sequential rank-1 updates.
When pruning column , the optimal weight adjustment for unpruned columns is computed as:
SparseGPT prunes 175B parameter models in under 4.5 hours on a single GPU while preserving downstream zero-shot accuracy.

Semi-Structured 2:4 Sparsity and Hardware Acceleration
While unstructured sparsity zeroes out arbitrary weights across the matrix, it produces random non-zero patterns that standard dense matrix multiplication hardware cannot accelerate efficiently without specialized sparse storage formats and sparse kernel overhead.
To bridge theoretical compression and real-world execution speed, modern GPU architectures (NVIDIA Ampere, Hopper, and Blackwell) implement native hardware support for semi-structured N:M sparsity, specifically 2:4 sparsity.
The 2:4 Sparsity Constraint
The 2:4 structured sparsity pattern mandates that for every contiguous block of 4 values along a row, exactly 2 values must be zero and 2 values remain non-zero (50% uniform sparsity):
On Sparse Tensor Cores:
- The non-zero values are packed into a dense tensor of half the original width ().
- A compact metadata tensor stores 2-bit column indices per non-zero element to map positions during hardware execution.
- Matrix multiply units read half the memory bandwidth and execute double the arithmetic throughput, delivering up to a theoretical 2x speedup over dense operations.
Pruning Under N:M Constraints
Both Wanda and SparseGPT adapt directly to 2:4 structured constraints:
- 2:4 Wanda: In each 4-element block , evaluate scores and prune the two elements with smallest scores.
- 2:4 SparseGPT: In each 4-element block, select the two weights whose elimination minimizes the second-order reconstruction error, then apply OBS compensatory updates to all trailing columns.
Comparative Trade-Offs and Architectural Analysis
Understanding the trade-offs across pruning strategies guides deployment decisions in production inference pipelines:
- Unstructured Magnitude Pruning: Lowest compute overhead ( per weight), but high perplexity degradation past 20% sparsity in LLMs due to activation outlier neglect.
- Wanda: Fast calibration pass (), accounts for activation outlier channels without matrix inversions, retains baseline accuracy up to 50% unstructured sparsity.
- SparseGPT: Second-order Hessian inversion (), compensates remaining weights, achieves superior accuracy at higher sparsity ratios (60%+) and under strict 2:4 structured constraints.
- Hardware Acceleration: Unstructured sparsity primarily saves disk storage unless paired with specialized CPU/GPU sparse runtimes. In contrast, 2:4 semi-structured sparsity delivers direct inference latency speedups on NVIDIA Tensor Cores.
Sources
- LeCun, Y., Denker, J. S., & Solla, S. A. (1989). Optimal Brain Damage. Advances in Neural Information Processing Systems (NeurIPS 1989). https://proceedings.neurips.cc/paper/1989/file/6c340f25808812b26aaf40f1a0a83229-Paper.pdf
- Hassibi, B., & Stork, D. G. (1992). Second Order Derivatives for Network Pruning: Optimal Brain Surgeon. Advances in Neural Information Processing Systems (NeurIPS 1992). https://proceedings.neurips.cc/paper/1992/file/303ed4c69846ab36c2904d3ba8573050-Paper.pdf
- Frantar, E., & Alistarh, D. (2023). SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot. Proceedings of the 40th International Conference on Machine Learning (ICML 2023). https://arxiv.org/abs/2301.00774
- Sun, M., Liu, Z., Bair, A., & Kolter, J. Z. (2023). A Simple and Effective Pruning Approach for Large Language Models. International Conference on Machine Learning (ICML 2023). https://arxiv.org/abs/2306.11695
- Mishra, A., Latorre, J. A., Pool, J., Stosic, D., Stosic, D., Venkatesh, G., Yu, C., & Micikevicius, P. (2021). Accelerating Sparse Deep Neural Networks. arXiv preprint. https://arxiv.org/abs/2104.08378
- Dettmers, T., Lewis, M., Belkada, Y., & Zettlemoyer, L. (2022). LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale. Advances in Neural Information Processing Systems (NeurIPS 2022). https://arxiv.org/abs/2208.07339
