Key Moments

Sharpness, Edge of Stability & Flat Minima | Stanford CS312 Lecture 6 with Suhas Kotha

Stanford OnlineStanford Online
Education5 min read72 min video
Nov 30, 2026|3,747 views|30|1
Save to Pod
TL;DR

Neural network training mysteriously stabilizes at the 'edge of stability' instead of exploding, suggesting our standard optimization theories are incomplete.

Key Insights

1

Standard gradient descent theory predicts divergence when sharpness exceeds 2/learning rate, yet deep learning training often self-stabilizes around this threshold.

2

The 'central flow' framework, incorporating third-order Taylor expansions, better predicts training dynamics by accounting for a 'sharpness regulation' term.

3

Momentum's effect on sharpness differs drastically between full-batch (increases threshold) and mini-batch (decreases threshold) training, with noise dominating the latter.

4

Adaptive optimizers like RMSprop use a second force, related to gradient variance, to stabilize training and reduce effective sharpness, in addition to standard sharpness regularization.

5

Sharpness-Aware Minimization (SAM) aims to find flat minima by optimizing for worst-case loss in a neighborhood, showing benefits in generalization and robustness to noisy labels.

6

The exact reason for 'gradual sharpening' (why models naturally seek sharper minima) remains an open research question, despite its practical implications.

The 'edge of stability' phenomenon defies standard optimization theory

Traditional optimization theory, based on quadratic approximations of loss landscapes, suggests that if the sharpness of the loss function (related to the Hessian's eigenvalues) exceeds a certain threshold (specifically, 2 divided by the learning rate, or 2/eta), training should diverge. This threshold is determined by the maximum eigenvalue of the Hessian. However, empirical observations in deep learning show that training doesn't typically explode. Instead, training loss decreases slowly, sharpness increases, potentially crosses this instability threshold, but then mysteriously decreases again, with oscillations also subsiding. The training process then stabilizes around this 'edge of stability' (around 2/eta), rather than diverging. This self-stabilizing property is a key observation that standard gradient descent theory fails to explain. Different learning rates result in sharpness stabilizing at different, but related, thresholds (e.g., 2/eta).

Central flow provides a more accurate model of training dynamics

To better model these observed training dynamics, researchers have introduced the 'central flow' framework. Unlike traditional analyses that rely on second-order Taylor expansions (which behave like quadratic approximations), central flow incorporates third-order terms. This addition introduces a 'sharpness regulation' term into the differential equations governing weight updates. This term effectively acts to reduce sharpness during training. By considering this third-order term and averaging over oscillations, the central flow model can predict that sharpness will stabilize rather than diverge. This framework helps explain why, despite exceeding the theoretical instability threshold, training remains stable and converges. The central flow approach accounts for the dynamics that pull the system away from simple quadratic behavior.

Momentum's impact on sharpness varies with batch size

The interaction between optimizers and sharpness is complex. For full-batch gradient descent, momentum tends to increase the effective learning rate's bound, thus increasing the sharpness threshold at which instability occurs. The effective learning rate becomes approximately eta / (1 + beta), and the sharpness threshold scales with (1 + beta). However, in the mini-batch setting, where noise dominates, the effect is reversed. Gradients become noisy, and the accumulated gradient is scaled by 1 / (1 - beta). This leads to a lower sharpness threshold. In essence, momentum amplifies the effective learning rate in full-batch settings, pushing the stability threshold higher, while in noisy mini-batch settings, it effectively amplifies noise and reduces the stability threshold.

Adaptive optimizers like RMSprop introduce new stabilization forces

Adaptive optimizers, such as RMSprop, introduce additional mechanisms for stabilizing training. Standard RMSprop normalizes gradients by the square root of the moving average of squared gradients ('mu'). This creates an 'effective learning rate' (eta / sqrt(mu)) and an 'effective sharpness'. While the effective sharpness tends to stabilize around 2, the actual sharpness can continue to increase. RMSprop introduces a second stabilizing force: as oscillations increase, 'mu' grows, which in turn reduces the effective learning rate and indirectly influences sharpness. This duality—adapting to the landscape's curvature and actively regulating sharpness—is key. Experiments show that increasing the beta_2 parameter (which controls the EMA of squared gradients) slows down the increase of 'mu', leading to longer stabilization times for effective sharpness but potentially lower final sharpness.

Sharpness-Aware Minimization (SAM) promotes flatter minima

Sharpness-Aware Minimization (SAM) is an algorithm designed to directly optimize for flatter minima. Instead of minimizing the loss at the current weights, SAM seeks weights that achieve good loss over a small neighborhood. This is mathematically achieved by finding the 'worst-case' loss within a small radius around the current weights and then performing a gradient update based on that worst-case loss. The intuition is that if a region around your weights has a consistently low loss, you are in a flat minimum, which is believed to generalize better. Empirical results show SAM can improve performance, particularly on tasks with noisy labels or when fine-tuning pre-trained models, leading to less catastrophic forgetting.

The complex and sometimes contradictory role of sharpness in generalization

The relationship between sharpness and generalization is not straightforward. While a common intuition is that flatter minima generalize better than sharper ones, empirical evidence is mixed. Some studies show a negative correlation (sharper minima generalize better), while others find positive correlations. The issue is compounded by the fact that sharpness is sensitive to how the model's parameters are set, making it a difficult metric to interpret definitively. Despite the ambiguity, flatter regions are often associated with more robust training and better performance during fine-tuning. SAM attempts to leverage this by seeking flatter regions, though the precise mechanism by which it achieves its benefits is still debated, with some research suggesting it might be optimizing average perturbation rather than worst-case perturbation in certain settings.

Open questions and practical implications

Several aspects of sharpness remain open research questions. The fundamental reason for 'gradual sharpening'—why models naturally tend towards sharper minima—is not fully understood and is likened to a 'magical property' of deep learning. Furthermore, existing analyses primarily apply to mean squared error loss and full-batch gradient descent; extending them to cross-entropy loss and mini-batch settings with modern optimizers like Adam is an ongoing challenge. While sharpness can accelerate convergence and potentially improve generalization, directly controlling it is difficult. Current methods involve indirect approaches like adjusting learning rates or batch sizes. SAM offers a direct optimization approach, but its theoretical underpinnings are still being refined, highlighting the dynamic and evolving nature of deep learning research.

Optimizing Deep Learning Models: Key Takeaways

Practical takeaways from this episode

Do This

Understand that sharpness (related to the Hessian's maximum eigenvalue) impacts learning rate stability.
Be aware that deep learning models exhibit self-stabilization properties, unlike simple quadratic models, where sharpness often decreases after exceeding a threshold.
Utilize tools like Central Flow, which considers third-order Taylor expansions, to better track optimization dynamics beyond simple gradient flow.
Understand that momentum's effect on sharpness differs between full-batch (increases threshold) and mini-batch (decreases threshold) scenarios.
Recognize that adaptive optimizers like RMSprop introduce a second force for stabilization by adjusting the effective step size based on gradient norms.
Consider that flatter minima might correlate with better generalization, though this is not always guaranteed and depends on how the model's parameters are defined.
Explore algorithms like SAM (Sharpness-Aware Minimization) to directly optimize for flatter regions in the loss landscape, potentially improving generalization and robustness.

Avoid This

Do not assume that standard quadratic optimization intuition (e.g., divergence above a certain learning rate) fully applies to deep learning.
Avoid relying solely on gradient flow for predicting model behavior once the optimization reaches a critical or unstable region.
Do not overlook the complex interactions between optimizers (momentum, adaptive methods) and sharpness.
Be cautious about directly equating sharpness with generalization ability, as research shows conflicting results and the definition of sharpness can be parameter-dependent.
Do not solely rely on pre-training loss as a predictor for downstream task performance; consider sharpness and fine-tuning dynamics.
Be wary of over-reliance on the 'flat minima generalize better' heuristic, as counterexamples exist where sharp minima generalize well.

Common Questions

Sharpness refers to the curvature of the loss landscape, typically related to the maximum eigenvalue of the Hessian matrix. High sharpness means the loss increases rapidly in certain directions, while low sharpness (flatness) means the loss changes more gradually.

Topics

Mentioned in this video

More from Stanford Online

View all 203 summaries

Ask anything from this episode.

Save it, chat with it, and connect it to Claude or ChatGPT. Get cited answers from the actual content — and build your own knowledge base of every podcast and video you care about.

Get Started Free