## Introduction to the Edge of Stability Norris: Welcome back to Mechanical Dreams, the podcast where we explore the beautiful, messy, and fascinating gears of machine learning and natural language processing. I am Professor Norris, your resident skeptic, and as always, I am joined by my brilliant student, Linda, who always manages to bring something to the table that challenges my deeply held beliefs. Linda: Hi everyone! I am so excited for today's episode. I brought a paper from ICLR 2021 that completely blew my mind when I first read it. It is called 'Gradient Descent on Neural Networks Typically Occurs at the Edge of Stability' by Jeremy Cohen, Simran Kaur, Yuanzhi Li, J. Zico Kolter, and Ameet Talwalkar. Norris: Now, when you first showed me that title, Linda, I have to admit I chuckled. Gradient descent? Full-batch gradient descent? I thought to myself, did she bring me an optimization paper from the 1990s? Nobody trains modern neural networks with full-batch gradient descent; we all use stochastic gradient descent, or Adam, or some other variant. Why are we looking at full-batch? Linda: I know, I know! It sounds completely counterintuitive for a modern deep learning paper. But the authors make a really compelling point: full-batch gradient descent is the conceptual foundation for all those popular optimization algorithms like SGD. Yet, we actually know surprisingly little about its dynamics in neural network training. By stripping away the noise of mini-batches, they were able to isolate exactly what is happening to the loss landscape during training. And they found two massive surprises that completely contradict prevailing optimization dogma. Norris: Contradicting optimization dogma is exactly the kind of trouble I like to get into on this show. So, let us set the stage for the listeners. What exactly are they measuring as the network trains? Linda: They are measuring something called 'sharpness'. In this paper, sharpness is strictly defined as the maximum eigenvalue of the training loss Hessian. Norris: Right. For our listeners brushing up on their second-order optimization, the Hessian matrix captures the local curvature of the loss function. The maximum eigenvalue essentially represents the direction of steepest curvature in this incredibly high-dimensional parameter space. If you are standing in a valley, the sharpness tells you how steep the walls are right next to you. Linda: Exactly. And conventional optimization wisdom tells us that if you are using a fixed step size, which we will call eta, you need to be careful. For a quadratic objective, if the sharpness ever exceeds the value of 2 divided by eta, gradient descent becomes unstable. The steps are too big for the curvature, and you will oscillate out of control and diverge to infinity. Norris: It makes perfect sense mathematically. If the walls of the valley are too steep and you take a giant leap, you bounce higher up the opposite wall, and eventually, you fly right out of the valley. Linda: But here is the wild part. The authors empirically demonstrate that when you train a neural network, full-batch gradient descent actively seeks out these steep walls. It operates in a regime they call the Edge of Stability. The sharpness of the landscape hovers just above that critical value of 2 over eta. Norris: So it intentionally walks right up to the theoretical limit of divergence, crosses it, and just hangs out there? That violates practically everything I teach in my convex optimization course. Linda: It completely does! In this Edge of Stability regime, the training loss behaves non-monotonically over short timescales. It is bouncing around, spiking up and down, but consistently decreasing over long timescales. It is surfing right on the edge of catastrophe without actually diverging. Norris: That is absolutely fascinating. It sounds like the network is effectively using the instability as a feature rather than a bug. We definitely need to dig into the mechanics of how this happens. Let us unpack exactly how the network gets to this edge in the first place. ## Progressive Sharpening Norris: At the end of our last chapter, I asked how the network gets to this precarious edge. If I initialize my weights in a nice, gentle, flat valley where the curvature is extremely low, shouldn't gradient descent just happily and safely roll to the bottom? Linda: You would certainly hope so! But the authors found the exact opposite. They coined a term for this behavior: 'progressive sharpening'. They observed that as long as the sharpness is small enough for gradient descent to be stable, meaning it is below that critical threshold of 2 over eta, the gradient flow has an overwhelming tendency to continually increase the sharpness. Norris: An overwhelming tendency. That is incredibly counter-intuitive. Gradient descent is entirely blind; it only looks at the local first derivative. It does not look ahead and say, 'I think I will go climb that steep, narrow canyon today.' Why would it actively seek out higher curvature? Linda: That is the million-dollar question, and to be perfectly honest, the authors state outright that they do not know exactly why it happens. But they prove empirically that it is a ubiquitous phenomenon. They tested this across a huge range of architectures. Fully-connected networks, convolutional networks, networks with average pooling, max pooling, ReLUs, Tanh activations. They even tested it on toy 1D regression tasks and natural language Transformers. Across the board, the sharpness just marches upward like a heat-seeking missile targeting that 2 over eta threshold. Norris: That is a robust set of experiments. You cannot just brush that off as an artifact of one specific toy model. But let me put my skeptic's hat back on for a moment. Are there absolutely no exceptions to this rule? Does the sharpness ever go down? Linda: There are actually two really interesting exceptions where progressive sharpening does not hold perfectly. The first one is dependent on the loss function. If you are training a classification task using cross-entropy loss, the sharpness actually drops at the very end of training. Norris: Ah, cross-entropy. Let me think about the math there. With cross-entropy, you are pushing the raw logits through a softmax. Once the network gets most of the examples right, it can keep driving the loss down just by making the correct logits larger and larger, which pushes the classifier margins higher. The probabilities get closer and closer to 1. Linda: Spot on! Because the loss function's second derivative shrinks as the margins get larger, the overall Hessian's maximum eigenvalue gets pulled down. So, right at the terminal phase of training, when accuracy approaches 100 percent, the sharpness dips. But note that this does not happen with Mean Squared Error. With MSE, the sharpness just keeps climbing or plateaus. Norris: Fascinating. The geometry of the loss function itself dictates the final curvature. You mentioned a second exception? Linda: Yes, network width. There is a lot of theoretical work right now on the Neural Tangent Kernel, or NTK, parameterization. Theory says that if you make a network infinitely wide, the Hessian moves a vanishingly small amount during training. The authors tested this empirically by gradually increasing the width of their networks. They found that progressive sharpening occurs to a much lesser degree as networks become increasingly wide. Norris: Right, the NTK regime is essentially convex optimization, so the landscape is practically frozen. But nobody is deploying infinitely wide networks on their edge devices. For standard, practical networks, we are stuck with progressive sharpening. Linda: Exactly. And for those standard networks, the degree of sharpening is dramatic. To see how far the sharpness would rise without the instability getting in the way, they trained a VGG network on CIFAR-10 using gradient flow, which is basically gradient descent with an infinitesimally small step size. Norris: So, simulating continuous time to see the true path without taking discrete, jarring steps. What happened to the sharpness? Linda: It ballooned. It started at a baseline value of about 6.4 at initialization, and it climbed all the way to a peak of 2,227. Norris: Over two thousand? Good grief. That means if you wanted to run a standard, discrete gradient descent that is mathematically guaranteed to be stable, your step size eta would have to be less than 2 divided by 2,227. That is a step size of less than 0.001. Linda: Yes! And they calculated that if you actually trained with that tiny, quote-unquote 'stable' step size, it would take nearly 17,000 iterations to finish. But, if you just use a normal, larger step size, say 0.16, the network still successfully trains in just 329 iterations. Norris: So maintaining strict mathematical stability is actually a terrible strategy. It makes your training 50 times slower! But wait, if they used a step size of 0.16, the stability threshold is 2 divided by 0.16, which is 12.5. If the natural sharpness of the landscape wants to go up to 2,000, what happens when it hits 12.5? Linda: That is exactly the boundary of the Edge of Stability! The sharpness wants to go to 2,000, but the step size acts like an invisible electric fence. It hits 12.5, the network destabilizes, and it is forced to ride that edge for the rest of training. ## Surviving the Edge Norris: Let us pick up right where we left off, Linda. You painted a vivid picture of a network desperately wanting to reach a sharpness of two thousand, but hitting this invisible electric fence at twelve point five because of our chosen step size. What actually happens when it touches the fence? Does it get shocked? Linda: You could certainly say that! The authors call that exact moment the 'breakeven point'. Once the sharpness crosses the two over eta threshold, full-batch gradient descent becomes destabilized. Mathematically, the weights of the network start to oscillate along the direction of greatest curvature, which corresponds to the leading eigenvector of the Hessian. Norris: And according to standard theory, those oscillations should grow exponentially. Every time it bounces back and forth across the valley, it should land higher up the slope than the previous step. That is the textbook definition of divergence. Linda: Exactly. And at first, it looks like that is exactly what is going to happen. The magnitude of the oscillations grows with every step. But initially, these swings are too small to noticeably affect the overall objective function, so the training loss actually continues to go down for a little while. Norris: It is like a car starting to fishtail on an icy road. You are still moving forward, but the back end is swinging wider and wider. Linda: That is a great analogy. Eventually, those swings grow so large that the training loss suddenly spikes upward. But here is the miracle: it does not fly off the road entirely. Instead, the network manages to catch itself. After that initial spike, the loss continues to decrease, just in a very choppy, non-monotonic way. Norris: It catches itself. That defies the quadratic Taylor approximation entirely! If the landscape were a true quadratic bowl, the walls would just keep getting steeper forever, and the network would be launched into infinity. For the network to survive, the actual loss landscape must be fundamentally non-quadratic at that scale. Linda: You hit the nail on the head, Professor. The authors ran a brilliant experiment to prove exactly that. Right when the network enters the Edge of Stability, they took the current weights and swapped the real neural network objective with its local quadratic Taylor approximation. Norris: Oh, let me guess. The quadratic proxy blew up in their faces? Linda: Spectacularly. Within just a few steps, gradient descent on the quadratic approximation diverged to infinity. But gradient descent on the real neural training objective survived and kept making progress. The paper points out that this makes the quadratic Taylor approximation an extremely poor model for local progress once you reach this regime. Norris: So the landscape must be flattening out just enough to keep the iterates contained. Some researchers call this the catapult mechanism, where the network gets launched out of a sharp minimum and lands in a flatter region. Does it just find a flat plateau and stay there? Linda: That is what is so fascinating; it does not just jump to a flat region and relax. It stays locked in a perpetual struggle. It is constantly trying to increase the sharpness due to progressive sharpening, but the moment it inches above two over eta, the instability knocks it back down. So the sharpness just hovers there, right at the limit, for the rest of training. Norris: It is trapped! It is like a thermodynamic equilibrium between the force of progressive sharpening pushing up, and the penalty of divergence pushing down. But how can we be absolutely sure that progressive sharpening is constantly pushing against it? Maybe the network just naturally settled at that curvature? Linda: To prove it is a constant force, the authors did a learning rate drop experiment. They trained a network at a specific step size until it reached the Edge of Stability, and the sharpness flatlined. Then, right in the middle of training, they suddenly cut the step size to a smaller value. Norris: Oh, that is clever. If you drop the step size eta, the stability threshold, which is two divided by eta, instantly goes up. Linda: Exactly! And what do you think happened to the sharpness? Norris: If the network was being artificially held back by the instability, then raising the ceiling should unleash it. The sharpness should immediately start climbing again until it hits the new, higher threshold. Linda: And that is exactly what the data shows. The moment the step size is cut, progressive sharpening resumes. The sharpness shoots up and only stops when it hits the new two over eta boundary. The authors conclude that gradient descent at the Edge of Stability is essentially acting like a constrained optimization algorithm. The step size imposes an implicit constraint on the sharpness. Norris: That is an elegant experiment. It completely re-frames how we think about hyperparameter tuning. We are not just setting a speed limit for our network; we are literally dictating the maximum curvature of the features it is allowed to learn. We are doing implicit regularization just by choosing our step size! ## Shattering Optimization Dogmas Norris: At the end of our last chapter, I had a bit of an existential crisis realizing that choosing a step size is actually a form of implicit regularization. But Linda, if gradient descent is perpetually riding this jagged, bouncing edge of instability... what happens to all our mathematical guarantees? Linda: I hate to be the bearer of bad news, Professor, but they mostly go right out the window. Section 5 of this paper is essentially a graveyard for conventional optimization wisdom. The authors systematically dismantle three major dogmas, starting with the biggest one of all: L-smoothness. Norris: Oh, no. Not L-smoothness. For our listeners who might not spend their weekends reading optimization proofs, L-smoothness is a foundational assumption. It basically assumes there is a strict upper bound on the sharpness, or the curvature, along the optimization trajectory. If you have that bound, you can mathematically guarantee that every single gradient step will decrease your training objective. Linda: Exactly. The weakest form of that guarantee says that if your local sharpness is strictly less than 2 divided by your step size, the loss is guaranteed to go down. But as we just established, practical neural network training does not stay below that limit. Because of progressive sharpening, it slams right into that limit and hovers just above it. Norris: So, by definition, any convergence analysis based on L-smoothness simply does not apply to a neural network trained with a reasonable step size. Because the network actively seeks out a regime where that assumption is violated. Linda: Precisely. The authors point out that it is extremely common for optimization papers motivated by deep learning to analyze algorithms under a 'non-convex but L-smooth' setting. But if even the simplest algorithm, full-batch gradient descent, violates this assumption in practice, the burden of proof really should be on the theorists to justify using L-smoothness at all. Norris: It is like trying to model the aerodynamics of a supersonic jet using equations that only work for a bicycle. It is mathematically elegant, but entirely detached from the reality of the system. I suppose this completely shatters the second dogma too: the idea of monotone descent. Linda: It does! We all know that Stochastic Gradient Descent is noisy, so the loss jumps around due to the randomness of the mini-batches. But it has always been a widespread assumption that if we theoretically had infinite compute and could run full-batch gradient descent on a neural network, the training loss would smoothly and monotonically slide down to the minimum. Norris: Right, a nice, clean, descending curve. But the Edge of Stability proves that is a fantasy. Because the network is surfing that threshold of instability, the loss behaves non-monotonically over short timescales. It spikes, it stumbles, it chops around. Linda: It is constantly taking steps that actually increase the training objective locally, even though it consistently decreases the objective over the long haul. Norris: It is like a drunk person walking down a steep hill. Every individual step might be a stumble backwards or sideways, but gravity eventually wins. Linda: I love that analogy! But the biggest shocker for me was how this paper demolishes the third dogma: the classic heuristic for setting the 'optimal' step size. Norris: Ah, you mean the golden rule from the 90s. Yann LeCun and others championed this. The theory goes that if you somehow magically know the exact local sharpness, which we will call lambda, you should set your step size to exactly 1 over lambda. That dynamically maximizes the guaranteed decrease in your objective. Linda: Right. It is computationally impractical to calculate the Hessian at every step, but it has always been viewed as the theoretical ideal. Well, the authors actually ran an experiment where they forced the network to use that 'ideal' dynamic step size of 1 over the current sharpness. Norris: Wait. Let me think this through. If the step size is 1 over the sharpness, and progressive sharpening means the sharpness is constantly increasing... Linda: You see it! The step size continuously shrinks. Because the step size rule constantly adapts to avoid instability, it effectively anneals itself into taking smaller and smaller steps. Norris: So it safely, monotonically crawls to a halt. How did that compare to just using a normal, fixed step size? Linda: The fixed step size absolutely crushed the dynamic one! The authors compared the dynamic rule to a theoretically 'impermissible' fixed step size based on the initialization sharpness. The fixed step size quickly became unstable, entered the Edge of Stability, started bouncing around, and reached the target accuracy orders of magnitude faster. Norris: That is a beautiful irony. The mathematically 'optimal' path is practically useless, while the unstable, impermissible path gets the job done. The non-monotonicity, the bouncing, the instability... it is literally the price we pay for the ability to take large steps and train networks in a reasonable amount of time. Linda: Exactly. We trade theoretical safety for sheer speed. The Edge of Stability is not a bug we need to fix with better step-size schedules; it is the fundamental mechanism that makes efficient neural network training possible. Norris: I am going to have to rewrite half of my lecture notes for next semester. But Linda, there is still one massive elephant in the room that we need to address before we wrap up today. ## What About SGD? Norris: You left us on quite the cliffhanger, Linda. We have spent this entire episode dismantling optimization dogmas based on the Edge of Stability. But the elephant in the room is that nobody actually trains modern, massive neural networks with full-batch gradient descent. We all use Stochastic Gradient Descent, taking noisy steps with mini-batches. Does this Edge of Stability even apply to SGD? Linda: That is the million-dollar question, and the authors are very upfront about it. The precise mathematical characterization we discussed, where the sharpness hovers exactly at two over eta, strictly applies to full-batch gradient descent. In SGD, the sharpness does not flatline at a neat, mathematically predictable value. Norris: That makes intuitive sense. The stochastic noise from sampling mini-batches acts as its own source of turbulence. You are not just fighting the curvature of the landscape; you are fighting the variance of your data batches. But does the underlying intuition of the Edge of Stability carry over? Linda: It absolutely does! Prior works, as well as the experiments in this paper's appendix, show that in SGD, the trajectory of sharpness is heavily influenced by your hyperparameters. Specifically, using a large learning rate or a small batch size steers the network into flatter regions of the landscape with lower sharpness. Norris: Ah, so instead of hitting a hard, mathematical wall at two over eta, SGD sort of acclimates to the noise and the step size. It finds a balance between the progressive sharpening and the stochastic turbulence. Linda: Exactly. The authors ran a really cool experiment where they tracked the expected change in the loss during SGD. They found that SGD navigates to regions where taking a step with the current hyperparameters will sometimes increase and sometimes decrease the loss in expectation. It is surfing a much noisier edge. Norris: But let me guess, if you were to suddenly drop the learning rate or increase the batch size in that region, the loss would consistently decrease again? Linda: You guessed it! It proves that SGD is still pushing itself into the sharpest valleys it can survive in, given the specific turbulence of the batch size and step size we set. Norris: This completely redefines how we should view hyperparameters in deep learning. They are not just tuning knobs for how fast we want to converge. They actively shape the geometry of the final solution. A larger step size forces the network to find flatter, potentially more generalizable minima simply because it cannot survive the sharp ones. Linda: Exactly. The Edge of Stability intuition holds, it just manifests differently when you add stochasticity. It is a paradigm-shifting way to think about what our algorithms are actually doing under the hood. Norris: I have to admit, I came into this episode highly skeptical of a full-batch gradient descent paper in 2021, but I am leaving with a completely new mental model of neural network optimization. We are not gracefully sliding down smooth convex hills; we are violently bouncing down jagged canyons, surviving right on the edge of catastrophe. Linda: And that bouncing is exactly what makes the magic happen! Thank you so much for exploring this paper with me, Professor. And thank you to all our listeners for tuning in to Mechanical Dreams. We will be back next week with another paper. Norris: Until then, keep dreaming, everyone!