Pruning
Pruning is a model compression technique that identifies and removes parameters - or entire structural units - from a trained Neural Network that contribute little to its outputs, reducing model size and accelerating Inference with minimal degradation in accuracy. Unstructured pruning zeroes out individual weights below a magnitude threshold, producing sparse matrices; structured pruning removes whole neurons, attention heads, or convolutional filters, yielding dense smaller models that map more efficiently to standard hardware without requiring sparse-computation support. Both approaches typically involve a prune-fine-tune cycle: weights are removed and the model is briefly retrained to recover any lost accuracy.
Think of it like editing a first draft of a very long document - you identify sentences and paragraphs that add no information and cut them, ending up with a shorter, crisper piece that says roughly the same thing as the original but in far fewer words.
A simple magnitude-based unstructured pruning example with PyTorch:
import torch.nn.utils.prune as prune
# prune 30 % of weights in a linear layer by lowest magnitude
prune.l1_unstructured(model.fc1, name="weight", amount=0.30)
# make pruning permanent (remove mask, zero weights are gone)
prune.remove(model.fc1, "weight")
print(f"Sparsity in fc1: {(model.fc1.weight == 0).float().mean():.1%}")
Pruning is closely related to Quantization - both reduce the footprint of a trained model and are often applied together - and to Knowledge Distillation, which compresses via training a smaller student model rather than trimming the original. The Loss Function and Overfitting dynamics during the post-prune fine-tune phase must also be managed carefully.
You will encounter pruning whenever a team needs to deploy a large model under memory or latency constraints: on-device inference, browser-side models, or real-time applications where a full-size LLM would be too slow or expensive to run, making pruning a practical step in any production model-compression pipeline.