Pruning
Pruning removes low-importance weights, filters, or layers from a trained neural network to shrink it and speed up inference, then fine-tunes to recover.
Pruning is a model optimization technique that removes weights, neurons, filters, attention heads, or whole layers that contribute little to a trained neural network's output, leaving a smaller model that needs less memory, compute, and energy. In deep learning the term is a synonym for model pruning. Most networks are heavily over-parameterized: Han et al. cut AlexNet from 61 million to 6.7 million parameters and VGG-16 from 138 million to 10.3 million on ImageNet with no loss of accuracy by training, removing low-magnitude connections, and retraining the rest. Pruning is a common step before edge AI deployment, where memory, power, and inference latency budgets are tight.
How Pruning Works#
Every pruning method decides which parameters to remove and when to remove them. The importance score is usually weight magnitude, since near-zero weights change the output least, while gradient-based scores estimate each parameter's effect on the loss function more directly. Removing a large fraction at once tends to cost more accuracy than iterative pruning, which removes a small fraction, fine-tunes the remaining weights to recover, and repeats until the size or speed target is met. The Lottery Ticket Hypothesis adds that dense networks contain sparse subnetworks that, reset to their original initialization, train on their own to accuracy comparable to the full network.
Unstructured, Structured, and Semi-Structured Pruning#
Unstructured pruning zeroes individual weights anywhere in a tensor. It reaches the highest sparsity for a given accuracy, but the result is an irregular sparse matrix that dense GPU and CPU kernels still process at full cost unless a sparse runtime skips the zeros. Structured pruning removes whole filters, channels, attention heads, or layers from a convolutional neural network or transformer, so each pruned layer becomes a smaller dense layer that runs faster on any hardware, at the cost of more accuracy loss per removed parameter. PyTorch's pruning utilities apply both kinds as masks on an existing layer:
import copy
from torch import nn
from torch.nn.utils import prune
# Two copies of one convolution layer with 32 filters of shape 16x3x3
unstructured = nn.Conv2d(16, 32, kernel_size=3)
structured = copy.deepcopy(unstructured)
# Unstructured: zero the 50% of individual weights with the smallest magnitude
prune.l1_unstructured(unstructured, name="weight", amount=0.5)
# Structured: zero the 50% of whole filters (dim=0) with the smallest L2 norm
prune.ln_structured(structured, name="weight", amount=0.5, n=2, dim=0)
for name, layer in [("Unstructured", unstructured), ("Structured", structured)]:
zeros = (layer.weight == 0).float().mean()
empty_filters = (layer.weight.flatten(1).abs().sum(dim=1) == 0).sum()
print(f"{name}: {zeros:.0%} of weights zeroed, {empty_filters}/32 filters entirely empty")Both layers lose 50% of their weights, but only the structured layer ends up with 16 of its 32 filters entirely empty, which can be physically removed to leave a dense 16-filter convolution.
Semi-structured pruning sits between the two. NVIDIA's 2:4 sparsity pattern zeroes two of every four consecutive weights, which Sparse Tensor Cores on Ampere and later GPUs skip to do the same matrix math in half the time; NVIDIA measured end-to-end gains of up to 20% for a sparse ResNeXt-101 in TensorRT on an A100. On dense hardware, scattered zeros alone buy no speed: pruning Ultralytics YOLOv5x to 30% global unstructured sparsity with its prune() utility, without fine-tuning, lowered COCO mAP50-95 from 0.507 to 0.489 and left V100 inference time unchanged at 5.2 ms per image.
Real-World Applications#
Pruning matters most where a model must run on constrained hardware. Channel-pruned object detection networks fit the memory and power budgets of drones, smart cameras, and phones, enabling real-time inference without a cloud connection and keeping imagery on the device for data privacy. In manufacturing inspection, the same compression lets a defect detector run on a low-cost edge module beside the production line.
Large language models are pruned too. SparseGPT prunes OPT-175B and BLOOM-176B to 60% unstructured sparsity in one shot, without retraining, with a negligible increase in perplexity. NVIDIA's Minitron work pruned Llama 3.1 8B to a 4B model by removing layers or hidden dimensions, then recovered quality with knowledge distillation from the original model.
Pruning vs. Related Techniques#
Pruning is often combined with other compression methods, and the term also has an older meaning outside neural networks.
- Model Quantization: Quantization keeps every weight and lowers its numeric precision, such as from 32-bit floats to 8-bit integers. Pruned models are often quantized afterward for further savings.
- Knowledge Distillation: Distillation trains a separate compact student to imitate a larger teacher, and it is a common way to recover the accuracy a heavily pruned model loses.
- Dropout Layer: Dropout zeroes random activations for a single training step as regularization and leaves the parameter count unchanged, while pruning removes parameters permanently.
- Decision Tree Pruning: In classical machine learning, pruning cuts branches from a fitted decision tree to reduce overfitting, as in scikit-learn's cost-complexity pruning, which removes the weakest subtrees as its
ccp_alphaparameter grows.










