Sam Babichenko

Reading notes / Deep Learning Alchemy

Loss basins, river valleys and saddle points

From Lecture 5 of Stanford CS 312 Deep Learning Alchemy (Fall 2026), taught by Tatsunori Hashimoto and Suhas Kotha

slides quiz answers assignment code

Landscape
θ\thetathe model's parameters (weight vector), the variable the loss depends on
L(θ)L(\theta)the loss at parameters θ\theta; in the course's runs, validation loss in nats per token
HHthe Hessian H=∇2L(θ)H=\nabla^2L(\theta), the matrix of second derivatives of the loss
hih_ithe ii-th eigenvalue of the Hessian HH, the curvature of the loss along eigendirection ii
ε\varepsilonthe loss at a critical point (a point where ∇L=0\nabla L=0)
α\alphathe index of a critical point, the fraction of Hessian eigenvalues that are negative there
Averaging
θ1,θ2\theta_1,\theta_2the weights of two trained models whose average is tested
θ0\theta_0the pretrained starting point shared by two fine-tuned models θ1,θ2\theta_1,\theta_2
B(θ1,θ2)B(\theta_1,\theta_2)midpoint barrier B=L(θ1+θ22)−L(θ1)+L(θ2)2B=L\big(\tfrac{\theta_1+\theta_2}2\big)-\tfrac{L(\theta_1)+L(\theta_2)}2, the loss of the weight average minus the average loss; B≤0B\le0 for a convex loss, and B≤.01B\le.01 counts as averaging working
Bestthe lower of the two models' losses (the better endpoint)
Ensthe loss of the ensemble, the model whose next-token probabilities are 12pθ1+12pθ2\tfrac12p_{\theta_1}+\tfrac12p_{\theta_2}
Avgthe loss of the weight average 12(θ1+θ2)\tfrac12(\theta_1+\theta_2)
xxthe number of updates in the shared prefix, trained once before two runs fork
yythe number of updates in each of the two branches after a fork, each with a different data order
τ\tautask vector τ=θft−θpre\tau=\theta_{\mathrm{ft}}-\theta_{\mathrm{pre}}, the change in weights made by fine-tuning on one task
Training
η\etalearning rate (Lecture 5's noisy-quadratic slides write α\alpha)
ω\omegadecoupled weight-decay coefficient; each AdamW update multiplies the weights by 1−ηω1-\eta\omega (.1 in d8)
cic_iper-example gradient-noise variance along Hessian eigendirection ii, in the noisy quadratic model
bbbatch size, the number of examples averaged into each gradient (the slides write BB)
ℓi(t)\ell_i(t)the loss along Hessian eigendirection ii after tt steps, in the noisy quadratic model
ℓi∞\ell_i^\inftynoise floor ℓi∞=ηci/(2b(2−ηhi))\ell_i^\infty=\eta c_i/(2b(2-\eta h_i)), the loss along direction ii that a constant learning rate η\eta settles at
θˉt\bar\theta_texponential moving average (EMA) of the weights, θˉt=βθˉt−1+(1−β)θt\bar\theta_t=\beta\bar\theta_{t-1}+(1-\beta)\theta_t, used only for evaluation
β\betadecay of the weight EMA θˉt\bar\theta_t; β=.999\beta=.999 averages over about 1,000 updates

Context. Training moves parameters θ\theta downhill on a loss L(θ)L(\theta) over millions of coordinates that no one can plot directly. Practitioners still use mental pictures of that landscape to decide whether two models can be averaged, why runs end with a learning-rate decay, or whether a flat training curve means the optimizer is stuck. Lecture 5 of Hashimoto and Kotha's Stanford course CS 312 Deep Learning Alchemy (Fall 2026) examines three such pictures: loss basins, the river valley, and critical points. Assignment 3 and Quiz 3 test the first two on the course's the course's depth-8 transformer language model ("d8"), pretrained for 9,375 AdamW updates (about 614M tokens) at peak learning rate .003 and weight decay .1, with a linear decay of the rate to zero; each course experiment changes one part of this recipe. Reading note: Prediction as understanding: the d8 model organism.

Models that share enough training history land in a common a region of weight space around a minimum where the loss is close to convex, so that averaging the weights of two models inside it gives a loss no worse than the average of theirs, so their weights can be averaged. Fine-tunes of one pretrained checkpoint and runs forked late enough in pretraining share a basin, whereas independently pretrained models do not. At a constant learning rate, the iterate bounces across the steep walls of a valley while drifting down a flat river at its floor. Decaying the rate or averaging the iterates removes the bounce and exposes that progress. In high-dimensional random-field models, almost every high-loss critical point is a saddle rather than a local minimum, and local minima sit near the global minimum. Gradient descent escapes strict saddles on its own.

Setting. Two probes test these pictures in the literature and on d8. To test whether two models θ1,θ2\theta_1,\theta_2 share a convex basin, the d8 experiments track the how much worse the averaged weights are than the average of the two losses; B≤0B\le0 for any convex loss on validation loss, B(θ1,θ2)=L(θ1+θ22)−L(θ1)+L(θ2)2.B(\theta_1,\theta_2)=L\Big(\tfrac{\theta_1+\theta_2}2\Big)-\tfrac{L(\theta_1)+L(\theta_2)}2. By Jensen's inequality, any convex loss satisfies B≤0B\le0; the experiments count B≤.01B\le .01 as averaging working. Each pair is reported through three losses: Best for the lower endpoint loss, Ens for the the model whose next-token probabilities are 12pθ1+12pθ2\tfrac12p_{\theta_1}+\tfrac12p_{\theta_2}, the average of the two models' probabilities that averages predicted probabilities, and Avg for the weight average 12(θ1+θ2)\tfrac12(\theta_1+\theta_2). The H=∇2L(θ)H=\nabla^2L(\theta), the matrix of second derivatives of the loss; along an eigenvector with eigenvalue hh, the loss near a critical point changes like 12hz2\tfrac12hz^2 in the coordinate zz along it H=∇2L(θ)H=\nabla^2L(\theta) captures local curvature, and a Krylov method that builds the subspace spanned by v,Hv,H2v,…v,Hv,H^2v,\dots from Hessian-vector products alone; the eigenvalues of HH restricted to that subspace approximate its extreme eigenvalues, and the Hessian itself is never formed estimates its top eigenvalues from Hessian-vector products without forming HH.

What it changes in practice. Averaging fine-tunes of one checkpoint usually beats keeping the best single run. Pretraining runs become averageable only after a long enough shared prefix. In a constant-rate run, progress shows up in a weight average or after a short a final stretch of training in which the learning rate is decayed to zero, which lets the iterate settle and shows the progress made at the higher rate. Reading note: Learning-rate schedules and batch size. Under AdamW with learning rate η\eta and decoupled θ←(1−ηω)θ\theta\leftarrow(1-\eta\omega)\theta at every update; ω\omega is the weight-decay coefficient (.1 in d8), and decoupled means the shrink is applied to the weights directly, outside AdamW's per-coordinate rescaling of the gradient step, a learning-rate change leaves a transient of about 1/(ηω)1/(\eta\omega) updates, roughly 3,300 on d8. Training needs no special machinery to avoid saddles or bad local minima.

Two independently pretrained models do not share a basin. On d8, two runs from different random seeds reach validation losses of 2.942 and 2.939 nats per token, yet their 50/50 weight average scores 7.795. Along the straight line between them, the loss rises smoothly to that peak. Part of this barrier comes from reordering the hidden units of a layer, together with the matching rows and columns of the weight matrices on either side, leaves the network's function unchanged: two runs can learn the same function with their hidden units in different orders. Aligning units before averaging with Git Re-Basin (Ainsworth et al., 2022) or optimal-transport fusion (Singh and Jaggi, 2019) lowers the barrier, though the matched average still trails an ensemble of the two models.

Independent minima are still joined by simple curved paths. Garipov et al. (2018) connect independent minima of image classifiers by a one-bend polygonal chain or a quadratic Bezier curve. Training loss and test accuracy stay nearly flat along the path. To fit a curve, they hold the endpoints fixed and minimize expected loss at a uniformly random value of the curve parameter. Their Fast Geometric Ensembling exploits this geometry by running short learning-rate cycles and saving checkpoints, yielding an ensemble for the cost of one training run. Within a single run, loss often falls monotonically along the line from initialization to final weights, more reliably under SGD than under Adam (Lucas et al., 2021).

Fine-tunes of one pretrained model share a basin. Starting from a shared pretrained checkpoint θ0\theta_0 keeps fine-tuned weights close enough for linear interpolation to work. WiSE-FT (Wortsman et al., 2021) interpolates linearly between zero-shot and fine-tuned weights. It improves accuracy both in distribution and under distribution shift, and often beats sweeps over learning rate, epochs, and weight decay. In reasoning models, interpolating the last fine-tuning checkpoint with an earlier one restores coverage measured by the probability that at least one of kk sampled answers is correct, estimated from n≥kn\ge k samples with mm correct as 1−(n−mk)/(nk)1-\binom{n-m}{k}/\binom nk (Chen et al., 2021). Reading note: RL and the set of solvable problems and improves single-sample accuracy at the same time (Dang et al., 2025). weight averages of several models fine-tuned from the same pretrained weights, with different seeds or hyperparameters; the greedy soup adds a model to the average only if held-out accuracy does not fall (Wortsman et al., 2022) average several fine-tunes at zero extra inference cost. Gains grow with the angle between the displacements θ1−θ0\theta_1-\theta_0 and θ2−θ0\theta_2-\theta_0, so soups vary hyperparameters across runs. A greedy soup, which adds a model only when it improves held-out accuracy, beats a uniform average.

Task arithmetic adds and subtracts fine-tuning displacements as directions. Ilharco et al. (2022) define a τ=θft−θpre\tau=\theta_{\mathrm{ft}}-\theta_{\mathrm{pre}}, the change in weights made by fine-tuning on one task τ=θft−θpre\tau=\theta_{\mathrm{ft}}-\theta_{\mathrm{pre}} for a model fine-tuned on one task. Adding two task vectors gives a model both capabilities, while subtracting a task vector removes its capability. Negating target task vectors cuts a pretrained ViT-L/14's accuracy on those tasks from 64.8% to 19.0%, while control-task accuracy moves only from 75.5% to 72.9%.

Forked pretraining runs share a basin once the shared prefix is long enough. Fort et al. (2020) train a parent network for a short prefix and branch off children with different data orders. Past a brief parent phase, the error barrier between children drops near zero. On d8, the same test runs at a constant learning rate of .003 after warmup. A shared prefix of x∈{0,50,100,250,500,1000}x\in\{0,50,100,250,500,1000\} updates splits into two independent branches of y∈{25,50,100,250,500}y\in\{25,50,100,250,500\} updates with different data orders. Across this grid, the ensemble always matches or beats the weight average, and a too-short prefix leaves the weight average worse than the better endpoint. Counting losses within .01 as equal (lowest first): at x=100,y=50x=100,y=50, Avg = Ens < Best; at x=100,y=250x=100,y=250 and x=250,y=250x=250,y=250, Ens < Avg < Best. Staying in one basin depends on how far the branches drift relative to how settled the prefix was at the split.

A constant learning rate leaves a noise floor that decay or averaging removes. The noisy quadratic model explains why constant-rate runs plateau and why cooldowns or weight averages drop the loss right away. It splits the loss into independent Hessian eigendirections. Along direction ii, with curvature hih_i, per-example gradient-noise variance cic_i, and batch size bb, SGD at learning rate η\eta gives expected loss after tt steps E ℓi(t)=(1−ηhi)2t E ℓi(0)+(1−(1−ηhi)2t) ℓi∞,ℓi∞=ηci2b(2−ηhi).\begin{aligned}\mathbb E\,\ell_i(t)&=(1-\eta h_i)^{2t}\,\mathbb E\,\ell_i(0)\\&\quad+\big(1-(1-\eta h_i)^{2t}\big)\,\ell_i^{\infty},\\\ell_i^{\infty}&=\frac{\eta c_i}{2b(2-\eta h_i)}.\end{aligned} The first term decays the starting error geometrically. The second rises to the ℓi∞=ηci/(2b(2−ηhi))\ell_i^\infty=\eta c_i/(2b(2-\eta h_i)), the loss along Hessian eigendirection ii once the starting loss has decayed away; gradient noise keeps it up, and it grows with the learning rate η\eta. Reading note: Noisy quadratics and weight norms ℓi∞\ell_i^\infty, which is roughly proportional to η\eta while ηhi\eta h_i stays well below 2. Decaying η\eta lowers this floor directly; averaging the iterates (Polyak averaging) cuts a single direction's noise term like 1/T1/T over TT steps. Measured transformer Hessians fit this diagonal model loosely: their eigenvalues decay smoothly, and most, though not all, are positive (Meterez et al., 2026).

In the river-valley picture, a high learning rate hides progress that a decay reveals. Wen et al. (2024) interpret this anisotropy geometrically: the high-curvature directions form the walls of a valley and the low-curvature directions a river along its floor. A large learning rate bounces the iterate from wall to wall while letting it move quickly down the river. Successive full-batch updates show negative cosine similarity from that bounce (Xing et al., 2018), though SGD noise blurs the sign. Total loss reflects height up the walls, so progress down the river stays hidden until a cooldown drops the iterate to the floor. Branching a cooldown off a constant-rate run therefore matches a cosine schedule tuned to that exact length (Hägele et al., 2024).

Cooldown schedules, horizon-free schedules, and weight EMAs serve multiple budgets from one run. One cooldown approach branches a decay off a long constant phase at each target budget (MiniCPM; Hu et al., 2024). Because the optimal peak rate falls with training length, that branch finishes somewhat worse than a schedule tuned for each length. A second cooldown variant, Wen et al.'s WSD-S, resumes high-rate training directly from a decayed checkpoint. Horizon-free schedules instead lower the peak rate continuously, for instance as the inverse square root of the step. An evaluation-only exponential moving average of the weights, θˉt=βθˉt−1+(1−β)θt\bar\theta_t=\beta\bar\theta_{t-1}+(1-\beta)\theta_t, used only for evaluation; decay β=.999\beta=.999 averages over about 1,000 updates averages across the wall-to-wall bounce to estimate river-floor loss without a cooldown.

On d8, an EMA closes most of the gap to a cooldown. At a constant learning rate of .003, d8 reaches validation loss 3.099 with raw weights. Adding a β=.999\beta=.999 EMA drops it to 2.973, closing about 73% of the gap to a linear decay to zero. When the schedule decays to zero, the EMA hurts only slightly at the very end, where its 1,000-step window lags the descending weights.

Under AdamW, learning-rate changes settle on the weight-decay timescale 1/(ηω)1/(\eta\omega). Each AdamW update moves every weight by roughly η\eta regardless of gradient scale, so its effect on the function depends on η\eta relative to the weight norm. When weights have grown, the same η\eta produces smaller relative steps. Decoupled weight decay multiplies the weights by 1−ηω1-\eta\omega per update, so the weight norm and relative step size adjust to a new η\eta over about 1/(ηω)=1/(.003×.1)≈3,3331/(\eta\omega)=1/(.003\times .1)\approx3{,}333 updates. As a rule of thumb, any learning-rate change leaves a transient of about that length. In dip-and-rewarm runs, lowering the rate temporarily drops the loss below the control as the iterate slides down the valley walls. Restoring the rate then creates an overshoot above the control until the transient fades. Across d8 schedule runs, that overshoot tracked the learning-rate area removed, the sum over updates of the rate given up.

In high-dimensional random fields, high-loss critical points are saddles. At a a point where the gradient ∇L\nabla L is zero: a local minimum if every Hessian eigenvalue is positive, a saddle if some are negative and some positive, let ε\varepsilon be the loss and α\alpha the the fraction of the Hessian's eigenvalues that are negative at a critical point. For high-dimensional Gaussian random fields, Bray and Dean show that α\alpha rises monotonically with ε\varepsilon. The Hessian has a random-matrix semicircle spectrum that sits rightward at low loss, with all eigenvalues positive near the global minimum, and shifts leftward at high loss, picking up many negative eigenvalues. High-loss critical points are therefore saddles with overwhelming probability, while index-0 minima cluster near the global minimum. Dauphin et al. (2014) test this on a one-hidden-layer MLP on downsampled MNIST and CIFAR-10. Using Newton's method, which converges to critical points of any index, they recover a rising error-versus-index curve. They attribute gradient descent's apparent stalls to plateaus around saddles. Plain Newton's method, θ←θ−H−1∇L\theta\leftarrow\theta-H^{-1}\nabla L, divides each eigendirection's gradient by its eigenvalue hh, stepping toward a saddle along negative-curvature directions. Their saddle-free Newton divides by ∣h∣|h| and steps away.

Exact models and optimization theory confirm that gradient descent avoids strict saddles. Several tractable problems have no local minima whose loss is above the global minimum. Both a one-hidden-layer linear network under square loss (Baldi and Hornik, 1989) and positive semidefinite matrix completion (Ge et al., 2016) have only saddles and global minima. Yun et al. (2018) nevertheless construct neural networks with bad local minima. From a random start with a small fixed step, gradient descent almost surely avoids every a critical point whose Hessian has at least one strictly negative eigenvalue, so a descent direction exists; if every point with a small gradient either has a Hessian eigenvalue below a fixed negative level or lies near a local minimum around which the loss is strongly convex (the robust strict-saddle property), noisy gradient descent reaches a point near a local minimum in polynomially many steps (Ge et al., 2015) (Lee et al., 2016). When its iterates converge and every saddle is strict, they therefore reach a local minimizer almost surely. Adding occasional random perturbations lets gradient descent escape strict saddles with a step count polylogarithmic in dimension (Jin et al., 2017). From very small initialization, deep linear networks are conjectured to pass near a sequence of saddles, one plateau each, before reaching a global minimum. Jacot et al. (2021) prove the passage between the first two saddles and support the rest with experiments. In Lecture 5's reading, saddles vastly outnumber local minima, surviving local minima sit near optimal loss, and gradient descent is not permanently blocked by them. These results still leave open how long training lingers near a saddle.

Caveats. All three pictures are cartoons. Two-dimensional loss slices depend heavily on architecture, with skip connections smoothing them (Li et al., 2018). A network landscape can even be engineered to match almost any chosen picture (Skorokhodov and Burtsev, 2019). The river valley redraws the convex noisy quadratic, and Lecture 6 revises what sets the steepness of its walls. Weight averaging also mixes two distinct effects. In WiSE-FT, an EMA during fine-tuning behaves differently from interpolating the start and end points, so averaging along one trajectory differs from averaging across a basin. The critical-point theory rests on random-field models and small networks.

Terms

basin
region around a minimum where the loss is close to convex, so weight averages of models inside it do no worse than the models' average loss
midpoint barrier BB
L(θ1+θ22)−L(θ1)+L(θ2)2L(\tfrac{\theta_1+\theta_2}2)-\tfrac{L(\theta_1)+L(\theta_2)}2; B≤.01B\le.01 counts as averaging working
ensemble vs average
average of the two models' predicted probabilities vs the model with averaged weights; the ensemble never needs a shared basin
WiSE-FT, model soup
interpolate a fine-tune with its starting point; average several fine-tunes of one model
task vector
θft−θpre\theta_{\mathrm{ft}}-\theta_{\mathrm{pre}}; add to give a skill, subtract to remove it
forked runs
two runs sharing a prefix of training; averageable once the prefix is long enough compared with how far the branches travel
noise floor
steady-state loss ηci/(2b(2−ηhi))\eta c_i/(2b(2-\eta h_i)) per direction at a constant learning rate, roughly proportional to η\eta while ηhi≪2\eta h_i\ll2
river valley
steep walls where a large step bounces, a flat river along the floor where progress happens; decay or averaging shows the progress
EMA
θˉt=βθˉt−1+(1−β)θt\bar\theta_t=\beta\bar\theta_{t-1}+(1-\beta)\theta_t; helps at a constant rate, lags slightly at the end of a decay to zero
1/(ηω)1/(\eta\omega)
AdamW weight-decay timescale; how long a learning-rate change takes to settle (about 3,300 updates in d8)
index
fraction of negative Hessian eigenvalues at a critical point; rises with the loss there
saddle-free Newton
Newton step with each eigenvalue hh replaced by ∣h∣|h|, so it moves away from saddles

Sources

Lecture 5, “Loss Landscapes Part 1: Basins, River Valley, Critical Points” (Oct 13, 2026), of Stanford CS 312 Deep Learning Alchemy, Fall 2026. Taught by Tatsunori Hashimoto and Suhas Kotha; course staff Kaiyue Wen and Tristan Thrush (CAs).

Course site Lecture slides Online quiz Quiz answers Assignment Assignment code

The lessons, experiments, figures and quiz problems in this note are the course's, shown here with the instructors' permission.

Connected notes

  • SGD's expected loss is the gradient-descent loss plus a term from noise injected while the loss is still of order one, so SGD noise matters only when the kernel decays more slowly than the gradient-descent loss.

  • In one-layer linear self-attention, the loss depends only on the product V=u−1U11V=u_{-1}U_{11} and leaves the scale split between the label-value scalar and the key-query matrix free; gradient flow conserves u−12=∥U11∥F2u_{-1}^2=\|U_{11}\|_F^2, which pins the limit on the hyperbola of equivalent global minima.

  • Smoothing the loss over a cap of radius λ\lambda shrinks gradient noise faster than the squared signal up to λ=d1/4\lambda=d^{1/4}, which lowers the sample cost from dk⋆−1d^{k^\star-1} to the correlational-query lower bound dk⋆/2d^{k^\star/2}.

  • When every update has spectral norm at most bb, decay applied as 1−ηλ1-\eta\lambda confines the weights to a spectral-norm ball of radius b/λb/\lambda. The learning rate does not enter the radius and sets only the speed λ∑tηt\lambda\sum_t\eta_t at which the weights get there.

Threads