Interactive figures
Every figure in the track. Each one is a small experiment: drag, slide, and watch the numbers. The link under each figure takes you to the lesson that explains it.
Lesson 1 · Loss surfaces and gradient descent
Drag the violet point and the small grey handle . The violet curve is the level set through the point, the orange arrow is and the blue arrow is , the direction gradient descent takes. Notice that the gradient always crosses the level set at a right angle, so in the narrow valley it points mostly across the valley, not toward the minimum (the black star). Turn and watch : it is largest along and zero along the level set.
Predict, then play. Set with the slider, choose your prediction, then press Play. The blue arrows are the gradient-descent steps on the parabola; the chart on the right shows against . Try , , , and .
Drag the blue start point and change the step. The slider gives in units of , where is the largest curvature (here ). The blue path is gradient descent; the chart shows on a log scale, with the theory bound dashed. Use the Try buttons: "too small" crawls, "best" uses , "just above " diverges in the steep direction. Then raise , and switch to the rotated quadratic: the valley no longer follows an axis, and the picture is the same.
Click the chart or move the slider to pick . The blue curve is the loss after 50 steps, , for every step size, from the same start . It is flat for tiny , has its lowest point near the best step (grey dashed line), and then rises sharply at the stability limit (yellow line). The small contour plot shows the chosen run. Switch : the cliff moves with , and the good region gets narrower as grows.
Lesson 2 · Convexity, smoothness, conditioning
Drag the violet chord ends , and the aqua tangent point . Where the chord lies below the graph, or the graph falls below the tangent, the gap is shaded magenta. For the double well both tests fail for some choices. For , the logistic loss and no choice fails: they are convex. For the chord test passes everywhere, but at there is no tangent line (no derivative), only many supporting lines.
Drag the point on the graph and move the sliders and . The orange parabola has curvature , the blue parabola curvature ; both touch at the point. Where leaves the band, the gap is shaded magenta. For , find the smallest and the largest that work at every point (answer: , ). Then try : whatever you choose, some point far out breaks the upper bound.
Move the eigenvalues , and the angle . The blue ellipses are level sets of ; read , , and the axis ratio in the panel. Think of as , the covariance of two centered features. Press Standardize the features: the aqua dashed ellipses show the loss after each feature is divided by its standard deviation. With they are circles (). With nothing changes: the features are correlated, and rescaling each feature alone cannot remove a correlation.
Switch between bowl, trough and saddle, and rotate the figure. A convex quadratic is a bowl (both eigenvalues of positive: strongly convex) or a trough (one eigenvalue zero: convex, not strongly convex). The saddle has one negative eigenvalue: not convex.
Move along the segment from () to (). The two ends compute the same function and have loss 0. The violet curve is the loss along the segment; a convex loss would stay on or below the dashed chord, here at 0. In the two-unit tanh network the midpoint has equal hidden units whose output weights cancel, so it outputs 0 everywhere. Switch to to see the segment leave the set of minimizers (aqua).
Lesson 3 · GD rates and line search
Press Play, then try the three presets (the slider is the step in units of ). The contours belong to with and ; the dashed lines are the eigen-directions (flat) and (steep). The blue path is gradient descent. The bars show the two error components with their sign. With the steep component dies in one step, and the flat one shrinks by only per step. With the steep component flips sign at every step (zig-zag). On the log chart, the blue curve always ends up parallel to the slower dashed line.
Drag on the chart to move the step size (or use the slider , the step in units of ). The aqua V is , the magenta V is , and the thick dark curve is their maximum . Above the dashed line there is no convergence: this starts at the yellow line . The lowest point of the thick curve is the best step . Change and : the best factor depends only on .
Press Next trial to run backtracking one trial at a time. The black curve is , the grey dashed line is the tangent at 0, and the yellow line is the Armijo line. The violet circles are the trials ; the filled one is accepted. The bands below show where Armijo holds, where the curvature condition holds, and where both hold (the Wolfe set); is the curvature constant defined below. Try the wavy slice: the Wolfe set has several pieces. Move toward 0.5 and see the Armijo set shrink.
Compare the fixed step (blue) with Armijo backtracking (violet, dashed), both started at . Try the three presets for . With , just above at the minimizer, the fixed step never settles: it stays near the minimizer and bounces across the valley. Look at the long violet jump: with , backtracking sometimes accepts a long step across the bend of the valley, because it lowers enough. Then switch to "2 × last step" and compare the number of function evaluations.
Lesson 4 · Momentum and Nesterov
Press Play and watch the three paths: gradient descent (blue), heavy ball (orange) and Nesterov (violet), each with its theory parameters. The chart shows ; the dashed lines are the theory factors . Heavy ball first overshoots far across the valley, then wins by a wide margin. Increase and see the gap grow. With same η and β all three share one step (the slider is the step in units of ) and one . Then choose Rosenbrock: heavy ball with the parameters that are best near the minimizer diverges, while Nesterov converges.
Move and , or use the presets. The orange dots are the heavy-ball iterates , the faint blue line is gradient descent with the same , and the dashed lines are , where is the size of the largest root. In the under-damped case the roots are complex and their size is exactly , whatever is. Find the critically damped point for : it is at .
The roots in the complex plane. For many eigenvalues between and , the figure draws both roots of as orange dots. The solid circle is the unit circle (outside it: divergence); the dashed circle has radius . With Polyak's parameters every root lies on the dashed circle. Make smaller: the roots for near leave the circle along the real axis, and the largest root size grows. Press β = 0 to see plain gradient descent, whose roots all lie on the real axis.
Steps against , on log-log axes. Move the marker. Gradient descent (best step) lies on a line of slope 1: steps . Heavy ball and Nesterov lie on lines of slope : steps . The dashed lines are the formulas and . Conjugate gradient (grey) is never worse than heavy ball and is often better, because it adapts to the actual eigenvalues (folded part at the end of section 3).
Lesson 5 · SGD and batch size
Drag the blue point from the right into the shaded region. Each arrow is the step direction of one example: blue if it agrees with the full step (thick dark arrow), magenta if it points the other way. Outside the data range all arrows agree. Inside, they disagree, and the full step becomes short. The chart below runs SGD with one random example per step from the current : it moves fast at first, then jumps around inside the dashed band (derived in section 3).
Many SGD runs from one start. Each faint blue line is one SGD run; the dark line is gradient descent with the same step. Press Play. The runs first follow gradient descent, then stop in a cloud: the noise ball. Change the step and the batch and watch the cloud size: it scales like . The yellow dashed circle has the radius of the bound ; the dotted dark circle has the radius , where is the exact floor. Then choose decaying: the cloud keeps shrinking.
Move the batch size and watch the two costs. The blue curve is the number of steps ; the violet curve is the number of examples . Below (yellow line) the steps fall almost like the dashed line of perfect linear scaling, at almost no extra cost in examples. Above it, the steps flatten and the examples grow. Change : the whole picture slides along the axis.
Count work, not steps. Least squares with and . The x-axis is the number of example gradients. Gradient descent (dark, one dot per pass) needs a full pass for one step; minibatch SGD makes progress after a few hundred examples, then stops at its noise floor. Switch from 10,000 to 100,000: the GD curve moves right by a factor of 10, the SGD curve does not move. Choose decaying to see SGD go below its floor, slowly. The yellow line marks one pass.
Lesson 6 · AdaGrad, RMSProp, Adam, AdamW
Slide and watch the two averages of the noisy gradients (grey dots). The orange EMA without correction starts near 0 and needs about steps to catch up; the aqua corrected average is right from the first step. With jump at t = 50, a large reacts slowly: long memory means smooth but late. The bars show the weight of each past gradient in the last average; the dashed line marks steps back.
Race four optimizers. Gradient descent (blue), momentum (orange), RMSProp (aqua, dashed) and Adam (aqua, solid) start from the same point (drag it). On the axis-aligned quadratic, Adam and RMSProp go almost straight to the minimum. Switch to rotated 45°: with the same learning rates they lose their advantage and stall, while gradient descent is unchanged. Then try the saddle (Adam escapes in a few steps, because it rescales the tiny gradient along ), Rosenbrock and the double well, and turn on gradient noise. Each optimizer has its own learning-rate slider; Default learning rates resets them.
Type a gradient (or pick an example) and read the first three steps of each method, in units of . SGD copies the gradient: steps of and . RMSProp (light aqua) starts with ; Adam without correction (grey) starts with about ; Adam (aqua) moves by in both coordinates. With (100, 0.01), then flip, the coordinate whose sign flips moves back by only 5% of . Set to see Adam lose its adaptivity.
Two groups of weights, no reason to move. All weights start at 1 and see zero-mean gradient noise: group A with RMS 10 (solid lines), group B with a smaller RMS (dashed). Only the decay moves them on average. With AdamW (aqua) both groups shrink alike, like . With Adam + L2 (magenta), group A barely shrinks and group B shrinks fast, like . Change the RMS of group B and the decay .
Lesson 7 · Schedules, warmup and clipping
Move the step slider and read for each schedule: warmup + cosine (violet), WSD with a linear (orange) or a 1−sqrt (orange, dashed) cooldown, linear decay (aqua) and step decay (magenta). Change the cooldown length : only the WSD curves move. Then press Plan 2T, stop at T: the cosine planned for twice the length (violet, dotted) is still at about half the peak when you stop.
Compare the curves. All runs first fall to the same plateau: the noise ball for . The constant run stays there. The WSD runs stay there too, until the cooldown starts (dashed line), and then drop fast. The cosine run decays slowly from the start. The cosine planned for and stopped at (violet, dotted) is still high. Set σ = 0 (no noise): now the constant learning rate ends lowest, because decay only slows progress when there is no noise to remove.
Change the threshold and the step size . Plain gradient descent (blue) jumps from side to side with growing size. Clipped gradient descent (aqua) moves by at most per step. Clipping acts only inside the yellow band, where . The dashed lines mark where the local curvature equals ; outside them a plain step overshoots.
Run the test on a least-squares problem. The smoothed loss falls, reaches a minimum and blows up. The yellow dashed line is , the stability limit of full-batch gradient descent on this problem. The blow-up comes a little later, because divergence needs a few steps to show and the moving average lags. Switch the features to the same scale: drops and the whole curve moves right.
Lesson 8 · Lagrange multipliers, KKT, duality
Drag the black point along the yellow constraint curve and find where is smallest. The blue arrow is the direction of , the yellow arrow the direction of , and the magenta arrow the downhill direction along the curve. The dashed blue curve is the level set of through the point. At the minimum the magenta arrow vanishes, the angle between the gradients is or , and the dashed level set touches the curve. The chart shows along the curve. Try the circle: it has a minimum and a maximum, and both satisfy the condition.
Move the slider to walk along the lifted curve, and drag the figure to rotate it. The blue surface is ; the yellow curve on the floor is the constraint, and the vertical lines connect it to its lift. The bottom of the bowl, , is not on the curve. Press Go to the lowest point: for the line, it is with , the same answer as the calculation above.
Move to slide the constraint line. The left plot shows the contours of and the constrained minimizer ; the right plot shows the optimal value (black) and its tangent line, whose slope is . For the inequality , the multiplier is at and becomes 0 when : then the unconstrained minimizer is feasible and the constraint costs nothing. Switch to the equality to see a multiplier that changes sign.
Drag the blue point , the unconstrained minimizer of , inside and outside the yellow feasible set . Inside, and . Outside, (black star) is on the boundary, and the push of the wall (yellow arrow) cancels the pull of , (blue arrow). The four KKT conditions are listed with ticks. In the mode choose λ yourself, the orange point minimizes for your : too small and it is infeasible, too large and complementary slackness fails.
Move . Each thin line is for one fixed : yellow for feasible (slope ), grey for infeasible . Their lower envelope is the dual function (thick blue), and the orange line belongs to the that attains the minimum. The blue dot never rises above the dashed line . In the convex problem the best bound reaches at . In the nonconvex problem the best bound is while : a gap of 2.
Lesson 9 · Proximal methods and ADMM
Move and . Left: the two parts of the prox objective, (violet) and (blue, dashed), and their sum (black). The orange point is the minimizer . Right: the prox map with the identity dashed. For , the yellow dead zone is sent to exactly 0: the kink at 0 holds the minimizer there. For the map is a line through 0 with slope ; for the indicator it is a clip.
Drag the blue start point and press Play. Each step is a gradient step (blue, dashed), which may leave the set, followed by a projection back onto the yellow set . The iterates reach the boundary and then slide along it to the constrained minimizer (black star). The grey star is the unconstrained minimizer, outside . At , (grey arrow) points straight out of : no feasible direction goes downhill. Try the disc, and a step above 2.
Drag the start point, move , and press Play. ISTA (blue) and FISTA (violet) minimize a 2D lasso whose contours (grey) have kinks on the axes. At the minimizer is : both methods reach exactly after a finite number of steps. FISTA overshoots past and its curve in the chart goes up and down, but it ends far ahead of ISTA. The dashed lines are the two worst-case bounds. The worked example has ; there acceleration helps little.
Move and watch which coefficients are exactly 0. The curves (colours 1, 2, 3, 4, 5) are the lasso coefficients of a small data set (20 samples, 5 standardized features), computed in your browser by coordinate descent. Right of all are 0. Coefficient 3 enters first, grows, shrinks, is exactly 0 again for between about and , and then turns negative: a coefficient can leave the model when correlated features take over.
Lesson 10 · Newton, BFGS and Gauss–Newton
Press Step several times. The grey curve is ; the dashed magenta parabola is the local model at the current point, and the step goes to its stationary point. On from , the log chart of falls faster and faster: the exponent doubles (quadratic convergence). Then try the presets. From the curvature is tiny and the jump goes far away. On the double well from the curvature is negative: the model opens downward and pure Newton moves towards the maximum at 0. Switch to "damped" to see the fixes of section 3.
Drag the point in the left plot. On the left are the elliptic level sets of . The blue arrow is a gradient step : it is perpendicular to the level set, so it does not point at the minimum. The magenta arrow is the Newton step: it points straight at the minimum. On the right the same point is drawn in the coordinates ; the grey grid is the left grid after the change of variables. The level sets are circles, and the gradient step is the magenta arrow again. Set : both arrows on the left point the same way.
Pick a surface, then drag the large start dot. Blue: gradient descent (best fixed step on the quadratic, backtracking elsewhere). Magenta: pure Newton. Violet: damped Newton. Dashed magenta: BFGS. On the rotated quadratic, Newton needs one step for every , while gradient descent needs more steps as grows. On Rosenbrock, pure Newton needs 6 steps and gradient descent about 19,000. On the double well from the default start, pure Newton stops at the saddle point : the Hessian there is not positive definite. Damped Newton (which also fixes negative curvature) and BFGS reach a minimum.
Press Step twice. Left: BFGS with exact line searches on , from the slider, starting from . Right: the ellipse of the current estimate (magenta) and of the true inverse Hessian (dashed). After one step the two ellipses pass through the same point (orange arrow, ): this is the secant condition. After two steps the ellipses coincide and .
Press Step, then try the presets. We fit to 9 data points. Left: contours of with the paths of Gauss–Newton (magenta) and Levenberg–Marquardt (violet, adaptive ). Right: the data and the current fits, and on a log scale. With small residuals both methods converge in a few steps. "Start far away" (): the first Gauss–Newton step jumps to and the fit explodes, while LM rejects bad steps, increases and converges. "Large residuals" (data that no decaying exponential fits well): the dropped term is no longer small, and the log chart shows a slower, linear rate. Choose "fixed " and move the slider: a huge gives tiny gradient steps.
Lesson 11 · Saddles, sharpness and stability
Rotate the surface by dragging it. The surface is aqua where is above and magenta where it is below. The orange and blue curves follow the eigenvectors and of the Hessian. Use the presets for a minimum, a maximum and a saddle. Then set , and try the degenerate functions (a minimum) and (not a minimum): both have the same Hessian at the origin, so the Hessian alone cannot tell them apart.
Make the offset smaller. The gradient-descent path comes closer to the saddle (the cross) and stays near it longer, but it still escapes. The chart shows on a log scale: a straight line with slope , next to the linear estimate (dashed). Each factor 10 in adds the same number of steps. Press δ = 0 exactly: now GD converges to the saddle. Add noise and it escapes again. Show Newton: Newton's method (magenta) jumps to the saddle. Switch to the double well to see the same on a function with two minima.
Press "One HVP" a few times. The blue vector turns toward the eigenvector (yellow dashed line); the orange vector is , the only thing the method computes. The dashed ellipse is the image of the unit circle under . The chart shows the error of next to (dashed). Try close eigenvalues: convergence slows down. Try near a saddle: the iteration finds , not .
Compare three step sizes. A small network (97 parameters) is trained with full-batch GD on 20 points, from the same start. The bottom chart shows the sharpness and the line . With the sharpness rises (progressive sharpening) and stays below the line. With or it rises to and stays there, while the loss (top) has small up-and-down steps but keeps decreasing.
Change the radius . The loss (grey) has a deeper sharp minimum on the left and a flat one on the right. The dashed violet curve is the exact SAM objective: the worst loss in the yellow ball around each point. For it is the loss. As grows, the narrow well is filled first, and the table shows that the SAM objective becomes lower at the flat minimum. Drag the point : the arrows below the axis compare the GD step and the SAM step, which uses the gradient at the ascent point .
Lesson 12 · K-FAC, Shampoo and Muon
Drag the tip of . The three shaded shapes are unit balls: the circle (), the square () and the diamond (). Each arrow is the point of its ball where is most negative. Choose one norm under "Show": the dashed line is the level line , and it touches the ball exactly at the steepest point. Its distance from the origin gives the dual norm . Try : the steepest step is no longer unique.
Move the sliders, then try the presets. The dashed circle is the set of unit inputs, with the input directions (grey arrows). The blue ellipse is its image under the gradient (drawn with ): the blue arrows have lengths and . The magenta circle is the image under : the same directions , both of length 1. With "" the blue ellipse is almost a line, but the orthogonalized step still moves the weak direction fully. "Muon (5 steps)" shows the dashed result of Muon's iteration: close to the circle, but not exactly on it.
Move the slider from 1 example to 2, then to many. A tiny linear layer with 2 inputs and 2 outputs has 4 weights, so its Fisher block is . Left: the exact , the mean of over examples. Right: K-FAC's from the same examples. Blue entries are positive, orange ones negative; the thick lines show the blocks (block of is ). With one example the two maps are equal. With independent and the error shrinks as grows (with some noise). When depends on , the error stays at about 0.6 for every large .
Move and switch the polynomial. The large chart shows the map after steps (magenta; earlier faint), on a log scale of the starting singular value. The small chart follows five starting values over the steps. With the cubic, values near 1 converge very fast but needs many steps. With the quintic, every value from 0.001 to 1 enters the band between the yellow lines within about 6 steps, and then keeps moving inside it.