AI Wiki中文/EN

Nesterov acceleration: where is the gradient measured?

Nesterov 加速

Derive the lookahead/buffer coordinate change and run a smooth accelerated schedule with explicit assumptions.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Measure the slope where momentum is taking you

Imagine a current position and a velocity already pointing beyond it. Classical momentum measures the slope at the current position. A Nesterov-style velocity update first forms a provisional position and measures the slope there. The difference is one evaluation location, but its effect accumulates over later steps.

Sutskever and colleagues, Section 2, express this lookahead update explicitly. The fixed PyTorch 2.8 SGD documentation writes a buffer-based implementation. We derive why these can agree after reparameterization even though their stored “parameters” do not equal the same coordinate sequence.

Two positions, one gradient evaluation per step

Use constant positive η, constant β in [0,1), and zero initial velocity. The lookahead coordinate is p:

pt=θt+βvt,vt+1=βvt−η∇f(pt),θt+1=θt+vt+1.p_t=\theta_t+\beta v_t,\qquad v_{t+1}=\beta v_t-\eta\nabla f(p_t),\qquad \theta_{t+1}=\theta_t+v_{t+1}.

The provisional move βvₜ is not a second gradient step; it reuses the existing velocity. For f(θ)=θ²/2, θ₀=1, η=1/4 and β=1/2, the first new θ is 3/4. The next gradient is evaluated at 3/4−1/8=5/8. It produces θ₂=15/32, whereas classical momentum produces 7/16.

Derive the buffer form instead of comparing variable names

Set bₜ=−vₜ/η and retain pₜ as the stored parameter. Substitute the velocity update into pₜ₊₁=θₜ₊₁+βvₜ₊₁:

bt+1=βbt+gt,pt+1=pt−η(gt+βbt+1),gt=∇f(pt),vt=−ηbt.b_{t+1}=\beta b_t+g_t,\qquad p_{t+1}=p_t-\eta(g_t+\beta b_{t+1}),\qquad g_t=\nabla f(p_t),\quad v_t=-\eta b_t.

With p₀=θ₀ and b₀=0, the buffer method stores p₁=5/8 after its first step, not θ₁=3/4. Comparing those two numbers as if both represented θ would falsely report an implementation mismatch. They are related by the stated coordinate change. This derivation assumes constant coefficients, zero dampening, no weight decay and matched initial state; do not transfer it unchanged to variable-rate schedules or every optimizer option.

For a scalar quadratic with curvature λ, eliminating velocity from the lookahead method gives a characteristic polynomial:

r2−(1+β)(1−ηλ)r+β(1−ηλ)=0.r^2-(1+\beta)(1-\eta\lambda)r+\beta(1-\eta\lambda)=0.

Compared with classical momentum, curvature now also multiplies the effective momentum term. This helps explain different oscillations, but does not guarantee stability for any learning rate. The tests include a deliberately unstable choice.

The accelerated rate belongs to a specified algorithm

A concrete smooth accelerated scheme is the zero-regularizer specialization of Beck and Teboulle’s FISTA, Section 4 and Theorem 4.4. Set a₀=1 and y₀=x₀. For a convex differentiable function on Euclidean space with L-Lipschitz gradient, an attained minimum x*, exact gradients and positive L, use:

xk+1=yk−L−1∇f(yk),ak+1=1+1+4ak22,yk+1=xk+1+ak−1ak+1(xk+1−xk),f(xk)−f(x∗)≤2L∥x0−x∗∥2(k+1)2(k≥1).\begin{aligned} x_{k+1}&=y_k-L^{-1}\nabla f(y_k),&a_{k+1}&=\frac{1+\sqrt{1+4a_k^2}}2,\\ y_{k+1}&=x_{k+1}+\frac{a_k-1}{a_{k+1}}(x_{k+1}-x_k),& f(x_k)-f(x^*)&\leq\frac{2L\|x_0-x^*\|^2}{(k+1)^2}\quad(k\geq1). \end{aligned}

The source uses an index shifted by one for its auxiliary sequence. This bound concerns objective error, not distance to a minimizer or classification accuracy. The changing coefficient (aₖ−1)/aₖ₊₁ is part of the algorithm. The fixed β=1/2 demonstration above does not inherit this bound merely because it uses a lookahead. We cite the theorem; a few numerical checks below are not its proof.

Verify the coordinate change and run the scheduled method

The complete Python 3.12 standard-library program implements the lookahead and buffer forms independently with exact fractions. It also runs the specified changing-coefficient scheme on f(x,y)=(x²+4y²)/2 with L=4 and initial point (1,1), using floating point only for that square-root schedule.

from fractions import Fraction as F
from math import sqrt,isfinite


def lookahead(gradient,steps,initial=F(1),rate=F(1,4),beta=F(1,2),classic=False):
    theta=F(initial);rate=F(rate);beta=F(beta);v=F(0)
    if type(steps) is not int or not 0<=steps<=32 or not 0<rate<=1 or not 0<=beta<1:raise ValueError('bounded steps, positive rate and beta in [0,1) required')
    rows=[(theta,v,theta+beta*v)]
    for _ in range(steps):
        point=theta if classic else theta+beta*v
        v=beta*v-rate*F(gradient(point));theta+=v
        rows.append((theta,v,theta+beta*v))
    return rows


def buffer_nag(gradient,steps,initial=F(1),rate=F(1,4),beta=F(1,2)):
    p=F(initial);b=F(0);rows=[(p,b)]
    for _ in range(steps):
        g=F(gradient(p));b=beta*b+g;p-=rate*(g+beta*b);rows.append((p,b))
    return rows


def accelerated_quadratic(initial,curvatures,L,steps):
    x=tuple(float(v) for v in initial);lam=tuple(float(v) for v in curvatures);L=float(L)
    if len(x)!=len(lam) or not 1<=len(x)<=8 or not all(isfinite(v) for v in (*x,*lam,L)):raise ValueError('finite matching bounded dimensions required')
    if not all(0<v<=L for v in lam) or type(steps) is not int or not 0<=steps<=100:raise ValueError('positive curvatures bounded by L and integer steps required')
    if any(abs(v)>100 for v in x) or L>100:raise ValueError('teaching magnitude limit exceeded')
    y=x;a=1.;rows=[x]
    for _ in range(steps):
        new=tuple((1-l/L)*v for l,v in zip(lam,y))
        next_a=(1+sqrt(1+4*a*a))/2
        y=tuple(n+(a-1)/next_a*(n-old) for n,old in zip(new,x))
        x=new;a=next_a;rows.append(x)
    return rows


if __name__=='__main__':
    nag=lookahead(lambda x:x,4);buf=buffer_nag(lambda x:x,4);cm=lookahead(lambda x:x,4,classic=True)
    print('step / NAG position / lookahead / buffer-stored parameter / classical position')
    for k,(n,b,c) in enumerate(zip(nag,buf,cm)):print(k,str(n[0]),str(n[2]),str(b[0]),str(c[0]))
    print('reparameterized sequences agree:',all(n[2]==b[0] and n[1]==-F(1,4)*b[1] for n,b in zip(nag,buf)))
    rows=accelerated_quadratic((1,1),(1,4),4,10)
    loss=(rows[-1][0]**2+4*rows[-1][1]**2)/2
    print('scheduled ten-step point:',[round(v,9) for v in rows[-1]])
    print('scheduled loss / theoretical upper bound:',round(loss,9),round(16/121,9))

Actual output:

step / NAG position / lookahead / buffer-stored parameter / classical position
0 1 1 1 1
1 3/4 5/8 5/8 3/4
2 15/32 21/64 21/64 7/16
3 63/256 69/512 69/512 11/64
4 207/2048 117/4096 117/4096 -1/256
reparameterized sequences agree: True
scheduled ten-step point: [-0.029492797, 0.0]
scheduled loss / theoretical upper bound: 0.000434913 0.132231405

At every fixed-coefficient step, the stored buffer parameter agrees with the lookahead coordinate, and the velocity agrees with −η times the buffer. Tests also check this identity on a nonlinear polynomial gradient, so the comparison is not restricted to a quadratic coincidence.

The scheduled example has minimum zero at the origin and squared initial distance two, giving the displayed bound 16/121 at k=10. The implementation rejects L smaller than its largest diagonal curvature. These exact quadratic assumptions allow a legitimate theorem comparison; it is not an empirical claim about deep-network training. Both variants need one gradient evaluation and O(d) additional vector state per ordinary d-dimensional step.

Do not attach a convex theorem to an arbitrary training loop

Mini-batch noise, nonconvex losses, changing learning rates, clipping and nonzero dampening can invalidate the assumptions of a particular equivalence or convergence theorem. A framework’s nesterov=True option does not assert that the user’s objective is convex or that its settings implement the changing-coefficient theorem above.

Lookahead is not a forecast of the exact next optimum and does not compute a Hessian. It changes where the current gradient is measured. Larger momentum can still lead to overshoot or divergence, and objective values need not decrease monotonically under accelerated schemes.

Our buffer routine illustrates the cited zero-dampening update; it does not reproduce every framework option or invoke PyTorch. FISTA is used only in its smooth, zero-regularizer specialization. We do not implement its general proximal step, backtracking, image-deblurring experiment or nonsmooth regularizers here.

Name the coordinate before comparing its value

  1. Why are the first values 3/4 and 5/8 both correct?

Answer 1: The first is θ₁; the second is p₁=θ₁+βv₁. They are different coordinates of related formulations.

  1. Does the lookahead step require two gradient evaluations?

Answer 2: No. It reuses velocity to choose a point and evaluates one gradient there.

  1. Does a fixed β=1/2 automatically establish the displayed O(1/k²) bound?

Answer 3: No. The displayed theorem uses its specified coefficient schedule and smooth convex assumptions.

  1. What does the convergence bound measure?

Answer 4: Objective suboptimality f(xₖ)−f(x*), not classification accuracy or necessarily parameter distance.

An algorithm name is not a complete specification

The 2013 paper supplies the deep-learning lookahead formulation; the fixed API supplies the buffer update. The 2009 FISTA paper provides an explicit accelerated schedule and theorem for the smooth specialization. Our rational trajectories, reparameterization check and small diagonal experiment are original. Continue with momentum, convexity and SGD.

Make a prediction, then check

Which quantity agrees with the fixed-coefficient buffer parameter?

Choose one answer

Learning objectives

  • Derive which coordinate the buffer update stores.
  • Attach a rate claim to its algorithm and assumptions.

Prerequisites & connections

Explore related knowledge →

References

  1. On the importance of initialization and momentum in deep learning
    Ilya Sutskever; James Martens; George Dahl; Geoffrey Hinton · 2013
  2. SGD — PyTorch 2.8
    PyTorch contributors
  3. A Fast Iterative Shrinkage-Thresholding Algorithm for Linear Inverse Problems
    Amir Beck; Marc Teboulle · 2009

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.

  • Single-agent authored technical review: bounded primary-source locations, assumptions, original derivations, exact/literal references and matching bilingual equations/examples/exercises. Not independent human or second-agent review.
  • Four focused CPython3.12.4 tests passed per chapter. Bidirectional alignment/Jacobians, injected network faults, exhaustive learning curves and stochastic paths, exact momentum trajectories, Nesterov reparameterization and a smooth accelerated bound instance are checked. Bidirectional RNN/debugging use NumPy1.26.4; the other four use the standard library.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.