Early Stopping and Pruning
Stop wasting compute on runs that can't win
Early stopping halts training when validation stops improving; pruning cuts entire search candidates that can't win. Together they turn tuning budgets from 'number of full runs' into 'total compute spent', which is what actually matters.
What you will learn
- Apply early stopping with a validation patience
- Compare pruning mid-run candidates vs finishing all
- Use Hyperband-style racing to spend budget on the best
What is this?
Early stopping watches validation during a single run and halts when improvement stalls for n epochs — preventing overfitting and saving compute. Pruning generalizes that idea across a whole search: candidates whose early performance can't plausibly beat the best so far are canceled early (racing), and multi-fidelity methods like Hyperband allocate budget in growing bands so promising runs get more and doomed ones get killed. Tuning then optimizes compute, not just trial count.
Why do you need it?
- Full training runs dominate tuning budgets; most never win.
- Validation curves stabilize early — the ranking of candidates barely changes mid-run.
- Early stopping is also a regularizer: halting before overfit gives better validation performance.
- Hyperband can solve tuning 5–10x faster for iterative learners (GBDT, NN).
Mental model
A hiring funnel that fast-tracks superstars and cuts stragglers
Pruning + early stopping
You don't give every candidate a full year on probation. Early promising work buys more runway; clear mismatches are cut in week one. The strongest finalist still gets the complete process — some runners just never go the full distance.
How it works
- Early stopping: monitor validation loss each epoch; if no improvement in P epochs (patience), roll back to the best checkpoint and stop.
- Restore-the-best is important — stopping at a low point is the point.
- Pruning: search candidates report scores at fixed milestones; a candidate ≥ a distance below the incumbent best is terminated.
- Hyperband: try R candidates with 1 unit of budget each, keep the top 1/η, double budget, repeat bands — batting averages dominate finishing.
- Report best config + the compute saved (a KPI for tuning efficiency).
A band of Hyperband: budget grows, candidates shrink.
In production
- An XGBoost trainer early-stops on `validation_evaluations` with early_stopping_rounds=50, restoring the best iteration.
- A torch training loop checks `best_val < val - eps` each epoch and saves the best weights, halting at patience.
- Optuna's MedianPruner + HyperbandSampler cut an 8-hour search to 90 minutes on a deep-learning job.
Best practices
- Always restore the best epoch/checkpoint, not the last weight vector.
- Use a validation split/curve that doesn't leak into the search's decisions (a racing budget is still model selection).
- Pick patience proportional to loss noise: noisier losses need bigger patience to avoid premature stops.
- Combine pruning with Bayesian sampling — the sampler learns which regions deserve the surviving budget.
Common mistakes
- Early stopping without restoring the best state — dropping to the tail of the curve.
- Pruning on noisy per-epoch metric where one lucky batch kills a good config.
- Using the tuned-validation data for early stopping AND for the final report — it gets reused, so it's a guide, not gospel.
- Hyperband with too-frequent pruning, so no candidate ever reaches full budget and all underfit.
Common issues
Early stopping halts but validation then improves after restorationPatience too short vs loss noise, or the halting rule saw a lucky low
Increase patience, smooth the monitored metric, and confirm the final eval uses restored weights.
Pruning prematurely kills the eventual best configPer-milestone scores noisy or too-aggressive threshold
Filter less aggressively (keep more candidates), use a lower percentile pruner, and evaluate more points before cutting.
Debugging tips
- Plot validation curves (metric vs epoch) — if the 'best epoch' is the last, patience was too short.
- When pruning kills everything, lower the pruning threshold or reduce frequency of checks.
- Log stopped-epoch + reason for every candidate; audits love that trace.
- Reproduce the best config with a full-unpruned run once to confirm the pruned winner wasn't budget-starved.
Interview checkpoint
Hands-on lab
- Simulate learning curves and implement early stopping from scratch
- Implement a median-pruner race over candidate hyperparameters
- Compare compute spent with and without pruning
Early Stop and Prune a Training Loop by Hand
30 min · intermediate
Quick quiz
After early stopping triggers, the deployed model should use:
Pruning spends compute only on candidates that could plausibly win.