
The lowest training loss is not necessarily the best model. I learned the engineering version of this lesson during my PhD on aircraft shape optimization: the best design on paper can be worse once it leaves the computer. Numerical optimization is about choosing variables, defining what counts as better, and respecting limits. This first part explains how to formulate the problem, recognize a minimum and decide whether that minimum is worth keeping.
Numerical Optimization series. This is Part 1 of four. The others are Part 2, Pareto fronts and weighted losses; Part 3, choosing an optimizer; 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.
What is an optimization problem?
An optimization problem has three parts: variables you control, an objective function that returns one number to minimize, and constraints that say which variables are allowed. Everything else, including the algorithm, comes after. When a project fails, check these three parts first, because an optimizer solves the problem you wrote and has no access to the one you meant.
Written compactly: minimize F(θ) over the variables θ, subject to ci(θ) ≤ 0. The table compares the wing problems of my 2008 thesis with three modern ones.
| Wing shape (2008 thesis) | LLM pretraining | Fine-tuning with LoRA | Hyperparameter tuning | |
|---|---|---|---|---|
| Variables | up to 48 in my response surface cases | 405 billion weights (Llama 3 405B) | two small matrices per adapted layer | a few to about 20 settings, some discrete (learning rate, weight decay, warmup) |
| Objective | drag at cruise | average next-token loss | next-token loss on your data | loss on held-out data at the end of training |
| Constraints | bounds on each variable | few explicit ones; weight decay acts softly | the update BA has rank at most r | bounds on each setting, total compute budget |
| One loss evaluation | a flow simulation, potentially hours | one minibatch, forward pass | one minibatch, forward pass | one training run, complete or cut short |
| Gradient | adjoint method | backpropagation | backpropagation | usually none; random or Bayesian search |
Hyperparameter tuning is an optimization problem wrapped around another one: each evaluation of the outer objective is a training run. It is also the modern case closest to wing design, with few variables and expensive evaluations. The main difference is that the wing had an adjoint gradient. Part 3 covers the search methods, including Optuna.
The first three columns of the last row hide a useful link. The discrete adjoint used in aerodynamics and backpropagation share the principle of reverse-mode differentiation: one reverse computation gives the derivative with respect to every variable. A training step includes both the forward loss evaluation and the backward gradient computation.
LoRA is a good example of a constraint that helps. It freezes the pretrained weights W and searches only for a low-rank update BA, so the problem has far fewer variables.
What loss does an LLM minimize?
An LLM learns to predict the next token, a word or a piece of a word. At each position of the training text, it gives a probability to every possible next token. The loss looks only at the probability it gave to the token that really came next: the higher that probability, the lower the loss. Training minimizes the average over the text.
| Probability the model gave to the right token | Loss for this token, −log(probability) |
|---|---|
| 90% | 0.11 |
| 50% | 0.69 |
| 10% | 2.30 |
| 1% | 4.61 |
The logarithm makes confident mistakes expensive: a model that gave 1% to the right token pays over 40 times more than one that gave 90%. With N tokens in the text, the loss is:
L(θ) = −(1/N) Σ log pθ(tokent | previous tokens)
Here θ is the list of weights, and pθ is the probability the model gives with those weights. This loss is called cross-entropy. To read it, take its exponential, the perplexity: a loss of 2.3 means a perplexity of about 10, so the model hesitates as if it had to choose among 10 equally likely tokens. Minimizing this loss amounts to finding the weights that make the training text as probable as possible, which statisticians call maximum likelihood.
Engineering and learning part ways here. In wing design, the function you minimize is the function you care about, up to modeling error. In machine learning, you minimize the loss on training text and you care about the loss on text the model has never seen. A lower training loss helps until it stops helping, and only held-out data tells you when.
When is a point a minimum?
At an interior minimum of a differentiable function, the gradient must be zero. The reverse is false. At a stationary point, the Hessian matrix collects the second derivatives. If every Hessian eigenvalue is positive, the point is a strict local minimum. If the signs are mixed, it is a saddle point: lower in some directions, higher in others.
| Gradient | Hessian eigenvalues | What you found |
|---|---|---|
| zero | all positive | strict local minimum |
| zero | all negative | local maximum |
| zero | both signs | saddle point |
| zero | zero eigenvalues, all others of one sign | undecided: flat directions, look at higher orders |
A local minimum is the best point in its neighborhood. The global minimum is the best point everywhere. They coincide for a convex function, where every point with zero gradient is a global minimum. Neural network losses are not convex.

Why do saddles become important in high dimension? Consider a toy model where a stationary point’s Hessian is a random symmetric Gaussian matrix. I counted how often every eigenvalue was positive, which is sufficient for a strict minimum.
| Variables n | Share of random Hessians with all eigenvalues positive |
|---|---|
| 1 | 50% |
| 2 | 14.7% |
| 3 | 2.5% |
| 4 | 0.24% |
| 5 | 0.014% |
A trained network does not have a random Hessian, so these frequencies are not estimates for LLMs. Dauphin and colleagues (2014) argue that saddles and the plateaus around them can obstruct descent more than bad local minima. Under suitable smoothness and step-size assumptions, gradient descent with a random start almost surely avoids strict saddles. It can still spend a long time in their vicinity.
Under suitable overparameterization and regularity conditions, a network’s global minima can form a high-dimensional surface. LLM pretraining is a different regime: Llama 3 405B saw 15.6 trillion tokens, about 38 per weight, and its training loss stays far from zero. Parameter symmetries still make many weight settings equivalent. The token-to-parameter ratio alone does not determine the geometry of the loss.
What do constraints change?
With constraints, the gradient no longer has to vanish at the solution. If the best allowed point sits on a limit, the gradient pushes against that limit, and the two balance. The Karush-Kuhn-Tucker (KKT) conditions state this balance: for each constraint there is a multiplier λ ≥ 0, and λ is zero unless the constraint is active.
- Stationarity: ∇F + Σ λi ∇ci = 0.
- Feasibility: every constraint holds, ci ≤ 0.
- Sign: every multiplier satisfies λi ≥ 0.
- Complementary slackness: λi ci = 0, so an inactive constraint costs nothing.
Under suitable regularity and sensitivity assumptions, the multiplier is a marginal price: it tells you how much the optimal objective improves if you relax the corresponding limit a little. KKT conditions are necessary under a constraint qualification. In a convex problem they are also sufficient, but in a non-convex problem they do not prove global optimality.
LLM work has the same picture. Safe RLHF writes harmlessness as an explicit constraint and updates λ during training. A fixed penalty is the cheaper relative: you set the price yourself and accept the limit that results. Reinforcement learning from human feedback (RLHF) works this way: a penalty keeps the new model close to the original one, with the distance between their predictions measured by the Kullback-Leibler (KL) divergence.
One trap: with plain stochastic gradient descent, weight decay equals an L2 penalty after rescaling. With Adam it does not, which is why AdamW applies the decay separately from the gradient step.
Why prefer a wide valley to the lowest point?
A robust minimum stays good when the variables or operating conditions change. A sharp minimum can be the lowest point on paper and perform badly in practice. Manufacturing tolerances and numerical rounding perturb variables, while distribution shifts change the function you care about. Wing designers may accept slightly higher drag for a design that tolerates changes in speed, incidence or shape.

| Minimum | Loss at the point | Average loss when the variable moves (Gaussian, standard deviation 0.3) |
|---|---|---|
| Left, local | 0.580 | 0.674 |
| Sharp, global | 0.057 | 0.673 |
| Wide, local | 0.209 | 0.263 |
The global minimum loses its advantage after perturbation: 0.673 against 0.263 for the wide valley. Quantizing an LLM to fewer bits also perturbs weights, though real quantization errors are not independent Gaussian noise. This experiment illustrates a mechanism, not a prediction of quantized model performance.
Does flatness explain why networks generalize? The idea goes back to Hochreiter and Schmidhuber (1997), and Keskar and colleagues (2016) tied sharp minima to large batches. Sharpness-aware minimization turns it into a training objective. Dinh and colleagues (2017) set the limit: in ReLU networks you can rescale the weights to make a minimum look arbitrarily sharp without changing the function. Treat flatness as a useful signal with no settled definition.

What should you check before training?
Write the problem down before you choose an optimizer. Five questions catch most formulation errors, for a wing as for a model, and each one costs less than a training run. If you cannot answer one of them, a faster optimizer will only take you to the wrong answer sooner.
- Which variables can move, and which are frozen?
- Is the objective what you want, or a proxy for it? How will you notice when the two separate?
- Which limits are hard constraints, and which are preferences you can price?
- How noisy is one evaluation, and what does it cost?
- How much can the variables move after training (quantization, merging, further fine-tuning) before quality drops?
Part 2 tackles the harder formulation: what happens when there is more than one measure of success?
Optimization basics FAQ
What is the difference between a loss function and an objective function?
In machine learning, the loss measures the error on examples, and the objective is everything the optimizer minimizes: the average loss plus any penalty, such as weight decay or a KL term. In engineering, the word objective covers both. When the two differ, report them separately, because a penalty can fall while the loss stays flat.
Is the global minimum always the goal in deep learning?
No. Training stops on a budget, and the target is low loss on unseen data. In an LLM, many different weight settings reach a similar training loss, so the question becomes which of them generalizes and tolerates perturbation. An exact global minimum of the training loss is neither needed nor verifiable at LLM scale.
Are adjoint methods and backpropagation the same thing?
They are the same principle, reverse-mode differentiation, applied to different computations. The discrete adjoint differentiates a converged flow solver, usually by solving one linear system per objective. Backpropagation walks back through the layers of a network. In both cases the cost of the gradient, relative to one evaluation of the function, does not grow with the number of variables.
Related research posts
- Part 2, Pareto fronts and weighted losses
- Part 3, choosing an optimizer
- Part 4, gradient descent, Newton, Adam and Muon
- My PhD thesis: Kriging for aerodynamic shape optimization
- Gradient and Cokriging optimizers compared on four criteria
Sources
- J. Laurenceau, Surfaces de réponse par krigeage pour l’optimisation de formes aérodynamiques, PhD thesis, INPT, 2008, sections I.1 and I.2.3 (full text, in French). This post rewrites those sections for LLM training.
- S. Boyd and L. Vandenberghe, Convex Optimization, Cambridge University Press, 2004.
- Y. Dauphin et al., Identifying and attacking the saddle point problem, 2014.
- J. Lee et al., Gradient Descent Converges to Minimizers, 2016; Y. Cooper, The loss landscape of overparameterized neural networks, 2018.
- S. Hochreiter and J. Schmidhuber, Flat Minima, 1997; N. Keskar et al., On Large-Batch Training, 2016; L. Dinh et al., Sharp Minima Can Generalize, 2017; P. Foret et al., Sharpness-Aware Minimization, 2020.
- E. Hu et al., LoRA, 2021; I. Loshchilov and F. Hutter, Decoupled Weight Decay Regularization, 2017.
- L. Ouyang et al., InstructGPT, 2022; J. Dai et al., Safe RLHF, 2023; The Llama 3 Herd of Models, 2024.
- The random Hessian table and the three-valley numbers are my own computations (NumPy, fixed seeds).
0 Comments