Model Pruning
Model pruning is a compression technique that removes weights, neurons, or entire structural components from a trained neural network while attempting to preserve as much of its predictive accuracy as possible. In weight pruning, individual parameters below a magnitude threshold are zeroed out or deleted; in structured pruning, entire attention heads, filters, or layers are removed, yielding models whose architecture is inherently smaller and more hardware-friendly. Pruning is typically followed by a fine-tuning pass to recover accuracy lost during the removal step, and the resulting model is faster and cheaper to run during inference.
Think of it like editing a dense first draft: you cut every sentence that contributes little without changing the meaning, and the resulting text is leaner and faster to read without losing the core argument.
A simple unstructured magnitude-pruning pass in PyTorch removes the lowest-magnitude weights globally across a model:
import torch.nn.utils.prune as prune
# Remove 30% of weights globally by smallest absolute value
parameters_to_prune = [
(module, "weight") for module in model.modules()
if isinstance(module, torch.nn.Linear)
]
prune.global_unstructured(
parameters_to_prune,
pruning_method=prune.L1Unstructured,
amount=0.30,
)
Structured pruning of Transformer attention heads has been shown to remove up to 40% of heads in BERT-scale models with under 1% accuracy drop on downstream tasks.
Model pruning is closely related to Quantization (another size-reduction technique, often applied after pruning), Knowledge Distillation (a complementary approach to producing smaller models), Neural Network architecture, and Hyperparameter tuning (the pruning ratio and fine-tuning learning rate require careful selection).
You will encounter model pruning when deploying language or vision models on edge devices, in mobile applications with strict latency budgets, and in research papers comparing compression pipelines for efficient on-device inference.