Hyperparameter Sweeps
Search with a budget, measure with integrity
Sweeps are orchestrated hyperparameter search: grid, random, Bayesian or bandit. Done right they need budgets, early stopping and honest evaluation — done wrong they're just gaming the tracker.
What you will learn
- Choose a search strategy by compute budget and dimension count
- Configure early stopping to save compute safely
- Evaluate sweep results on a never-touched test set
What is this?
A hyperparameter sweep runs many training jobs over a configuration search space — grid, random or adaptive (Bayesian/bandit). Its purpose is to maximize a target metric within a compute budget, while keeping evaluation honest by selecting on validation, not the final test set.
Why do you need it?
- Hand-tuning burns time and takes exactly one path; sweeps explore the space systematically.
- Adaptive methods (Bayesian, bandit) explore where they can learn, saving compute.
- Early stopping cuts failed configurations early with little risk.
- Tracked sweeps produce comparable, auditable configuration → metric maps.
Mental model
Fishing with nets of different meshes
Search strategies
A grid is a fixed mesh (every point); random casts wide with cheap probes; Bayesian reads where the previous catches were and re-casts nearby. Each has a catch-per-effort — budget decides which to fish with.
How it works
- The space is declared (ranges or discrete for each hyperparameter).
- Sampler selects configurations: grid (all), random (fixed budget), Bayesian (model-informed).
- Each configuration trains on a budget slice with tracked params and metrics.
- Early stopping prunes unpromising runs (median stopping, patience).
- Results rank on a fixed validation set; the winner is evaluated once on the test set.
A sweep loop with early stopping and honest final eval.
Examples
A cheap random sweep with tracking
for trial in range(20): cfg = {"lr": 10 ** random.uniform(-4, -1), "layers": random.choice([2, 3, 4])} with mlflow.start_run(): mlflow.log_params(cfg) model, val = train_and_val(**cfg) mlflow.log_metric("val_loss", val)# then: choose min val_loss, evaluate ONCE on testRandom search over log-scaled lr and discrete layer counts, tracked per trial, with the final test evaluation reserved for the winner.
In production
- A transformer team budgets 200 GPU-hours; Bayesian search halved the configs needed.
- A tabular pipeline integrates a sweep stage that early-stops median-poor runs.
- A registry promotion records the sweep's config map as evidence for the champion's choice.
Best practices
- Set a compute budget before the sweep: trials × cost per trial.
- Prefer random over grid when some dimensions are low-value.
- Use early stopping where costs are high; keep it safe by a minimum training floor.
- Select on validation; touch the test set only once.
Common mistakes
- Selecting the winner on test — the test set stops being honest.
- Grid over a dimension that barely matters, exploding cost exponentially.
- Early stopping with too low a floor, killing eventual-winner configs.
- Forgetting to log seeds, so sweep results look noisy for the wrong reasons.
Debugging tips
- 'Sweep found great val but champ is bad' — check whether the win was on test vs val.
- Trials crash at random — same seed, different config? Look for config-induced edge cases.
- Sweep cost estimate blown — add per-trial budget accounting before launch.
Interview checkpoint
Hands-on lab
- Define a hyperparameter space and budget
- Run a tracked random sweep with early stopping
- Select a winner on validation and evaluate once
Run a Budgeted Random Sweep
30 min · intermediate
Quick quiz
Over many trials, early stopping saves compute mainly by:
Picking the best config from the test set is an acceptable selection strategy.