Population-based training: inherit a run, tune its recipe
群体训练
Follow three real momentum trajectories, clone a successful state, and compare equal-step training budgets.
population-based-trainingStart with the problem
Three models are training with different learning rates. Halfway through, one is doing well and another is going nowhere. Ordinary parallel search lets every run finish independently. Population-based training, or PBT, can replace a weak run with a copy of a better run, change a hyperparameter and continue from the inherited weights.
The “population” consists of ongoing training processes. It is not a bag of final models to average. Jaderberg and colleagues’ Algorithm 1 alternates ordinary parameter updates with exploitation and exploration. Exploitation chooses a useful existing state; exploration changes the training recipe. The original algorithm is asynchronous. Our small synchronous example pauses all workers at a common boundary so the state transfer can be inspected.
Definitions and derivation
Each worker minimizes the same scalar quadratic with momentum. Write v for a displacement buffer, w for its parameter, and η for the worker’s current rate:
This buffer includes the learning rate. It follows the convention explained in momentum. Training starts with w=v=0 and rates 0.05, 0.1 and 0.4. After three updates the parameters are 0.202625, 0.386 and 1.124. The last worker has the lowest loss even though it has passed the optimum at 1.
Rank by loss, with worker ID breaking ties. The weakest worker inherits the best worker’s declared training state. Then apply our deterministic exploration rule:
The donor’s rate 0.4 becomes 0.48 in the child. The copied state includes momentum v=0.284 and its training age. This is our explicit continuation policy, not a claim that every PBT implementation copies all optimizer state. The worker’s own identity and resource counter remain local. Deep copying prevents later child updates from modifying the donor.
With N workers, R rounds and K updates per worker per round, the individual gradient-evaluation count is:
The inherited age records the lineage, not work performed by the receiving machine. Copying it must not erase the child’s earlier compute from the budget. In this example copying and scoring are cheap; in large models checkpoint transfer, evaluation and waiting can be substantial additional costs.
Run the calculation
The complete Python 3.12 program uses exact rational arithmetic. It runs both a no-transfer control and a PBT variant, each with 18 gradient steps. Fitness is the known toy loss itself; this is an optimization demonstration, not a held-out generalization experiment.
from copy import deepcopy
from fractions import Fraction as F
def step(worker):
state = worker['state']
state['v'] = F(1, 2) * state['v'] + worker['rate'] * (1 - state['w'])
state['w'] += state['v']
state['age'] += 1
worker['cost'] += 1
def loss(worker):
return (worker['state']['w'] - 1) ** 2 / 2
def exploit(child, donor, factor=F(6, 5)):
if not 0 < factor <= 2 or child is donor:
raise ValueError('Choose a different donor and a factor in (0, 2].')
child['state'] = deepcopy(donor['state'])
child['rate'] = min(F(1, 2), donor['rate'] * factor)
def train(use_pbt=True):
workers = [dict(id=i, rate=r, cost=0, state=dict(w=F(0), v=F(0), age=0))
for i, r in enumerate((F(1, 20), F(1, 10), F(2, 5)))]
for worker in workers:
for _ in range(3):
step(worker)
first = deepcopy(workers)
if use_pbt:
best = min(workers, key=lambda w: (loss(w), w['id']))
worst = max(workers, key=lambda w: (loss(w), -w['id']))
exploit(worst, best)
inherited = deepcopy(workers)
for worker in workers:
for _ in range(3):
step(worker)
return first, inherited, workers
if __name__ == '__main__':
first, inherited, final = train()
for worker in first:
print('before', worker['id'], 'w', float(worker['state']['w']))
print('copied velocity', float(inherited[0]['state']['v']), 'new rate', float(inherited[0]['rate']))
for mode in (False, True):
end = train(mode)[2]
best = min(end, key=loss)
print('pbt', mode, 'steps', sum(w['cost'] for w in end),
'best w', float(best['state']['w']), 'loss', round(float(loss(best)), 12))
Actual output:
before 0 w 0.202625
before 1 w 0.386
before 2 w 1.124
copied velocity 0.284 new rate 0.48
pbt False steps 18 best w 1.085444 loss 0.003650338568
pbt True steps 18 best w 1.048341792 loss 0.001168464427
The mutated child ends at 1.048341792, compared with 1.085444 for the unmodified fast worker. PBT wins this constructed comparison. Resetting the copied momentum would give a different trajectory even with identical inherited weights and rate. For a model with d parameters and optimizer buffers, state transfer typically scales with the saved state size, and N concurrent workers multiply model-state storage. PBT does not make the population’s compute free.
When the method fails
Copying an early leader can discard a slower run that would eventually be better. Repeatedly choosing the same lineage reduces diversity. Frequent perturbation can interrupt useful training; infrequent perturbation wastes poor configurations. Validation noise can spread a lucky checkpoint through the population.
A real restore contract must specify model buffers, optimizer state, data position, random generators and how learning-rate changes are applied after restoring. Copying only weights is a valid alternative policy, but it is not exact optimizer continuation. Ray’s fixed PBT interface exposes perturbation intervals, quantile selection, mutation factors and a synchronous option. Those controls do not decide what your trainable saves. Evaluate the selected lineage on untouched data after search, and record the whole hyperparameter schedule rather than just its final rate.
Exercises with answers
- What is the inherited momentum before the child’s fourth step?
Answer 1: 0.284, or 71/250. It is copied from the best worker after three updates.
- Does replacing a weak worker erase its first three gradient calls?
Answer 2: No. Its local cost stays three and becomes six after the next round.
- Why use a deep copy rather than assigning the donor state object?
Answer 3: A shared mutable dictionary would let child updates change the donor and destroy worker independence.
- Does the lower final toy loss prove PBT improves generalization?
Answer 4: No. The evaluation is the training objective, and the example uses one prescribed mutation. Generalization and robustness require separate data and repeated comparisons.
Sources and next steps
The paper’s Section 3 and Algorithm 1 establish the two-timescale train/exploit/explore loop. Ray 2.49.0 illustrates operational controls; it was consulted, not executed here. The exact quadratic trajectories and copy-policy tests are original. Compare Bayesian optimization: it usually proposes configurations for objective evaluations, whereas PBT changes the recipe inside continuing training runs.
Make a prediction, then check
What must remain in the compute budget after copying a donor?
Learning objectives
- Distinguish state inheritance from independent parallel search.
- Audit checkpoint-copy policies and population resource counts.
Prerequisites & connections
Explore related knowledge →References
- Population Based Training of Neural Networks — arXiv v1
Max Jaderberg et al. · 2017 - PopulationBasedTraining — Ray 2.49.0
Ray contributors
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. NumPy 1.26.4 is used in six programs; PBT and curriculum use standard-library exact fractions. 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.
- Desktop review found an awkward Chinese title break inside a word. Shortened the bilingual heading without changing the explanation, equations or program; frozen drafts retained and final hashes rebound.
Source locations checked:
- Population Based Training of Neural Networks — arXiv v1 · Physical pages 4–5, Section 3 and Algorithm 1: asynchronous optimization, exploit and explore.
- PopulationBasedTraining — Ray 2.49.0 · PopulationBasedTraining class documentation: state cloning, quantile_fraction, perturbation_factors, time_attr and synch.
Related topics