{"course":{"slug":"maths-you-need","title":"The Maths You Actually Need","url":"https://addaly.com/learn/maths-you-need","level":"intermediate","track":"deep"},"lesson":{"slug":"curvature-momentum-and-adam","title":"Curvature, and what the optimisers are actually doing","url":"https://addaly.com/learn/maths-you-need/curvature-momentum-and-adam","position":25,"of":76,"minutes":10,"answer":"The ratio between the steepest and shallowest curvature decides how badly plain gradient descent zigzags, and momentum and Adam are two cheap ways of compensating without ever computing that curvature.","keyIdea":"The ratio between the steepest and shallowest curvature decides how badly plain gradient descent zigzags, and momentum and Adam are two cheap ways of compensating without ever computing that curvature."},"body":{"format":"markdown","text":"## The second derivative, in one line\n\nThe first derivative says which way is downhill. The second says how the slope itself is changing: whether the surface curves sharply or gently. In many dimensions the second derivatives form a matrix called the Hessian, one entry for every pair of parameters.\n\nYou will never compute a Hessian for a real model. For 7 billion parameters it would have 49 × 10^18 entries. But you need one number from it, and it is the one that explains most optimisation trouble.\n\n## The number that explains the zigzag\n\nThe Hessian's eigenvalues are the curvatures along its eigen-directions. The ratio of the largest to the smallest is the condition number, and it decides how gradient descent behaves.\n\nTake a simple quadratic bowl with curvature 100 along one axis and 1 along another: condition number 100. Gradient descent must use a learning rate small enough not to diverge along the steep axis, roughly `2/100 = 0.02`. But along the shallow axis, a step of 0.02 makes progress at rate `0.02 × 1`, so covering that direction takes about 100 times as many steps as the steep one.\n\nThat is the zigzag: fast oscillation across the narrow direction, crawling progress along the long one. The number of steps needed scales roughly with the condition number, and real loss surfaces have condition numbers in the thousands.\n\n## Momentum: remembering where you were going\n\nThe fix costs one extra buffer. Instead of stepping along the current gradient, keep a running average of recent gradients and step along that.\n\n```\nv  <-  beta * v + grad\nw  <-  w - learning_rate * v\n```\n\nwith `beta` typically 0.9.\n\nWhy it works is worth seeing concretely. Along the narrow direction the gradient alternates sign each step, so successive terms in the running average cancel. Along the long direction the gradient points the same way every step, so they accumulate. With `beta = 0.9` the accumulated step approaches `1/(1 − 0.9) = 10` times a single gradient. The consistent direction gets amplified tenfold and the oscillating one gets damped: precisely the correction the geometry needed.\n\n## Adam: a different step size per parameter\n\nAdam adds a second idea. Track not just the average gradient but the average *squared* gradient, per parameter, and divide by its square root:\n\n```\nm <- beta1 * m + (1 - beta1) * grad          (average gradient)\nv <- beta2 * v + (1 - beta2) * grad^2        (average squared gradient)\nm_hat = m / (1 - beta1^t)                    (bias correction)\nv_hat = v / (1 - beta2^t)\nw <- w - lr * m_hat / (sqrt(v_hat) + eps)\n```\n\nDefaults: `beta1 = 0.9`, `beta2 = 0.999`, `eps = 1e-8`.\n\nThe division is the substance. A parameter whose gradients are consistently large gets a large `v`, so its effective step is scaled down; a parameter with small gradients gets scaled up. Each parameter ends up with its own step size, adapted automatically. That is a crude, cheap, diagonal-only substitute for using the curvature.\n\n**Bias correction is not decoration.** Both `m` and `v` start at zero, so early estimates are biased towards zero. At step 1 with `beta2 = 0.999`, the raw `v` is 0.001 times the true squared gradient; dividing by `1 − 0.999^1 = 0.001` restores it. Without this the first few hundred steps take wildly wrong step sizes, which shows up as an unstable start and is the reason warmup helps.\n\n## What it costs\n\nAdam stores two extra numbers per parameter. For 7 billion parameters in 32-bit:\n\n```\nweights   :  7e9 * 4  = 28 GB\ngradients :  7e9 * 4  = 28 GB\nAdam m    :  7e9 * 4  = 28 GB\nAdam v    :  7e9 * 4  = 28 GB\n                        112 GB, before a single activation\n```\n\nThis is the arithmetic behind the familiar claim that full fine-tuning of a 7B model needs far more memory than you would guess from its size, and behind the popularity of memory-efficient variants: 8-bit Adam quantises the two states, and SGD with momentum keeps only one.\n\n## Reading a loss curve for which problem you have\n\nThree patterns, three causes:\n\n- **Loss spikes to NaN early.** The learning rate exceeds the stability limit for the steepest curvature. Lower it, or add warmup so the first steps are small.\n- **Loss decreases very slowly and smoothly.** The learning rate is too small, or the problem is badly conditioned. Try raising the rate first; it is one experiment.\n- **Loss falls then plateaus while the gradient norm stays high.** Oscillation across a narrow valley. A learning-rate decay usually breaks it, which is the main reason cosine schedules are the default.\n\nLog the gradient norm alongside the loss. Two curves distinguish these cases in seconds; one curve does not.\n\n## The position on optimisers\n\nAdamW (Adam with weight decay applied separately from the gradient) is the default for transformer training and has been for years. The claim that a newer optimiser beats it is made regularly and survives independent replication rarely, in part because comparisons are extremely sensitive to how much tuning each method received. If you are choosing an optimiser, the evidence supports AdamW plus a careful learning rate over almost anything else, and the time is better spent on the learning rate than on the optimiser.\n\n## The rule to keep\n\nCurvature differing across directions is why plain descent is slow. Momentum averages away the oscillation, Adam rescales each parameter by its own gradient history, and both are approximations chosen because the exact correction is unaffordable."},"check":{"question":"Adam's update divides by the square root of a running average of squared gradients. What does this achieve that momentum alone does not?","options":[{"text":"It removes noise from the gradient estimate, giving a cleaner descent direction.","correct":false,"tempting":"That is closer to what the first moment does; the second moment is a scale, not a smoother."},{"text":"It gives each parameter its own effective step size, shrinking steps for parameters with consistently large gradients and enlarging them for parameters with small ones.","correct":true},{"text":"It guarantees the loss decreases at every step, since the step size adapts to the local curvature.","correct":false,"tempting":"No adaptive method guarantees monotone decrease; Adam frequently increases the loss on individual steps."},{"text":"It prevents the gradient from vanishing by rescaling small gradients up to a fixed magnitude.","correct":false,"tempting":"The rescaling is relative to each parameter's own history, so a uniformly vanishing gradient stays vanishing."}]},"prev":{"slug":"convexity-and-local-minima","title":"Convexity, and why nobody promises anything about deep networks","url":"https://addaly.com/learn/maths-you-need/convexity-and-local-minima"},"next":{"slug":"when-gradients-vanish-or-explode","title":"Reading a training failure from the numbers","url":"https://addaly.com/learn/maths-you-need/when-gradients-vanish-or-explode"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Curvature, and what the optimisers are actually doing', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/curvature-momentum-and-adam (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Curvature, and what the optimisers are actually doing","courseTitle":"The Maths You Actually Need","module":{"index":3,"slug":"change-and-descent","title":"Change, slopes and the walk downhill"},"answer":null,"keyIdea":"The ratio between the steepest and shallowest curvature decides how badly plain gradient descent zigzags, and momentum and Adam are two cheap ways of compensating without ever computing that curvature.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"the-second-derivative-in-one-line","runs":[{"text":"The second derivative, in one line"}]},{"t":"p","runs":[{"text":"The first derivative says which way is downhill. The second says how the slope itself is changing: whether the surface curves sharply or gently. In many dimensions the second derivatives form a matrix called the Hessian, one entry for every pair of parameters."}]},{"t":"p","runs":[{"text":"You will never compute a Hessian for a real model. For 7 billion parameters it would have 49 × 10^18 entries. But you need one number from it, and it is the one that explains most optimisation trouble."}]},{"t":"h2","id":"the-number-that-explains-the-zigzag","runs":[{"text":"The number that explains the zigzag"}]},{"t":"p","runs":[{"text":"The Hessian’s eigenvalues are the curvatures along its eigen-directions. The ratio of the largest to the smallest is the condition number, and it decides how gradient descent behaves."}]},{"t":"p","runs":[{"text":"Take a simple quadratic bowl with curvature 100 along one axis and 1 along another: condition number 100. Gradient descent must use a learning rate small enough not to diverge along the steep axis, roughly "},{"text":"2/100 = 0.02","code":true},{"text":". But along the shallow axis, a step of 0.02 makes progress at rate "},{"text":"0.02 × 1","code":true},{"text":", so covering that direction takes about 100 times as many steps as the steep one."}]},{"t":"p","runs":[{"text":"That is the zigzag: fast oscillation across the narrow direction, crawling progress along the long one. The number of steps needed scales roughly with the condition number, and real loss surfaces have condition numbers in the thousands."}]},{"t":"h2","id":"momentum-remembering-where-you-were-going","runs":[{"text":"Momentum: remembering where you were going"}]},{"t":"p","runs":[{"text":"The fix costs one extra buffer. Instead of stepping along the current gradient, keep a running average of recent gradients and step along that."}]},{"t":"code","lang":"","label":"Text","text":"v  <-  beta * v + grad\nw  <-  w - learning_rate * v"},{"t":"p","runs":[{"text":"with "},{"text":"beta","code":true},{"text":" typically 0.9."}]},{"t":"p","runs":[{"text":"Why it works is worth seeing concretely. Along the narrow direction the gradient alternates sign each step, so successive terms in the running average cancel. Along the long direction the gradient points the same way every step, so they accumulate. With "},{"text":"beta = 0.9","code":true},{"text":" the accumulated step approaches "},{"text":"1/(1 − 0.9) = 10","code":true},{"text":" times a single gradient. The consistent direction gets amplified tenfold and the oscillating one gets damped: precisely the correction the geometry needed."}]},{"t":"h2","id":"adam-a-different-step-size-per-parameter","runs":[{"text":"Adam: a different step size per parameter"}]},{"t":"p","runs":[{"text":"Adam adds a second idea. Track not just the average gradient but the average "},{"text":"squared","i":true},{"text":" gradient, per parameter, and divide by its square root:"}]},{"t":"code","lang":"","label":"Text","text":"m <- beta1 * m + (1 - beta1) * grad          (average gradient)\nv <- beta2 * v + (1 - beta2) * grad^2        (average squared gradient)\nm_hat = m / (1 - beta1^t)                    (bias correction)\nv_hat = v / (1 - beta2^t)\nw <- w - lr * m_hat / (sqrt(v_hat) + eps)"},{"t":"p","runs":[{"text":"Defaults: "},{"text":"beta1 = 0.9","code":true},{"text":", "},{"text":"beta2 = 0.999","code":true},{"text":", "},{"text":"eps = 1e-8","code":true},{"text":"."}]},{"t":"p","runs":[{"text":"The division is the substance. A parameter whose gradients are consistently large gets a large "},{"text":"v","code":true},{"text":", so its effective step is scaled down; a parameter with small gradients gets scaled up. Each parameter ends up with its own step size, adapted automatically. That is a crude, cheap, diagonal-only substitute for using the curvature."}]},{"t":"p","runs":[{"text":"Bias correction is not decoration.","b":true},{"text":" Both "},{"text":"m","code":true},{"text":" and "},{"text":"v","code":true},{"text":" start at zero, so early estimates are biased towards zero. At step 1 with "},{"text":"beta2 = 0.999","code":true},{"text":", the raw "},{"text":"v","code":true},{"text":" is 0.001 times the true squared gradient; dividing by "},{"text":"1 − 0.999^1 = 0.001","code":true},{"text":" restores it. Without this the first few hundred steps take wildly wrong step sizes, which shows up as an unstable start and is the reason warmup helps."}]},{"t":"h2","id":"what-it-costs","runs":[{"text":"What it costs"}]},{"t":"p","runs":[{"text":"Adam stores two extra numbers per parameter. For 7 billion parameters in 32-bit:"}]},{"t":"code","lang":"","label":"Text","text":"weights   :  7e9 * 4  = 28 GB\ngradients :  7e9 * 4  = 28 GB\nAdam m    :  7e9 * 4  = 28 GB\nAdam v    :  7e9 * 4  = 28 GB\n                        112 GB, before a single activation"},{"t":"p","runs":[{"text":"This is the arithmetic behind the familiar claim that full fine-tuning of a 7B model needs far more memory than you would guess from its size, and behind the popularity of memory-efficient variants: 8-bit Adam quantises the two states, and SGD with momentum keeps only one."}]},{"t":"h2","id":"reading-a-loss-curve-for-which-problem-you-have","runs":[{"text":"Reading a loss curve for which problem you have"}]},{"t":"p","runs":[{"text":"Three patterns, three causes:"}]},{"t":"ul","items":[[{"text":"Loss spikes to NaN early.","b":true},{"text":" The learning rate exceeds the stability limit for the steepest curvature. Lower it, or add warmup so the first steps are small."}],[{"text":"Loss decreases very slowly and smoothly.","b":true},{"text":" The learning rate is too small, or the problem is badly conditioned. Try raising the rate first; it is one experiment."}],[{"text":"Loss falls then plateaus while the gradient norm stays high.","b":true},{"text":" Oscillation across a narrow valley. A learning-rate decay usually breaks it, which is the main reason cosine schedules are the default."}]]},{"t":"p","runs":[{"text":"Log the gradient norm alongside the loss. Two curves distinguish these cases in seconds; one curve does not."}]},{"t":"h2","id":"the-position-on-optimisers","runs":[{"text":"The position on optimisers"}]},{"t":"p","runs":[{"text":"AdamW (Adam with weight decay applied separately from the gradient) is the default for transformer training and has been for years. The claim that a newer optimiser beats it is made regularly and survives independent replication rarely, in part because comparisons are extremely sensitive to how much tuning each method received. If you are choosing an optimiser, the evidence supports AdamW plus a careful learning rate over almost anything else, and the time is better spent on the learning rate than on the optimiser."}]},{"t":"h2","id":"the-rule-to-keep","runs":[{"text":"The rule to keep"}]},{"t":"p","runs":[{"text":"Curvature differing across directions is why plain descent is slow. Momentum averages away the oscillation, Adam rescales each parameter by its own gradient history, and both are approximations chosen because the exact correction is unaffordable."}]}],"check":{"question":[{"text":"Adam’s update divides by the square root of a running average of squared gradients. What does this achieve that momentum alone does not?"}],"options":[{"text":[{"text":"It removes noise from the gradient estimate, giving a cleaner descent direction."}],"correct":false,"tempting":[{"text":"That is closer to what the first moment does; the second moment is a scale, not a smoother."}]},{"text":[{"text":"It gives each parameter its own effective step size, shrinking steps for parameters with consistently large gradients and enlarging them for parameters with small ones."}],"correct":true,"tempting":null},{"text":[{"text":"It guarantees the loss decreases at every step, since the step size adapts to the local curvature."}],"correct":false,"tempting":[{"text":"No adaptive method guarantees monotone decrease; Adam frequently increases the loss on individual steps."}]},{"text":[{"text":"It prevents the gradient from vanishing by rescaling small gradients up to a fixed magnitude."}],"correct":false,"tempting":[{"text":"The rescaling is relative to each parameter’s own history, so a uniformly vanishing gradient stays vanishing."}]}],"order":[0,3,1,2],"why":null},"prev":{"slug":"convexity-and-local-minima","title":"Convexity, and why nobody promises anything about deep networks","minutes":9},"next":{"slug":"when-gradients-vanish-or-explode","title":"Reading a training failure from the numbers","minutes":9}}}