One-Shot Pruning

Beginner Explanation

Imagine you have a garden full of plants, and you want to make it more beautiful by removing some plants. Instead of going through the garden multiple times to decide which plants to pull out, you take a quick look and remove all the plants that don’t look good in one go. This is like one-shot pruning in machine learning, where we quickly remove unnecessary parts of a neural network in just one step, rather than repeatedly checking and adjusting it over time. It helps make the model simpler and faster while keeping the important parts that help it learn.

Technical Explanation

One-shot pruning is a technique used to reduce the size of neural networks by eliminating weights in a single pass. Unlike traditional pruning methods that require multiple training iterations, one-shot pruning identifies and removes less important weights based on a predefined criterion, such as weight magnitude. This can be implemented in PyTorch as follows: “`python import torch import torch.nn.utils.prune as prune # Define a simple model model = torch.nn.Sequential( torch.nn.Linear(10, 5), torch.nn.ReLU(), torch.nn.Linear(5, 1) ) # Apply one-shot pruning prune.l1_unstructured(model[0], name=’weight’, amount=0.2) # Prune 20% of weights # Verify the pruning print(model[0]) “` This method reduces the model size and can improve inference speed while maintaining performance, especially in resource-constrained environments.

Academic Context

One-shot pruning is a relatively recent advancement in the field of neural network compression, aiming to optimize models for deployment without extensive retraining. The foundational concept is based on the observation that many weights in neural networks are redundant. Key papers include ‘Pruning Convolutional Neural Networks with Optimal Brain Damage’ (LeCun et al., 1990) and ‘The Lottery Ticket Hypothesis’ (Frankle & Carbin, 2019), which explore weight significance and optimal pruning strategies. Mathematically, one-shot pruning can be described through the optimization of a loss function, where the goal is to minimize the model’s capacity while maintaining accuracy, often using L1-norm regularization to identify less significant weights to prune.

Code Examples

Example 1:

import torch
import torch.nn.utils.prune as prune

# Define a simple model
model = torch.nn.Sequential(
    torch.nn.Linear(10, 5),
    torch.nn.ReLU(),
    torch.nn.Linear(5, 1)
)

# Apply one-shot pruning
prune.l1_unstructured(model[0], name='weight', amount=0.2)  # Prune 20% of weights

# Verify the pruning
print(model[0])

Example 2:

torch.nn.Linear(10, 5),
    torch.nn.ReLU(),
    torch.nn.Linear(5, 1)

Example 3:

import torch
import torch.nn.utils.prune as prune

# Define a simple model
model = torch.nn.Sequential(

Example 4:

import torch.nn.utils.prune as prune

# Define a simple model
model = torch.nn.Sequential(
    torch.nn.Linear(10, 5),

View Source: https://arxiv.org/abs/2511.16653v1