AI Logic

Model Compression

Lottery Ticket Hypothesis

Updated:

How the Lottery Ticket Hypothesis works. The left side shows the flow of obtaining a winning ticket by randomly initializing, training, pruning the weights with small magnitudes, and resetting the remaining weights to their initial values θ₀, repeated n times. The right side compares, with the same mask, the network reset to the original initial values (the winning ticket) and the one with redrawn initial values, showing that the winning ticket trains faster and reaches higher accuracy

Background and Overview

The Lottery Ticket Hypothesis, presented by Frankle and Carbin (2019), states that a large network contains, from the very start, a small "winning" network.

It was already known that pruning can remove more than 90% of the parameters of a trained network while preserving accuracy. If so, training that small network from the start should also make training cheaper. However, when the structure obtained by pruning was randomly reinitialized and trained from scratch, it usually failed to reach the original accuracy.

Frankle and Carbin explained this discrepancy through initialization. When the weights remaining after pruning were reset not to their trained values but to their original initial values from before training began and then trained, even the small network reached the same or higher accuracy in the same or fewer iterations. Reinitializing the weights with new random values destroyed this property.

The name comes from the lottery. Randomly initializing a large network is like buying many lottery tickets at once. Among them is a combination of initial values and structure that happens to be well suited to training (a winning ticket), and training can be seen as digging it out.

The Lottery Ticket Hypothesis drew attention less as a practical way to shrink models and more as a clue to why large networks are easier to train.

Theory (Definition of the Hypothesis and How to Find Winning Tickets)

The paper states the hypothesis as follows.

A randomly-initialized, dense neural network contains a subnetwork that is initialized such that, when trained in isolation, it can match the test accuracy of the original network after training for at most the same number of iterations.

In formulas, it reads as follows. Suppose a network f(x;θ)f(x; \theta) with initial parameters θ0\theta_0 (drawn randomly from a distribution Dθ\mathcal{D}_\theta) is trained with stochastic gradient descent, reaching minimum validation loss at iteration jj with test accuracy aa. Suppose f(x;m⊙θ)f(x; m \odot \theta), masked with a binary mask m∈{0,1}∣θ∣m \in \{0, 1\}^{|\theta|}, is trained from initialization m⊙θ0m \odot \theta_0 (with mm fixed), reaching minimum loss at iteration j′j' with accuracy a′a'. The Lottery Ticket Hypothesis predicts that there exists an mm satisfying the following.

j′≤j (same or fewer training iterations),a′≥a (same or higher accuracy),∥m∥0≪∣θ∣ (far fewer parameters)j' \le j \ (\text{same or fewer training iterations}), \qquad a' \ge a \ (\text{same or higher accuracy}), \qquad \|m\|_0 \ll |\theta| \ (\text{far fewer parameters})

A winning ticket f(x;m⊙θ0)f(x; m \odot \theta_0) is found with the following steps (Chapter 1).

  1. Randomly initialize the network f(x;θ0)f(x; \theta_0) (θ0∼Dθ\theta_0 \sim \mathcal{D}_\theta).
  2. Train it for jj iterations to obtain parameters θj\theta_j.
  3. Prune the p%p\% of θj\theta_j with the smallest magnitudes, creating a mask mm.
  4. Reset the remaining weights to their original initial values θ0\theta_0. This is the winning ticket f(x;m⊙θ0)f(x; m \odot \theta_0).

Besides removing p%p\% in one step (one-shot), there is a method that repeats training, pruning, and resetting to the initial values nn times, each time removing p1/n%p^{1/n}\% of the weights that survived the previous round (iterative). In the paper, the iterative method found smaller winning tickets.

The fraction of remaining weights is denoted Pm=∥m∥0/∣θ∣P_m = \|m\|_0 / |\theta|. For example, pruning 75% of the weights gives Pm=25%P_m = 25\%.

The only difference from ordinary pruning is step 4. Ordinary pruning continues training from the trained values θj\theta_j after pruning (fine-tuning). In the Lottery Ticket Hypothesis experiments, the trained values are discarded and training restarts from the initial values θ0\theta_0.

Why the Initialization Matters

The paper compared winning tickets with f(x;m⊙θ0′)f(x; m \odot \theta'_0), which keeps the structure of the winning ticket (which weights remain) but redraws only the initial values from the distribution (right side of the figure at the top).

  • Reinitializing slows training and lowers accuracy. On LeNet (a fully connected network on MNIST), winning tickets trained faster the more they were pruned, while reinitialized networks trained more slowly the more they were pruned. With 21% of the weights remaining, the winning ticket reached minimum validation loss 2.51 times sooner than the reinitialized network, and its accuracy was 0.5 points higher.
  • Structure alone cannot explain it. The accuracy of the reinitialized network fell below the original accuracy once 21.1% of the weights remained, whereas the winning ticket kept the original accuracy down to 2.9%. The effect of a winning ticket comes from the combination of structure and initialization.

So why are the initial values of a winning ticket well suited to training? Against the idea that "the initial values of a winning ticket may already be close to their trained values," the experiment in Appendix F of the paper showed the opposite: the weights of winning tickets moved more than the other weights. The paper states that the advantage of the initialization is tied to the optimization algorithm, the data, and the model, and that the initial values of a winning ticket may lie in a region of the loss landscape (optimization landscape) that is easy to train for the chosen optimizer.

As a further conjecture (not yet verified), the paper also states that "stochastic gradient descent seeks out and trains a subset of well-initialized weights." This explains why large networks are easier to train: they contain more candidate subnetworks that could become winning tickets.

Winning tickets also showed better generalization. As weights were removed, test accuracy first rose and then fell when too much was pruned. Since training accuracy was nearly 100% in every case, winning tickets had a smaller gap between training and test accuracy, meaning they were less prone to overfitting.

Experimental Results

These are the main results of the paper. In every case, the winning ticket was found by iterative pruning and trained from the initial values θ0\theta_0.

Network (data)Main results
LeNet-300-100 (MNIST)With 21% of the weights remaining, minimum validation loss was reached 38% sooner than the original. With 13.5% remaining, test accuracy rose by more than 0.3 points, returning to the original level at 3.6% remaining
Conv-2 (CIFAR-10)Up to 3.5x faster training (8.8% remaining), up to 3.4 points higher test accuracy (4.6% remaining)
Conv-4 (CIFAR-10)Up to 3.5x faster training (9.2% remaining), up to 3.5 points higher test accuracy (11.1% remaining)
Conv-6 (CIFAR-10)Up to 2.5x faster training (15.1% remaining), up to 3.3 points higher test accuracy (26.4% remaining)

Conv-2, 4, and 6 are scaled-down convolutional networks based on VGG. In all of them, the winning tickets exceeded the original average test accuracy as long as more than 2% of the weights remained.

For deeper networks (VGG-19 and ResNet-18 on CIFAR-10), the following was found (Chapter 4).

  • With a high learning rate, no winning tickets were found. At the learning rate of 0.1 used in the original papers, subnetworks found by iterative pruning were no better than reinitialized ones.
  • With warmup, they were found. By gradually raising the learning rate from 0, winning tickets were found for VGG-19 as long as 1.5% or more of the weights remained, and for ResNet-18 (learning rate 0.03) as long as 11.8% or more remained.
  • Pruning was done by comparing across the whole network rather than per layer. In deep networks, the number of weights varies greatly between layers (the first two layers of VGG-19 have 1,728 and 36,864 weights, while the last layer has 2.35 million), so pruning the same fraction from each layer would choke the small layers first.

Winning tickets were also found when combined with Dropout, and accuracy improved further (Conv-2, 4, 6). Since Dropout can be seen as training a random subnetwork at each step, it is thought to work well with the Lottery Ticket Hypothesis.

Practical Considerations

  • Finding winning tickets is expensive. Iterative pruning can require retraining the network 15 or more times in a row. Because of the computational cost, the paper did not examine large datasets such as ImageNet. It cannot be used as-is to make training cheaper.
  • The verified scope is limited. The paper's experiments cover only image classification on MNIST and CIFAR-10, with fully connected and convolutional networks.
  • The winning tickets found are sparse networks. Since they are found by unstructured pruning, which removes individual weights, the parameter count goes down, but they do not run faster on ordinary hardware and libraries.
  • They are sensitive to hyperparameters such as the learning rate. In deep networks, no winning tickets were found with a high learning rate without warmup.

The Lottery Ticket Hypothesis claims that "resetting to the original initial values is essential," but this applies when a large fraction is pruned. Liu et al. (2019) report that a VGG-19 pruned up to 80% reaches the original accuracy even when reinitialized and trained from scratch, and Frankle and Carbin confirmed the same result in this range. The initialization starts to matter when even more is pruned (up to 98.5% for VGG-19).

Comparison with Other Methods

The following table compares methods by which values the remaining weights are retrained from after pruning.

MethodStarting values for retrainingHow the structure is chosenPurpose
Ordinary pruning (Han et al. 2015)Trained values θj\theta_j (fine-tuning)Weight magnitudeShrink a trained model
Lottery Ticket Hypothesis (Frankle and Carbin 2019)Original initial values θ0\theta_0Weight magnitude (iterative)Investigate whether a small trainable network exists from the start
Reinitialization (the paper's control)New initial values θ0′\theta'_0Same mask as the winning ticketIsolate the effect of the initialization

As methods for shrinking models, they are used as follows.

  • To shrink a trained model, ordinary pruning followed by retraining is enough. Finding winning tickets requires retraining many times and is not worth the cost.
  • To speed up inference, use structured pruning such as filter pruning or Network Slimming. Winning tickets are sparse, so they are not faster as-is.
  • The Lottery Ticket Hypothesis is best read as a clue for thinking about weight initialization, methods that prune early in training, and network design.

PyTorch example

Show code
python
import copy

import torch
import torch.nn as nn


def make_lenet():
    # LeNet-300-100 from the paper (a fully connected network for MNIST)
    return nn.Sequential(nn.Flatten(), nn.Linear(784, 300), nn.ReLU(),
                         nn.Linear(300, 100), nn.ReLU(), nn.Linear(100, 10))


def prunable(model):
    return {n: p for n, p in model.named_parameters() if n.endswith("weight")}


def train(model, masks, loader, steps, lr=1.2e-3):
    """Train with the mask fixed. Pruned weights are reset to 0 every step"""
    opt = torch.optim.Adam(model.parameters(), lr=lr)
    model.train()
    for step, (x, y) in enumerate(loader):
        if step >= steps:
            break
        loss = nn.functional.cross_entropy(model(x), y)
        opt.zero_grad()
        loss.backward()
        opt.step()
        with torch.no_grad():
            for n, p in prunable(model).items():
                p.mul_(masks[n])


@torch.no_grad()
def prune_by_magnitude(model, masks, rate):
    """In each layer, prune the fraction rate of the remaining weights with the smallest magnitudes (layer-wise pruning)"""
    new = {}
    for n, p in prunable(model).items():
        alive = p[masks[n].bool()].abs()
        k = int(rate * alive.numel())
        th = alive.kthvalue(k).values if k > 0 else alive.min() - 1
        new[n] = masks[n] * (p.abs() > th).float()
    return new


def find_winning_ticket(loader, rounds=5, rate=0.2, steps=1000):
    model = make_lenet()
    theta0 = copy.deepcopy(model.state_dict())                     # 1. save the initial values θ0
    masks = {n: torch.ones_like(p) for n, p in prunable(model).items()}
    for _ in range(rounds):
        train(model, masks, loader, steps)                          # 2. train j iterations to get θj
        masks = prune_by_magnitude(model, masks, rate)              # 3. prune small |w| to get m
        model.load_state_dict(theta0)                               # 4. reset the rest to θ0
        with torch.no_grad():
            for n, p in prunable(model).items():
                p.mul_(masks[n])
    return model, masks                                              # winning ticket f(x; m ⊙ θ0)


def reinit_control(masks):
    """Control: same mask, only the initial values are redrawn f(x; m ⊙ θ'0)"""
    model = make_lenet()
    with torch.no_grad():
        for n, p in prunable(model).items():
            p.mul_(masks[n])
    return model


# small data for a quick check (use MNIST in practice)
data = [(torch.randn(60, 1, 28, 28), torch.randint(0, 10, (60,))) for _ in range(5)]
ticket, masks = find_winning_ticket(data, rounds=2, rate=0.2, steps=5)
remain = sum(m.sum() for m in masks.values()) / sum(m.numel() for m in masks.values())
print(f"Fraction of remaining weights P_m = {remain:.3f}")  # 20% pruned per round, so around 0.8 × 0.8 = 0.64

FAQ

Q. Does the Lottery Ticket Hypothesis make training cheaper?
A.

Not as-is, for now. Finding a winning ticket requires repeatedly training and pruning a large network, which is far more expensive than training the original network once. The paper also lists finding winning tickets early as future work. The value of the Lottery Ticket Hypothesis lies in showing that small yet trainable networks exist.

Q. Are the initial values of a winning ticket close to its trained values?
A.

No. In the experiment in Appendix F of the paper, the weights of winning tickets moved more during training than the other weights. The paper suggests that it is not that the initial values themselves are close to the answer, but that, in combination with the optimizer, data, and model, they start from a place that is easy to train from.

Q. Can winning tickets be found in large models or on ImageNet?
A.

The original paper did not examine large datasets such as ImageNet because of the computational cost. Even for deep networks such as VGG-19 and ResNet-18 on CIFAR-10, no winning tickets were found with a high learning rate; they were found when warmup was used. How far the hypothesis holds in larger settings was not verified within the scope of this paper.

References

  1. J. Frankle and M. Carbin, "The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks," ICLR, 2019. arXiv:1803.03635.
  2. D. Blalock, J. J. Gonzalez Ortiz, J. Frankle, and J. Guttag, "What is the State of Neural Network Pruning?," Proceedings of MLSys, 2020. arXiv:2003.03033.
  3. S. Han, J. Pool, J. Tran, and W. J. Dally, "Learning both Weights and Connections for Efficient Neural Networks," arXiv:1506.02626, 2015.