AI State of the Art
SOTA/Inference & Optimization/33 min
Section 129

Pruning: Structured vs Unstructured, Magnitude, Wanda

Listen as a podcast →

The Distinction That Decides Everything

This page has one point, and it is almost always glossed over. There are two ways to remove weights from a model, and they do not produce remotely the same result:

  • Unstructured pruning sets weights to zero, one at a time, where they sit. The matrix keeps its exact shape; it is simply full of zeros. The model does not get smaller as far as the hardware is concerned.
  • Structured pruning removes whole pieces, an attention head, a channel, an entire layer. The matrix genuinely shrinks. The model really is smaller.

A pruning run advertised at "50%" that speeds up nothing at all is not an accident or a bug: it is the normal outcome of the first case. If you take one thing away from this lesson, take that. The rest explains why.

The Problem: Models Carry Weights That Do Little

A tree has dead branches. Cutting them does not hurt its health. Neural networks are partly the same: many weights contribute very little to the predictions.

Why do they exist? During training the network explores many directions. Some weights settle at values close to zero. Others compensate for accidents of training rather than capturing anything useful. The network is over-parameterised on purpose, because that helps it converge, but that slack serves no purpose once training is over.

Sun, Liu, Bhatt & Kolter (2023), A Simple and Effective Pruning Approach for Large Language Models (Wanda)
The network lottery

The Lottery Ticket Hypothesis states that inside any dense network there exists a sparse sub-network (a subset of the weights) which, retrained on its own from the same initialisation, reaches the same quality as the full network. Put differently: the "real" model is smaller than the one you trained; you just have to find it inside.

Be careful about what the hypothesis does and does not say. It asserts that such a sub-network exists, and it assumes retraining. It does not promise that you will find it in one shot in a language model of several billion parameters, nor that it will run faster.

Frankle & Carbin (2018), The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks

The Scalpel: Unstructured Pruning

The idea is simple: walk the weight matrix, find the smallest values, replace them with zeros. The result is a matrix that looks like Swiss cheese: holes scattered irregularly.

The upside is surgical precision. You choose exactly which weights to sacrifice, one by one, with no constraint on shape.

The problem is that your graphics card has no idea what to do with it. It is worth seeing why, because this is where the whole misunderstanding lives.

A graphics card multiplies dense matrices, reading every coefficient, including the ones that are zero. It cannot skip them: it does not know in advance where they are. So after unstructured pruning:

  • the number of operations is unchanged: it still multiplies just as many numbers, it simply multiplies a lot of them by zero;
  • the number of bytes read is unchanged too: zeros are stored like any other number.

But inference in a large language model (LLM) is limited by memory bandwidth, by how long it takes to stream the weights from memory into the compute units; that argument is laid out in Quantization: the concepts. Since unstructured pruning reduces neither the operations nor the bytes read, it mechanically cannot speed anything up. That is a predictable result, not a disappointment.

What about the space saving?

It exists, but it needs a sparse format: instead of storing the whole matrix, you store only the non-zero values plus, for each, a note of where it goes. And that note costs space.

Do the arithmetic. At 50% sparsity you keep half the values, but you add one index per kept value. If the index weighs as much as the value, you have saved nothing at all. Compression only becomes clearly worthwhile at much higher sparsity levels, or with a regular pattern whose position can be encoded in very few bits, which is exactly the idea behind the 2:4 format below.

So never conflate three separate things: zeroing out, taking up less space, and running faster.

The Chainsaw: Structured Pruning

Here you remove whole structures: a complete attention head, an entire unit in a layer, a channel, or a full transformer layer. The result is an architecturally smaller model that stays perfectly regular, a dense matrix, just a narrower one.

Picture a 32-storey building. Unstructured pruning takes out bricks here and there: the building is the same height, with holes in it. Structured pruning takes out whole floors: you get a 24-storey building, smaller and entirely standard.

Three neural networks drawn as layers of circles joined by arrows. On the left, Before pruning: a dense network with four grey inputs, two blue hidden layers of five then four units, and two red outputs, with every connection present. Top right, after unstructured pruning: the same units are all still there, but most arrows are gone and the remaining ones form an irregular pattern. Bottom right, after structured pruning: the second hidden layer holds only two units instead of four, the others having been removed along with all their connections.
The two strategies on the same network, and the best summary of this page. Top right, unstructured pruning: every unit is still there, connections have been cut one by one in an irregular pattern, the shape of the network is unchanged, so the hardware sees exactly the same amount of work. Bottom right, structured pruning: whole units are gone along with all their connections, and the network really is smaller.Source : Sebastian Pokutta, research blog (Bi-directional Magnitude Pruning)

The upside: it genuinely speeds things up, with no special hardware. Removing a quarter of the layers means a quarter fewer weights to stream per token, so roughly a quarter less time.

The problem: it is far more brutal. You no longer pick weights one at a time; you carry off whole blocks, some of whose coefficients were useful.

How far you can cut layers

A 2024 study measured what removing entire layers costs in open-weight models. Its conclusion: degradation stays minimal until a large fraction (up to half) of the layers has been removed, provided a short repair phase follows.

Two caveats to hold on to. That repair is not optional: the authors do it with QLoRA, a memory-frugal fine-tuning method (see QLoRA). And the result is measured on multiple-choice-style benchmarks; it does not guarantee that a model shorn of half its depth still reasons as well through a ten-step derivation.

Gromov et al. (2024), The Unreasonable Ineffectiveness of the Deeper Layers

The Hardware Compromise: The 2:4 Pattern

There is a middle form, and it is the only one that delivers both space and speed without touching the architecture: 2:4 sparsity. The rule is mechanical: in every group of 4 consecutive coefficients you keep exactly 2 and zero the other 2.

Why does that change everything? Because the position of the zeros becomes predictable. The hardware knows there are exactly 2 values per group of 4, and 2 bits are enough to say which. NVIDIA cards from the Ampere architecture onward (the A100, then Ada cards such as the RTX 4090) contain dedicated units, the Sparse Tensor Cores, that consume this format directly.

NVIDIA 2:4 sparsity processing chain. On the left, a blue square matrix labelled Dense trained weights. An arrow marked Fine-grained structured pruning (2:4 non-zero) leads to the same matrix where, in each group of four neighbouring cells in a row, two are blacked out and annotated zero; a Fine-tuning weights loop returns to that step. A Compress arrow leads to two narrower arrays: Non-zero data in blue and Non-zero indices in purple. Both feed a green Sparse Tensor Core box, where select multiplexers pick the matching input activations before a dot-product, producing the Output activations in green.
The 2:4 pattern in practice. In the second matrix, the black cells are the zeroed weights: exactly two per group of four. That regularity is what makes the Compress step pay off (only the non-zero values are stored, plus two index bits each) and that compressed format is what the Sparse Tensor Core reads directly. Note the Fine-tuning weights loop going back: the pattern is constraining enough that the model often has to be readjusted afterwards.Source : NVIDIA Technical Blog, NVIDIA Ampere Architecture In-Depth
The real speedup factor: 1.24, not 2

You commonly read that the 2:4 format "doubles the speed". The number 2 is the theoretical throughput ratio of the Sparse Tensor Cores, a datasheet ceiling, not a measurement.

The Wanda authors did measure. On the matrix multiplications in the linear layers of LLaMA-65B they get 1.54 to 1.63 times faster depending on the layer. And end to end, on LLaMA-7B, they measure 1.24 times, 251 milliseconds instead of 312.

The gap between 2 and 1.24 is not an anomaly: it is what always happens when you accelerate only part of the work. The rest of the model (attention, normalisations, reading the attention cache) has not got any faster, and ends up dominating.

Wanda: The Simple Method That Works

The reference method for pruning an LLM without retraining is Wanda, short for Pruning by Weights and activations.

The intuition. Classical methods drop the weights that are smallest in absolute value. But a small weight wired to an input that consistently takes very large values has far more influence than a large weight wired to an input that hovers near zero. What matters is not the weight alone, it is the product of the weight and what flows through it.

Sij=∣Wij∣×∥Xj∥2S_{ij} = |W_{ij}| \times \lVert X_j \rVert_2

Symbol by symbol. SijS_{ij} is the importance score of the weight at row ii, column jj: the lower it is, the more that weight is a candidate for removal. ∣Wij∣|W_{ij}| is the absolute value of that weight, its size stripped of its sign, a weight of −3-3 and a weight of +3+3 count the same. XjX_j gathers all the values observed on input number jj during measurement, and ∥⋅∥2\lVert \cdot \rVert_2 is the Euclidean norm: the square root of the sum of squares, in plain terms "how much this input moves around, on average".

In one sentence: a weight matters if it is large and wired to an active input.

The office analogy: an employee's influence is not just their title (the weight's value), it is also the volume of files crossing their desk (the activation).

The other half of the method: what you compare against

The paper stresses a point that gets lost when only the formula is remembered. Having a score is not enough; you have to decide against whom it is compared before you cut.

Wanda compares weights within each output (every unit discards the same proportion of its own inputs) rather than across the whole layer. That is what stops one unit from being emptied entirely while another keeps everything. The authors show by ablation that this choice matters as much as the scoring formula itself.

Figure comparing two pruning methods on the same small three-row, four-column weight matrix containing the values 4, 0, 1, -1 / 3, -2, -1, -3 / -3, 1, 0, 2. On the left, Magnitude Pruning: the importance score is the absolute value of the weight, computed over the whole layer, and the pruned matrix keeps only 4, 3, -2, -3, -3 and 2. On the right, Wanda: an activation-norm vector of 1, 2, 8, 3 is shown under the weight matrix; the score is the absolute weight times that norm, computed row by row, and the pruned matrix keeps different weights, notably 1 in the first row and -1, -3 in the second.
The same block of weights, pruned two ways. On the left, the classical criterion looks only at the size of the weight. On the right, Wanda multiplies each weight by the activation norm of its input column: the column whose activation is 8 suddenly matters, and weights of 1 or -1 survive where they would have been cut on the left. Note the row-by-row wording on the right: that is the per-output comparison group, the second half of the method. The two final matrices differ, at exactly the same sparsity rate.Source : Wanda paper (Sun et al., 2023), authors' project page

What makes the procedure usable is its cost: you only need to measure the activations, which means pushing a small sample through the model. The paper uses 128 sequences drawn from a public web-text corpus. No retraining, no update to the surviving weights: you compute the scores, zero the lowest ones, and use the model as is.

Computing the criterion is almost free. The authors time it at 0.54 seconds on LLaMA-7B, against 203 seconds for SparseGPT, the competing method that solves a layer-by-layer optimisation problem. That is Wanda's real result: a one-line formula for a four-hundredth of the time.

What 50% Sparsity Actually Costs

Here are the paper's numbers, because they say something the summaries do not.

First, perplexity on a corpus the model has never seen. Perplexity measures how surprised the model is by the text: lower is better. A perplexity of 5 means that at each word the model hesitates roughly as if it were choosing among 5 equally likely options.

LLaMA-2-7B, 50% unstructured sparsityPerplexity
Dense model, unpruned5.12
Magnitude pruning (smallest weights)14.89
SparseGPT6.51
Wanda6.42

Two readings. First: Wanda crushes magnitude pruning, 6.42 against 14.89, the naive criterion destroys the model, adding the activations rescues it. Second, less often quoted: 6.42 is not 5.12. Pruning half the weights of a 7-billion-parameter model costs about a quarter more perplexity. That is not nothing.

And here is the genuinely interesting result, on mean accuracy at tasks the model was never trained on (higher is better):

Mean accuracy, 50% unstructured sparsity7 billion65 billion
Dense model59.9966.97
Wanda54.2166.67
Gap−5.8 points−0.3 point

The gap closes as the model grows. At 7 billion parameters, removing half the weights costs nearly 6 points; at 65 billion it costs a third of a point, and the authors note that on LLaMA-2-70B the 50%-sparse model matches the dense one. That is the right way to say "you can remove half the weights": it is true of very large models, and considerably less true of small ones.

The 70-to-90% figures you read elsewhere

You often meet the claim that 70 to 90% of the weights can be removed while keeping good performance. That figure comes from the literature on small vision networks, retrained after pruning. On a large language model without retraining, the literature's reference point is 50%, and the table above shows what that 50% alone already costs a 7-billion-parameter model. Be sceptical of any rate quoted without two things attached: the size of the model, and whether retraining took place.

The price of the 2:4 pattern

The 2:4 format charges for its regularity. Still on LLaMA-7B, the "exactly 2 out of 4" constraint takes perplexity from 6.42 (free 50% sparsity) to 11.02, and mean accuracy from 54.21 to 48.53, at the same sparsity rate of 50%. The difference is not how much was removed, it is being forced to remove it in a prescribed pattern, which forbids keeping three important neighbouring weights.

So the real 2:4 trade is: 1.24 times faster end to end, against a quality loss markedly worse than free sparsity at the same rate.

Choosing, According to What Is Blocking You

The choice follows entirely from your actual constraint:

  • You are short of memory. Look at quantization first: it divides the space by 4 going from 16 bits to 4, with no pattern and no indices to manage. Unstructured pruning comes after that, and only if you have a sparse format and a library able to read it.
  • You are short of speed. Then it has to be structured, or the 2:4 format. Unstructured will do nothing for you, whatever rate is advertised.
  • Both. Structured or 2:4, plus quantization. The two levers are independent: one removes weights, the other cuts the bytes per surviving weight, and their gains multiply.

A word about ordinary processors, where the picture differs: on a central processor, specialised libraries can exploit irregular sparsity where a graphics card cannot. That is the bet behind engines such as DeepSparse. It does not change the general rule, it tells you where to look for the exception.

Finally, keep the habit of checking. A pruning result is judged on three numbers that are not interchangeable: the sparsity rate (how many weights were zeroed), the file size (how many bytes were actually saved), and the token throughput (how much speed was gained). An announcement that gives only the first says nothing about the other two.

Check your understanding0 / 5

1. A team announces a model « pruned to 50 percent ». You notice the file is the same size and inference is no faster. What most likely happened?

2. Magnitude pruning removes the smallest weights and blows up perplexity (14.89 versus 6.42 for Wanda). What is the idea that rescues Wanda?

3. Can you really « remove half of an LLM's weights with no loss », as one often reads?

4. NVIDIA's Sparse Tensor Cores advertise doubled throughput with the 2:4 format. What did the Wanda authors actually measure?

5. One often reads that 70 to 90 percent of a network's weights can be removed while keeping good performance. Why doesn't that figure carry over to LLMs as is?