# SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot

Elias Frantar, Dan Alistarh · arXiv · 2023-1-2

- **Problem** Accurate one-shot pruning methods that avoid retraining become too slow for GPT-family models with billions of parameters.
- **Method** SparseGPT prunes each layer column by column, reuses a shared sequence of Hessian inverses through OBS-style weight updates, and selects the mask in blocks of 128 columns.
- **Results** Reached 8.21 perplexity on raw-WikiText2 at 50% unstructured sparsity on OPT-175B, against 8.35 for the dense model.

![Figure 4: \[Left\] Visualization of the SparseGPT reconstruction algorithm. Given a ﬁxed pruning mask M, we incrementally prune weights in each column of the wei…](https://refivu.com/papers/98e70bdf-a832-4686-b3f8-e3eefd5887c4/figures/figure-8a0a9e653ca9885853a3c11a812a3d80.png?thumb=512)

**Figure 4** . \[Left\] Visualization of the SparseGPT reconstruction algorithm. Given a ﬁxed pruning mask M, we incrementally prune weights in each column of the weight matrix W, using a sequence of Hessian inverses (HUj )−1, and updating the remainder of the weights in those rows, located to the “right” of the column being processed. Speciﬁcally, the weights to the “right” of a pruned weight (dark blue) will be updated to compensate for the pruning error, whereas the unpruned weights do not generate updates (light blue). \[Right\] Illustration of the adaptive mask selection via iterative blocking.

[Original paper](https://arxiv.org/abs/2301.00774v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Elias Frantar, Dan Alistarh · SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot · Original paper figure · Extracted the figure area from page 4 of the original PDF.

## Why pruning GPT-scale models without retraining is hard

Most compression work on GPT-family models has targeted quantization, which lowers the numerical precision of the weights. Pruning removes weights or whole structures instead, and its strongest results have come with retraining afterwards. A 175 billion parameter model needs at least 320GB just to hold its half-precision weights, which makes the cost of retraining hard to justify.

One-shot pruning avoids retraining, but the accurate one-shot methods become very expensive on models with billions of parameters. Even AdaPrune, the method tuned for the best speed and accuracy trade-off, needs a few hours for a model with 1.3 billion parameters and would scale to several hundred hours at 175B. Prior accurate post-training methods were designed for models of a few hundred million parameters, while the target here is models up to 1000 times larger.

The full-model problem is split into layer-wise subproblems. For each layer, the goal is a sparsity mask and updated weights that minimise the l2 error between the dense layer output and the compressed one on given inputs. Choosing the mask and the weights jointly is NP-hard, so practical methods approximate, often by choosing the mask first and then reconstructing the surviving weights with the mask fixed.

Follow-up methods relax that separation: iterative AdaPrune reoptimises in gradual steps, and OBC removes weights one at a time with closed-form reconstruction after each step.

The authors state that they are the first to investigate pruning of massive GPT-scale models with more than 10 billion parameters.

## What SparseGPT changes

SparseGPT turns the pruning problem into a set of very large sparse regression instances and solves them with a new approximate solver. The solver is built from careful approximations to closed-form equations rather than from iterative optimisation, which keeps the runtime and the accuracy both manageable at giant model sizes.

The solver keeps the layer-wise view, but it changes how the inverses are computed and it selects the pruning mask during reconstruction instead of before it. Mask selection that follows the weight updates lets the sparsity fall unevenly across columns, which the fixed-mask approach cannot do.

The method uses no global gradient information. Each layer's weight updates are chosen to preserve that layer's input-output relation, which keeps the method local.

## Why exact reconstruction is too slow

For a fixed mask, each row's surviving weights are obtained exactly by solving a linear system. The system uses the Hessian of only the input features that the row keeps, and the Hessian is formed from the layer inputs as H = XX^T.

Each row has its own mask, so each row needs its own inverse of a d\_col by d\_col matrix. One inversion costs O(d\_col^3), and the total over d\_row rows is O(d\_row · d\_col^3). For a Transformer this means the runtime grows with the fourth power of the hidden dimension, so a speedup of at least a full factor of d\_hidden is needed for a practical algorithm.

The inverse of a masked Hessian is not the masked version of the full inverse, so one global inverse cannot be reused directly across rows. Forcing all rows to share one mask would allow a single shared inverse, but it would hurt accuracy, because removing whole structures such as columns is much harder than removing individual weights.

Rows are sparsified independently, so each row's masked Hessian differs from the others.

## Pruning one weight at a time with OBS updates

Removing one weight with an OBS update adjusts the remaining weights by a scaled column of the inverse Hessian, and it incurs the error given in the second expression. Because the layer loss is quadratic, this update is exact, and pruning weights one at a time reaches the same optimum as solving for the full mask at once.

If only a subset U of the surviving weights is updated, the update remains optimal for that subset, and the Hessian of U replaces the full one. Using a smaller subset makes the inversion cheaper, since inverting the Hessian of U is faster than inverting that of the full mask when \|U\| is smaller than \|M\|.

The subsets U\_j start from all input indices and drop the smallest remaining index at each step. Each inverse in the sequence follows from the previous one by a single Gaussian elimination step.

Columns are processed in order. Each inverse in the Hessian sequence is computed once and reused for every row whose mask removes that input index, and the pruned weight's error is pushed onto the not yet pruned weights to its right.

Read as a greedy column-wise compression, a pruned entry is set to zero and the remaining entries are frozen, so a frozen weight is never changed again by a later update.

## Choosing the mask during reconstruction

Choosing the mask by magnitude ignores that earlier weight updates change the weights through correlations between inputs. Selecting the easiest p% of weights in each column would impose the same sparsity on every column, which is a poor fit for massive models that have a few highly sensitive outlier features.

The mask is selected for blocks of Bs = 128 columns at a time, using the OBS reconstruction error and the diagonal values of the Hessian sequence. The next Bs weight updates are then performed before the mask for the following block is selected. For a single column the diagonal entries are constant across rows, so the criterion reduces to weight magnitude.

For n:m patterns the block size is set to m, so each group of m consecutive weights must contain exactly n zeros, chosen as the lowest-error weights in each row. The 2:4 pattern is the one that speeds up inference on Ampere NVIDIA GPUs. A larger block would not help here, because zeros cannot be distributed non-uniformly between the groups of size m.

## How pruning and quantization share one pass

Algorithm 1 follows the column-wise greedy scheme of GPTQ. It inherits a Cholesky factorization of the inverse Hessian for numerical robustness and lazy batched updates that improve the compute-to-memory ratio.

For joint sparsification and quantization, weights frozen by SparseGPT are also quantized, and the error passed to the update step is the weight minus the masked quantized value, divided by the diagonal entry of the inverse Hessian factor. Prior joint techniques first sparsify a layer and then quantize the remaining weights, which does not let the two decisions interact.

## Calibration data, models and evaluation

SparseGPT is implemented in PyTorch with the HuggingFace Transformers library, and all pruning runs use a single A100 GPU with 80GB of memory. On this setup the 175-billion-parameter models are sparsified in approximately 4 hours, and layers are processed sequentially to reduce memory use.

Calibration uses 128 segments of 2048 tokens, drawn from the first shard of the C4 dataset, so that no task-specific data is seen during pruning. The experiments primarily use the OPT family to study scaling, and also include the 176 billion parameter version of BLOOM.

Perplexity is the main metric, measured on raw-WikiText2, PTB and a subset of the C4 validation data. ZeroShot accuracy is reported on Lambada, ARC (Easy and Challenge), PIQA and StoryCloze as a complementary measure.

The baseline is magnitude pruning applied layer-wise, which scales to the largest models, and AdaPrune is compared on models up to 1B parameters.

## How accuracy changes with model size

On OPT-175B, the dense model reaches 8.35 perplexity on raw-WikiText2, and SparseGPT at 50% unstructured sparsity reaches 8.21. The 4:8 pattern gives 8.45 and the 2:4 pattern gives 8.74 on the same model, while magnitude pruning at 50% gives 4.3e4.

The slight improvement over the dense baseline on the largest model seems to depend on the dataset, since no such decrease appears on PTB or the C4 subset. At 2.7 billion parameters the perplexity loss from SparseGPT is about 1 point, and at 66B it is essentially zero.

AdaPrune takes about 1.3 hours on a 350M model and about 4.3 hours on a 1.3B model, while SparseGPT fully sparsifies the 66B and 175B models in roughly the same time on the same A100 GPU.

At the largest scale, the perplexity increase over dense is 0.11 for 4:8 and 0.39 for 2:4 sparsity. The authors attribute the trend that larger models are easier to sparsify to overparametrization, and leave a detailed investigation to future work.

On OPT-175B, magnitude pruning completely collapses beyond 30% sparsity and keeps accuracy only up to about 10%, while SparseGPT reaches up to 60% sparsity at a comparable perplexity increase.

BLOOM-176B tolerates magnitude pruning up to about 30% without major loss, and SparseGPT still delivers 50% sparsity at a similar level of perplexity degradation.

## ZeroShot accuracy on OPT-175B

On OPT-175B, the ZeroShot average is 70.29 for the dense model and 70.52 for SparseGPT at 50% sparsity, while the 4:8 and 2:4 variants average 69.62 and 69.11. Magnitude pruning at 50% averages 31.10 on the same tasks.

Magnitude-pruned models fall close to random performance, while SparseGPT models stay near the original accuracy.

Per-task numbers are noisier: the 2:4 variant scores 80.92 on Lambada against 75.59 for the dense model, even though 2:4 is the most constrained pattern. The authors expect these effects to average out across many tasks.

## Combining sparsity with quantization and with partial 2:4 pruning

Storing only the non-zero weights with a bitmask makes 50% sparsity plus 4-bit weights use the same memory as 3-bit quantization, so the comparison is against 3-bit GPTQ. On OPT-175B, 50% sparsity with 4-bit weights gives 8.29 perplexity, against 8.68 for 3-bit.

Combined with 4-bit weights on OPT-175B, the 2:4 and 4:8 patterns give 8.55 and 8.85 perplexity, and the authors read the extra cost of 4-bit weights on top of semi-structured sparsity as about 0.1 perplexity.

An appendix reports that 50% sparsity with 3-bit weights, corresponding to 2.5-bit storage, gives 8.60 on OPT-175B, against 8.94 for GPTQ at 2.5 bits. The 4:8 pattern with 3-bit weights gives 8.93.

On OPT-175B, sparsifying the first half of the layers to 2:4 gives 8.22 perplexity, against 8.74 when all layers are 2:4.

## Measured inference speedups

With the DeepSparse engine on an Intel CPU, end-to-end inference of OPT-2.7B at 50% sparsity is 1.82× faster than the dense model, for a single batch of 400 tokens on 18 cores. At 40% and 60% sparsity the speedups are 1.57× and 2.16×.

The authors note that support for the larger variants was still under development, so these CPU numbers cover only OPT-2.7B.

2:4 sparsity on Ampere and newer NVIDIA GPUs theoretically doubles matrix multiplication speed. Against cuBLAS, with 2048 tokens and the three layer shapes of OPT-175B, the measured speedups are 1.79×, 1.67× and 1.54× for Q/K/V/Out, FC1 and FC2.

These GPU figures are for individual layers, and the authors expect end-to-end speedups to be somewhat lower because of overheads such as attention.

## Sensitivity to calibration, dampening and block size

The ablations use OPT-2.7B at the default 50% sparsity and report raw-WikiText2 only. More calibration samples keep improving perplexity, but only up to a point, where the curve flattens, so 128 samples are used throughout.

Hessian dampening is a value multiplied by the average diagonal value. Values between 0.001 and 0.1 perform similarly, and only very high dampening degrades quality noticeably. The default is 1%.

Both column-wise blocks (block size 1) and near-full blocks (4096 and 8192) do clearly worse than moderate blocking, and a broad range of block sizes works well. The authors choose block size 128, which lies in that range and matches the default lazy update batch size.

Five runs with different random seeds for calibration sampling give 13.52 ± 0.075 mean and standard deviation, which the authors read as robustness to the calibration data.

Compared with exact reconstruction on the same mask and Hessian, SparseGPT's layer errors on the first half of OPT-2.7B at 50% sparsity are on average about 20% worse, with some early attention out-projection layers as outliers. On the later fully-connected-2 layers the gap gets close to 10%.

## Limitations

The accuracy evidence is mainly perplexity on raw-WikiText2, PTB and a C4 subset, with ZeroShot averages that the authors describe as noisier.

The sweeps over sparsity cover OPT and BLOOM, and the comparison with AdaPrune is limited to models up to 1B parameters. At 2:4 and 4:8, accuracy loss relative to the dense baseline is visible for smaller models.

The speed results are preliminary: the CPU study covers only OPT-2.7B, and the GPU numbers are per-layer measurements.

The joint quantization results are presented as initial investigations, and the reason larger models are easier to sparsify is left open.

## Paper info

- **Authors**: Elias Frantar, Dan Alistarh
- **Venue**: arXiv · Preprint
- **First published**: 2023-1-2
- **Added**: 2026-10-20
- **Updated**: 2023-3-22
- **Version**: v3
- **arXiv**: 2301.00774
- **Category**: cs.LG
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2301.00774v3) · [PDF ↗](https://arxiv.org/pdf/2301.00774v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

We show for the first time that large-scale generative pretrained transformer (GPT) family models can be pruned to at least 50% sparsity in one-shot, without any retraining, at minimal loss of accuracy. This is achieved via a new pruning method called SparseGPT, specifically designed to work efficiently and accurately on massive GPT-family models. We can execute SparseGPT on the largest available open-source models, OPT-175B and BLOOM-176B, in under 4.5 hours, and can reach 60% unstructured sparsity with negligible increase in perplexity: remarkably, more than 100 billion weights from these models can be ignored at inference time. SparseGPT generalizes to semi-structured (2:4 and 4:8) patterns, and is compatible with weight quantization approaches. The code is available at: https://github.com/IST-DASLab/sparsegpt.

## Quote from the paper

Elias Frantar, Dan Alistarh (2023). SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot. arXiv:2301.00774v3. https://arxiv.org/abs/2301.00774v3

**BibTeX**

```
@misc{frantar2023sparsegpt,
  title = {{SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot}},
  author = {Elias Frantar and Dan Alistarh},
  year = {2023},
  eprint = {2301.00774},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2301.00774v3}
}
```

## Other paper commentary

- [Fast Inference from Transformers via Speculative Decoding](https://refivu.com/en/papers/41a03564-b5d1-4b7f-8db4-502dbc43fbe0-fast-inference-from-transformers-via-speculative-decoding.md)
- [GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers](https://refivu.com/en/papers/46a31638-80a6-4626-a5e7-028ae5ccea93-gptq-accurate-post-training-quantization-for-generative-pre.md)
- [ZeRO: Memory Optimizations Toward Training Trillion Parameter Models](https://refivu.com/en/papers/30a4fae5-65d8-4fa2-8552-c186c4a4d88f-zero-memory-optimizations-toward-training-trillion-parameter.md)
- [Linformer: Self-Attention with Linear Complexity](https://refivu.com/en/papers/470ce67a-0f79-4a06-ae89-f26384095187-linformer-self-attention-with-linear-complexity.md)
- [Reformer: The Efficient Transformer](https://refivu.com/en/papers/0dd490a3-709f-4bac-ae3f-de0bc9e197db-reformer-the-efficient-transformer.md)
- [Generating Long Sequences with Sparse Transformers](https://refivu.com/en/papers/25192f20-3966-40d3-94ed-65ebcaba60f7-generating-long-sequences-with-sparse-transformers.md)
- [GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints](https://refivu.com/en/papers/11792bcd-8c73-4a2d-8b43-c855c3d7ad48-gqa-training-generalized-multi-query-transformer-models-from.md)
- [Fast Transformer Decoding: One Write-Head is All You Need](https://refivu.com/en/papers/65f892e7-2a21-4ce7-9e89-c75f7ec6b23c-fast-transformer-decoding-one-write-head-is-all.md)
- [Finetuned Language Models Are Zero-Shot Learners](https://refivu.com/en/papers/3dedf278-64d7-4653-93ff-bf4504ae70ac-finetuned-language-models-are-zero-shot-learners.md)
- [Dynamic Routing Between Capsules](https://refivu.com/en/papers/a4e87f62-36cc-47df-991e-87dd01b1a4ef-dynamic-routing-between-capsules.md)
- [Neural Machine Translation of Rare Words with Subword Units](https://refivu.com/en/papers/0950e659-f6cc-4852-b244-bbb2742bf059-neural-machine-translation-of-rare-words-with-subword.md)
- [Constitutional AI: Harmlessness from AI Feedback](https://refivu.com/en/papers/91e9437c-36ce-49cd-965c-18d9ca4664d6-constitutional-ai-harmlessness-from-ai-feedback.md)

## Terms in this paper

- [perplexity](https://refivu.com/en/terms/2b204e513801-perplexity)
- [C4](https://refivu.com/en/terms/87725552ed79-c4)
- [Hessian](https://refivu.com/en/terms/cb53640b58ff-hessian)
- [GPTQ](https://refivu.com/en/terms/9c1044f95540-gptq)
- [calibration data](https://refivu.com/en/terms/a47b8a88152c-calibration-data)
- [magnitude pruning](https://refivu.com/en/terms/2d43489c4d0e-magnitude-pruning)
- [OPT-175B](https://refivu.com/en/terms/1c998ad8fa5f-opt-175b)
- [PTB](https://refivu.com/en/terms/564f7a31fbb0-ptb)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/98e70bdf-a832-4686-b3f8-e3eefd5887c4-sparsegpt-massive-language-models-can-be-accurately-pruned)
