A sledgehammer sits above a delicate precision screw, and a spirit level above a heavy steel wedge.

Why do we train hundreds of billions of model weights with gradients, then tune the learning rate with random search? Because these are two very different optimization problems. The number of variables, cost of an evaluation, gradient access and shape of the landscape matter more than the optimizer’s reputation. After formulating the objective in Parts 1 and 2, this part explains how I choose an optimization algorithm.

Numerical Optimization series. This is Part 3 of four. The others are Part 1, loss, constraints and minima; Part 2, Pareto fronts and weighted losses; and Part 4, gradient descent, Newton, Adam and Muon. The series starts from chapter I of my 2008 PhD thesis and applies it to LLM training.

Is there a best optimization algorithm?

No. Wolpert and Macready (1997) proved that, averaged uniformly over all possible functions on a finite set, all search algorithms that never repeat a point perform the same, random search included. An algorithm wins on some problems because it bets on a structure those problems have, such as smoothness, and loses elsewhere.

Real problems are a small, structured part of “all possible functions”, so some optimizers are better for you. The theorem tells you where to look for evidence: your own problem class. A ranking on somebody else’s test functions only transfers if your function shares their structure.

I measured this on four test functions: a budget of at most 4,000 equivalent function evaluations, a gradient charged as four evaluations (the theoretical bound for reverse mode, explained below), 21 runs with independent random seeds, and the median best value (zero is perfect). Single-start BFGS stops early, with median costs between 20 and 370. The other methods use the whole budget: random search draws new points, BFGS restarts from new points, and the evolution strategy adapts its sampling and restarts when it stalls.

MethodBowl, 2 variablesBowl, 50 variablesRastrigin, 2 variablesRastrigin, 20 variables
Random search0.4258,4551.07214
BFGS, one startbelow 1e-16below 1e-1612.9232
BFGS, restartsbelow 1e-16below 1e-160.99133
Evolution strategy2.77,183below 1e-16105

The bowl is a single valley with a condition number of 10,000. Rastrigin has a regular grid of local minima. BFGS solves the bowl particularly efficiently. On Rastrigin one run gets trapped, restarts help, and the evolution strategy does better still. That strategy adapts one global step size and no covariance, which limits its progress on the ill-conditioned bowl. A different tuning could change the ranking, which is the point.

Two fairness caveats. These are equivalent evaluation counts, with no wall-clock time. And single-start BFGS spends much less than the others, so I also gave random search only the median budget of one BFGS run. On Rastrigin it then reaches 5.50 in two dimensions, better than the 12.9 of BFGS, and 245 in twenty, a near tie with 232 (individual BFGS runs range from 112 to 306). At equal cost, a single descent on a function full of local minima gave no clear advantage over random sampling. Which method wins depends on the budget as well as the landscape.

Cafeteria counter with an open serving dome over an empty plate, under the words NO FREE LUNCH.
Averaged over every possible problem, no search algorithm beats another.

What are exploration and exploitation?

Exploration looks for the best valley. Exploitation goes to the bottom of the valley you are in. Every optimizer divides a limited budget between the two. A uniform grid explores and never exploits. Gradient descent from one start exploits and barely explores. There is no agreed unit to measure either, so compare methods on cost and result.

Modern training exhibits related behavior, although SGD noise is not a deliberate global search strategy. A large learning rate and minibatch noise can help weights leave certain narrow basins or plateaus; a decaying schedule then reduces the noise. Reinforcement learning faces an explicit exploration and exploitation choice in its policy.

You do not always want the global minimum. A limited exploration that skips narrow valleys can be a feature, since narrow valleys are the fragile ones.

Why does global search fail in high dimension?

Covering a space costs a number of points that grows exponentially with the number of variables. Bellman called it the curse of dimensionality. With 10 variables and 10 levels per variable, a grid needs 1010 evaluations, or 317 years at one second each. Five levels per variable bring it down to 113 days, for a grid about twice as coarse.

Grid evaluations against the number of variables on a log scale, with lines for one day, one year and the age of the universe.
Grid cost at one second per evaluation, with 5 and 10 levels per variable.

Even a full grid proves nothing without an assumption on the function, such as a bound on its slope. Between two grid points, an arbitrary function can hide any minimum. That is why nobody can certify a global minimum by sampling alone.

Random sampling escapes the exponent in one sense: 299 random points give a 95% chance of hitting the best 1% of the space, in any dimension. In high dimension, though, the best 1% of the volume can still be far from the optimum, as the 50-variable bowl shows.

Population methods such as genetic algorithms search smarter than a grid. The exponential worst case remains, and nothing guarantees that their answer is global.

Why does random search beat grid search for hyperparameters?

Usually only a few hyperparameters matter, and you do not know which ones. A grid of nine runs over two settings tests three values of each. Nine random runs test nine values of each. Bergstra and Bengio (2012) showed this on neural networks, where random search found models as good or better in a small fraction of the computation time.

Nine grid points project onto three values of the setting that matters; nine random points project onto nine values.
Illustration of the argument of Bergstra and Bengio. Same budget, three times more distinct values of the setting that matters.

When one run costs a full training, even random search is too expensive. Three ideas reduce the bill:

  • Model the response. Bayesian optimization fits a surrogate to past runs and proposes the next one. My thesis used the same loop, with Kriging and RANS simulations.
  • Tune small, transfer large. With μTransfer, many optimal hyperparameters stay stable as the model grows, so you tune a small model and reuse the settings.
  • Stop bad runs early. Give every configuration a small budget and continue only the best. Early rankings can flip when the learning rate decays, so keep a margin.

What does Optuna do for hyperparameter search?

Optuna is an open-source Python framework that runs this search for you. You write a function that trains a model with suggested settings and returns a score. Optuna proposes the next settings, records every trial and stops the bad ones early. It automates the first and third ideas above, and it does not make one training run cheaper.

Akiba and colleagues (2019) built it around three choices: the search space is defined inside the function (so one setting can depend on another), the sampler is replaceable, and unpromising trials can be pruned while they run. Its components map onto the methods of this series:

Optuna componentWhat it doesWhere the idea appears here
RandomSampler, GridSamplerdraws at random or walks a gridrandom versus grid search
TPESampler (default)compares the settings of good and bad trials, then samples where good ones are more likelymodel the response
GPSamplerBayesian optimization with a Gaussian processKriging, as in my thesis
CmaEsSamplerevolution strategy with a full covariance matrixevolution strategies
MedianPruner, HyperbandPrunerstops trials that lag behind the othersstop bad runs early
Several directions, with NSGAIISamplerreturns the nondominated trials instead of one bestthe Pareto front of Part 2

Two habits avoid most disappointments. The default sampler draws its first 10 trials at random, so a study of 10 trials is plain random search: plan several times that. And a pruner judges a run on its early score, so a setting that only wins after the learning rate decays can be cut too soon. Keep a few complete runs as a check. With LLMs, use Optuna on a small model or on fine-tuning, then transfer the settings.

Why can gradient descent train billions of weights?

Because one reverse-mode differentiation pass gives every component of the gradient at a cost bounded by a small multiple of the forward computation. The theoretical multiple is around four or five. This does not mean training cost is independent of model size: the forward computation itself grows. Finite differences instead need one extra forward evaluation per variable, or 405 billion extra passes for Llama 3 405B.

MethodEvaluations per gradientExtra memory
Finite differences, n variablesn + 1none
Reverse mode (backpropagation, adjoint)a few, independent of nstored intermediate states

Memory is the price. Backpropagation keeps activations from the forward pass until the backward pass uses them. Gradient checkpointing stores part of them and recomputes the rest.

The numbers show how strongly this works. Llama 3 405B was trained with a schedule of 1.2 million steps, which is one step for every 337,500 weights. No method that needs even one evaluation per variable could get there.

The result of descent still depends on the starting point. In deep learning, initialization, normalization and a pretrained checkpoint all choose the valley before the optimizer runs. Fine-tuning is local optimization from an excellent start.

Which optimizer fits which LLM task?

Choose by dimension, gradient access and cost per evaluation. Weights have gradients and billions of dimensions, so first-order methods are a natural default. Hyperparameters have far fewer dimensions and are often optimized with derivative-free search. Discrete outputs such as prompts, code and kernels can be searched with evolutionary methods when an automatic evaluator exists.

TaskVariablesGradientUsual choice
Pretraining weights109 to 1012yes, noisyAdamW, Muon
Fine-tuning with LoRA106 to 108yes, noisyAdamW
Learning rate, decay, warmup3 to 20norandom or Bayesian search on small models, for example with Optuna
Post-training on a rewardall weightsestimated from samplespolicy gradient methods such as PPO (next section)
Prompts, code, algorithmsdiscretenoevolutionary search, for example AlphaEvolve

Keep one counterexample in mind. Qiu and colleagues (2025) fine-tuned LLMs with billions of parameters using an evolution strategy, without backpropagation and with a population of 30. They report better results than established reinforcement learning implementations on several criteria. The number of parameters overstates the difficulty when a pretrained model is the starting point. The curse of dimensionality is a worst case, and structure can beat it.

Is PPO a surrogate-based optimization method?

Yes, in its loop. Proximal policy optimization (PPO) and the Kriging optimizer of my thesis both evaluate something expensive, build a cheap surrogate from the samples, optimize the surrogate, then sample again. They differ in what the surrogate is and in what keeps the optimizer from trusting it too far. PPO is closer to a trust-region method than to Kriging.

The word is in the papers: TRPO (2015) and PPO (2017) both call the function they maximize a surrogate objective.

Kriging optimizer (my thesis, chapter IV)PPO
Expensive evaluationone flow simulationa batch of actions or answers, with their rewards
Surrogatean interpolation of the function over the design variablesan average over the samples, reweighted by how much more likely the new policy makes each action
Where it is reliablearound the simulated shapesaround the policy that produced the samples
What limits the stepno limit on the domain; the predicted error enters two of the three search criteriathe probability ratio is clipped (ε = 0.2 in the paper), or a penalty on the KL divergence
Explorationsampling where the prediction minus its error is lowestrandomness of the policy, with an optional entropy bonus
Search on the surrogateglobal: random and genetic search, then a gradient methodlocal: a few epochs of minibatch gradient steps
Old samplesall keptreplaced by a new batch at each iteration

Both methods also use pessimism. One of my three search criteria minimized the prediction plus its standard error, which favors shapes that should be good even if the model is wrong. The clipped objective of PPO is a pessimistic bound on the unclipped one.

The closest relative of a Kriging surface in LLM training is the reward model of RLHF. It is a model fitted to expensive human judgments, then optimized in their place. It fails like a response surface does: push far from the data, and the optimizer finds points where the model is wrong. My optimizer ran a real simulation at the points it proposed and refitted the model (comparison of the optimizers). Collecting new human comparisons on the latest policy is the same remedy.

For training weights, the remaining question is which gradient-based optimizer to use, and what you pay for a better update. Part 4 compares the mechanisms and their costs.

Choosing an optimizer FAQ

What does the no free lunch theorem mean for machine learning?

It means that no learning or search algorithm is best on every possible problem, so performance always comes from matching the structure of the data. Gradient methods do well on neural networks because the loss is mostly smooth and one backward pass gives every derivative. The theorem does not say that all optimizers are equal on your problem.

Should I use grid search or random search for hyperparameters?

Use random search as the default when you tune more than two settings, because it tests more distinct values of each important setting for the same budget. Sample the learning rate on a logarithmic scale. Use Bayesian optimization, for example the default TPE sampler of Optuna, when each run is expensive and you can wait for results before launching the next ones.

Can gradient descent find the global minimum of a neural network?

Nobody can verify it at scale, and it is not required. Many different weight settings reach a similar training loss, and an LLM never drives that loss to zero, because text is not fully predictable. What matters is the loss on held-out data, and it depends on the path taken by the optimizer as well as on the final training loss.

Related research posts

Sources


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *