# Loss Landscapes: Basins, River Valleys & Saddle Points | Stanford CS312 Lecture 5 with Suhas Kotha

## Executive summary

This lecture explores the complex geometry of the loss landscape using three mental models: basins, river valleys, and critical points. It contrasts the behavior of models during pre-training versus fine-tuning, demonstrating that weight averaging often yields superior results in the fine-tuning regime (where models share a basin), but not in pre-training. The lecture also provides a crash course on second-order methods, explaining how the Hessian and its eigenvalues characterize the sharpness and structure of local minima and saddle points.

## Key takeaways

- Basin Connectivity and Weight Averaging: Weight averaging works effectively in fine-tuning settings because the resulting models tend to share a basin, moving toward the basin's center. However, in pre-training, models often reside in different basins, leading to nonsensical results when averaged, a discrepancy that ensembling (averaging predictions) does not share.
- The River Valley Phenomenon: Loss landscapes can exhibit a 'river valley' structure where progress is made along a flat 'river direction' while oscillating sharply along 'valley directions.' This hidden progress is often only revealed when the learning rate is annealed (e.g., using WSD), allowing the model to reach the bottom of the valley.
- Critical Points and High Dimensions: Critical points (where the gradient is zero) can be local minima, saddle points, or global minima. In high-dimensional spaces, theoretical analysis suggests that saddle points are far more numerous than local minima, and gradient descent is generally believed to avoid getting stuck in them.
- Hessian and Second-Order Methods: The Hessian (the second derivative of the loss) captures curvature via its eigenvalues. Positive definite matrices correspond to local minima, while indefinite matrices correspond to saddle points. The Gauss-Newton matrix is used as a positive-definite approximation of the Hessian to maintain a well-behaved local quadratic approximation.

## Technical details

- Loss Landscape Models: The three mental models discussed are Basins (connectivity), River Valley (oscillation and progress), and Critical Points (minima vs. saddles). The loss landscape is noted to be highly chaotic and dependent on the training setup.
- Model Soups and Aggregation: Model aggregation methods include: 1) Ensemble (averaging predictions, which almost always helps); 2) Uniform Soup (simple weight averaging); and 3) Greedy Soup (filtering models to improve performance).
- Optimization Algorithms: Newton's method uses the inverse of the Hessian for rapid convergence (1/t^2), but is computationally expensive ($p imes p$ matrix). Preconditioned gradient descent rescales curvature. The Gauss-Newton matrix is a positive-definite approximation of the Hessian.
- Theoretical Guarantees: Theoretical models (like random Gaussian objectives) establish a tight correspondence between the error ($\epsilon$) and the index ($\alpha$, the fraction of negative eigenvalues) at critical points. Low error suggests a minimum (low $\alpha$), while high error suggests a saddle point (high $\alpha$).

## Practical implications

- Understanding the difference between fine-tuning and pre-training is crucial for deciding whether weight averaging is a viable optimization strategy.
- Learning rate schedules (like WSD) are theorized to be necessary to reveal 'hidden progress' made during high-learning-rate oscillation.
- The Gauss-Newton matrix provides a computationally feasible way to approximate the Hessian while maintaining the property that all eigenvalues are positive, preventing unbounded loss improvement regimes.

## Topics

Loss Landscapes, Optimization Theory, Deep Learning, Gradient Descent, Second-Order Methods, Stanford CS312: Deep Learning Alchemy, Model Soups

Source: https://www.youtube.com/watch?v=yYdwC786e1A
