Hyperparameter Tuning: Random Search, Bayesian Optimization, and Hyperband
Hyperparameters—learning rates, regularization strengths, tree depths, context chunk sizes, and optimizer momenta—govern how a learning algorithm behaves rather than being updated directly by gradient descent. Because evaluating a single hyperparameter configuration requires training and validating an entire model, naive Cartesian grid sweeps explode exponentially with dimension; principled search combines logarithmic Random Search, sequential Bayesian Optimization, and multi-fidelity early-termination schedulers like ASHA.
Key Highlights
- James Bergstra and Yoshua Bengio proved why Random Search beats Grid Search: in a 3×3 grid over one crucial hyperparameter (learning rate) and one unimportant parameter, all 9 runs test only 3 distinct learning rates—whereas 9 random draws test 9 distinct learning rates.
- Bayesian Optimization builds a probabilistic surrogate (Gaussian Process or Tree-structured Parzen Estimator, TPE, in Optuna) and selects next trials via Expected Improvement.
- Asynchronous Successive Halving (ASHA) and Hyperband launch wide configurations on small budgets and terminate bottom-performing runs early, cutting GPU search cost 5×–15×.
- Maximal Update Parameterization (μP) enables frontier LLM labs to tune learning rates and initializations on cheap 100M-parameter proxy models and transfer optimal hyperparameters directly to 70B+ runs.
Comparing Grid, Random, Bayesian Surrogates, and ASHA Pruning
Different hyperparameters span radically different mathematical scales: learning rates (10⁻⁵ to 10⁻²) and weight decay must be sampled on a logarithmic scale so `[0.0001, 0.001]` receives equal exploration density to `[0.001, 0.01]`, whereas dropout ratios (`0.0` to `0.4`) sample uniformly.
Bayesian Optimization refines search iteratively: Gaussian Process surrogates excel on continuous low-dimensional spaces (<15 parameters) with expensive trials, while Optuna’s Tree-structured Parzen Estimator (TPE) handles conditional, discrete, and hierarchical parameters naturally (for example, tuning `num_leaves` only when `booster == "lightgbm"`). Pairing TPE with ASHA monitors intermediate validation curves at epochs 1, 2, 4, and 8—halting diverging runs immediately to free GPUs.
| HPO Strategy | Parallelism | Sample Efficiency | Ideal Engineering Scenario |
|---|---|---|---|
| Cartesian Grid Search | Trivial | Poor (exponential curse of dimensionality) | Only 1 or 2 discrete parameters (<12 total runs) |
| Log-Scale Random Search | 100% Embarrassingly parallel | Strong unbiased baseline | First 20–30 exploration runs across parallel workers |
| Bayesian TPE / GP (Optuna / Ax) | Sequential or batched async | High (exploits promising basins) | Tabular GBDTs (50–200 trials) & expensive RAG pipelines |
| Bayesian + ASHA Early Pruning | High async GPU cluster utilization | Highest wall-clock efficiency | Deep neural network training where bad runs show early |
| μP Proxy Transfer | Tune small, train giant once | Mandatory when 1 trial costs $500k+ | Pretraining 7B–400B foundation models |
Guarding Against Validation-Split Overfitting
Running 1,000 hyperparameter trials against a single small validation split of 800 rows inevitably selects a lucky configuration whose random errors happened to align with those 800 rows—inflating validation metrics while degrading untouched test performance. Engineers protect generalization using three distinct splits (Train / Validation for HPO / untouched final Test vault) or nested cross-validation on small biomedical datasets.
- Prioritize hyperparameters by sensitivity: tune Learning Rate and Batch/Regularization scale first before touching minor epsilon constants.
- Be cautious pruning aggressive cosine-warmup runs too early at epoch 1—set a grace period past warmup before ASHA halving kicks in.
- Seed random generators and log every trial’s config hash, git commit, and validation metric in MLflow / Weights & Biases / SQLite.
FAQs
Why should learning rate always be tuned on a logarithmic scale instead of a linear scale?
On a linear scale `[1e-5, 1e-1]`, 90% of uniform samples fall between `0.01` and `0.1`, virtually ignoring `[1e-5, 1e-3]` where most Transformer and fine-tuning optima actually reside; log-uniform sampling explores every order of magnitude equally.
How many trials does Bayesian Optimization need before outperforming Random Search?
The first 10 to 20 startup trials typically use quasi-random Sobol or Latin Hypercube sampling to map the landscape, after which the surrogate model focuses search and measurably outperforms pure random sampling between trials 25 and 150.
References & Sources
- Bergstra, James; Bengio, Yoshua (2012) — Random Search for Hyper-Parameter Optimization, JMLR, 13, 281–305.
- Akiba, Takuya et al. (2019) — Optuna: A Next-generation Hyperparameter Optimization Framework, ACM KDD.
- Li, Lisha et al. (2020) — A System for Massively Parallel Hyperparameter Tuning (ASHA), MLSys.