Lottery ticket hypothesis: keep the mask, reset the weights
彩票假说
Run a small pruning-and-reset experiment, separate initialization controls and account for the cost of finding a mask.
lottery-ticketStart with the problem
A trained large network can sometimes be pruned into a useful smaller one. The lottery ticket hypothesis asks a more specific question: can a sparse subnetwork, reset to its original initialization, train in isolation and match the original network within a comparable training budget?
Frankle and Carbin, physical page 2, define a winning ticket through both its connectivity mask and its initial parameter values. Keeping trained weights and fine-tuning them is a different experiment. A successful tiny demonstration would not prove the hypothesis for every architecture, sparsity or optimizer; the controls are part of the question.
Definitions and derivation
The one-shot discovery procedure first trains a dense model, identifies entries to prune from trained magnitudes, and resets surviving entries:
The mask is selected from θT, but retraining starts from θ₀. Confusing those two arrays silently changes reset training into fine-tuning. The original paper also studies iterative pruning, repeatedly training, pruning surviving weights and resetting; our implementation performs one pruning round.
A fixed mask can be enforced after every gradient update:
Start with zeros in masked entries and project them back to zero every step. Otherwise optimizer updates can regrow connections that were supposedly removed. Optimizers with momentum would also need a policy for their state; this example uses ordinary gradient descent with no persistent optimizer buffers.
The network has four scalar tanh hidden units: four input weights, four output weights, four hidden biases and one output bias. We prune only the eight weight entries, retaining the four largest absolute trained values, with index order breaking ties. Biases remain unmasked:
Thus “50% of weights removed” is not “50% of all parameter entries removed.” Some unmasked biases can belong to disconnected units and have no effect on the prediction. A Boolean mask changes the function but does not automatically give a fast sparse implementation. Our array operations remain dense.
Run the calculation
The complete Python 3.12 / NumPy 1.26.4 program fits x² on 16 training inputs. After dense discovery, it compares the original-initialization mask, the same mask with a fresh initialization, and a random weight mask of the same size. Seeds and budgets are explicit.
import numpy as np
def initial(seed=7):
return np.random.default_rng(seed).normal(0, 0.5, 13)
def forward(theta, x):
hidden = np.tanh(x[:, None] * theta[4:8] + theta[8:12])
return hidden @ theta[:4] / 2 + theta[12], hidden
def train(theta0, mask, steps=4000):
theta0, mask = np.asarray(theta0, dtype=float), np.asarray(mask)
if theta0.shape != (13,) or mask.shape != (13,) or mask.dtype != bool or not np.isfinite(theta0).all() or type(steps) is not int or not 0 <= steps <= 6000:
raise ValueError('Use 13 finite parameters, a Boolean mask and 0 to 6000 steps.')
x = np.linspace(-1, 1, 16); y = x ** 2
theta = theta0.copy() * mask
for _ in range(steps):
prediction, hidden = forward(theta, x)
residual = (prediction - y) / len(x)
hidden_grad = residual[:, None] * theta[:4] * (1 - hidden ** 2) / 2
grad = np.r_[hidden.T @ residual / 2, (hidden_grad * x[:, None]).sum(axis=0),
hidden_grad.sum(axis=0), residual.sum()]
theta = (theta - 0.1 * grad) * mask
return theta
def magnitude_mask(trained, keep=4):
trained = np.asarray(trained, dtype=float)
if trained.shape != (13,) or not np.isfinite(trained).all() or type(keep) is not int or not 0 <= keep <= 8:
raise ValueError('Keep an integer number of the eight weight entries.')
order = sorted(range(8), key=lambda i: (-abs(trained[i]), i))
mask = np.ones(13, dtype=bool); mask[:8] = False; mask[order[:keep]] = True
return mask
def diagnostic_mse(theta):
# This synthetic grid was inspected while developing the teaching example; it is not an untouched test set.
x = np.linspace(-0.97, 0.97, 31)
return float(np.mean((forward(theta, x)[0] - x ** 2) ** 2))
def experiment():
theta0 = initial(); dense = train(theta0, np.ones(13, dtype=bool))
mask = magnitude_mask(dense)
rng = np.random.default_rng(11); random_mask = np.ones(13, dtype=bool)
random_mask[:8] = False; random_mask[rng.choice(8, 4, replace=False)] = True
variants = {'dense': dense, 'reset ticket': train(theta0, mask),
'fresh initialization': train(initial(13), mask), 'random mask': train(theta0, random_mask)}
return theta0, dense, mask, variants
if __name__ == '__main__':
theta0, dense, mask, variants = experiment()
print('retained weight indices', np.flatnonzero(mask[:8]).tolist(), 'unmasked parameters including biases', int(mask.sum()))
for name, theta in variants.items():
print(name, 'diagnostic grid MSE', round(diagnostic_mse(theta), 9))
print('reset differs from fine-tuning start', round(float(np.linalg.norm(theta0 * mask - dense * mask)), 9))
print('updates: discovery 4000; each compared training run 4000; discovery is additional search cost')
Actual output:
retained weight indices [0, 3, 4, 7] unmasked parameters including biases 9
dense diagnostic grid MSE 0.003236354
reset ticket diagnostic grid MSE 0.001171416
fresh initialization diagnostic grid MSE 0.002254996
random mask diagnostic grid MSE 0.091124316
reset differs from fine-tuning start 3.195355338
updates: discovery 4000; each compared training run 4000; discovery is additional search cost
The reset-mask run has the lowest error on this diagnostic grid, but the fresh-initialization run also beats the dense run. A random mask produces a much weaker result. These are one-run observations, not evidence that original initialization is always necessary.
The 31-point synthetic grid was inspected while developing the example and choosing a sufficient training duration; it is deliberately labeled diagnostic, not an untouched test set. An initial 600-step run underfit the curve; the final example uses 4000 updates for each comparison. No independent generalization claim is made. A research experiment would predeclare selection criteria, retain untouched evaluation data and repeat initializations.
Sorting d eligible magnitudes costs O(d log d); a selection algorithm can reduce that overhead. Dense training to discover the mask is additional work. Comparing only the sparse retraining phase with a dense baseline would hide that search cost.
When the method fails
Magnitude depends on parameter scaling and may not measure a connection’s functional importance. Unstructured sparsity, whole-channel pruning and removing layers create different architectures and hardware opportunities. A lower count of nonzeros is not a latency measurement.
Liu and colleagues emphasize strong from-scratch baselines in their pruning study, particularly for the structured methods examined. That work and the lottery-ticket experiments differ in settings and evaluation details; they should not be reduced to “initialization always matters” versus “never matters.” Match training budgets, sparsity definitions, resets, learning rates and final evaluation criteria before comparing claims. This chapter does not discover an unseen mask for a real image classifier.
Exercises with answers
- Which array chooses the mask and which initializes retraining?
Answer 1: Trained θT chooses the magnitude mask; original θ₀ initializes the reset run.
- How many parameter entries remain unmasked here?
Answer 2: Nine: four weight entries and five bias entries. This is not a claim that all nine affect the output.
- What distinguishes a fresh-initialization control from a random-mask control?
Answer 3: The first keeps connectivity and changes values; the second changes connectivity while retaining the declared original initialization for surviving entries.
- Why not call the diagnostic-grid result a winning-ticket proof?
Answer 4: The grid influenced example development, there is one run per condition, and no independent evaluation meeting the original hypothesis criteria was performed.
Sources and next steps
Frankle and Carbin’s physical page 2 supplies the hypothesis and train–prune–reset distinction. The abstract of Liu and colleagues supplies the scoped from-scratch-baseline challenge. The four-unit network and mask tests are original. Compare loss landscapes for parameter scaling and neural architecture search for selecting structures explicitly.
Make a prediction, then check
What is reset in the original train–prune–reset procedure?
Learning objectives
- Implement masked reset training without accidentally fine-tuning.
- Separate mask discovery cost, initialization controls and evaluation evidence.
Prerequisites & connections
Explore related knowledge →References
- The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks — arXiv v5
Jonathan Frankle; Michael Carbin · 2019 - Rethinking the Value of Network Pruning — arXiv v2
Zhuang Liu; Mingjie Sun; Tinghui Zhou; Gao Huang; Trevor Darrell · 2019
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-06 · Codex single-AI-author technical check: primary-source scope, explicit assumptions, original calculations, independent mathematical references and bilingual tests; not independent human or second-agent review.
- Single-AI-author technical check: bounded primary-source reading, explicit assumptions, original calculations, runnable examples and matching bilingual equations, code and exercises. Not an independent human or second-agent review.
- Four focused CPython 3.12.4 tests passed per chapter, including independent derivatives, integrals, normal equations or exact/literal trajectory references as appropriate. All eight programs use NumPy 1.26.4. Tests include augmentation geometry, exact quadratic certificates, finite differences, spectral solutions, conditional risk decompositions and masked neural-network training. CPU teaching calculations, not framework or GPU benchmarks.
- Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
Source locations checked:
- The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks — arXiv v5 · Physical page 2: hypothesis, mask plus original initialization, one-shot train–prune–reset steps and distinction from iterative pruning.
- Rethinking the Value of Network Pruning — arXiv v2 · Physical page 1 abstract: from-scratch controls, structured-pruning experiment scope and comparison with lottery-ticket initialization.
Related topics