The interview problem

Practice prompt

For the loss f(x,y)=0.5(x²+100y²), derive gradient-descent dynamics from (1,1) and determine which constant learning rates converge from every initialization. Explain what changes at a saddle, and how to inspect curvature when a model's full Hessian cannot fit in memory.

Original ML fundamentals practice, not a reported company interview. Derivations and numerical examples are original. Primary reference retrieved September 27, 2026; publication date not stated; interview date not applicable.

1. Connect curvature to a local loss model

For a twice continuously differentiable scalar loss f at parameters θ, let g=∇f(θ) and H=∇²f(θ). For a small displacement p, f(θ+p)=f(θ)+gᵀp+0.5pᵀHp+o(‖p‖²). The gradient describes the first-order slope; the Hessian describes how that slope changes. They are different quantities.

Under these smoothness assumptions H is symmetric and has real eigenvalues with orthogonal eigenvectors. Along a unit eigenvector v with Hv=λv, the quadratic curvature is vᵀHv=λ. Eigenvalues are not generally the diagonal entries in an arbitrary coordinate system: off-diagonal terms couple coordinates.

For a quadratic with constant H, the expansion is exact. For a nonlinear model, a Hessian measured at one point does not bound curvature over an arbitrarily long step. Keep that distinction when translating the worked example into optimization advice.

2. Derive the stability condition

Here g=(x,100y) and H=diag(1,100). Gradient descent gives xnext=(1−η)x and ynext=(1−100η)y. Repeated updates multiply each coordinate by its corresponding factor at every iteration.

More generally, on a positive-definite quadratic, express the error from the minimizer in the Hessian eigenbasis. Each component evolves as eit+1=(1−ηλi)eit. Convergence from every initialization requires |1−ηλi|<1 for every eigenvalue. For positive λi, this is 0<η<2/λmax.

Thus this example requires 0<η<0.02. The strict inequality matters. This is a guarantee for constant-step exact gradient descent on this quadratic, not for momentum, stochastic updates or an arbitrary neural-network loss.

3. Compute stable, oscillating and divergent steps

At (1,1), the initial loss is 50.5. With η=0.01, the factors are (0.99,0), giving (0.99,0) and loss 0.49005 after one step. The high-curvature coordinate disappears immediately in exact arithmetic, but the shallow coordinate subsequently contracts by only 0.99 each step.

With η=0.019, the factors are (0.981,−0.9). The sharp coordinate changes sign every iteration while its magnitude shrinks. Oscillation is therefore not itself proof of divergence. The first-step loss is approximately 40.981181.

At η=0.02, the factors become (0.98,−1). A nonzero y oscillates without shrinking, so the iterates do not converge to the minimum. At η=0.021, the factors are (0.979,−1.1): the sharp coordinate grows in magnitude and the first-step loss rises to about 60.979221.

An initialization with y=0 can still converge at η=0.021 because the unstable component is absent. That does not make the rate stable from arbitrary initialization. Finite precision and perturbations can introduce a component that a hand-picked starting point omits.

4. Explain the cost of unequal curvature

The positive-definite condition number is κ=λmax/λmin=100. A rate small enough for the sharp direction may make progress slow in the shallow one. Rotating coordinates does not remove that eigenvalue ratio, even though it changes which coordinate entries look large.

For a positive-definite quadratic with smallest eigenvalue m>0 and largest eigenvalue L, the scalar constant step minimizing the worst eigencomponent contraction balances the endpoint magnitudes: 1−ηm=−(1−ηL). This gives η*=2/(L+m) and contraction factor (L−m)/(L+m). Here η*=2/101≈0.019802 and the factor is 99/101≈0.980198.

This is a minimax fixed-step statement about error contraction. It is not the best line-search step for every particular iterate. An initially dominant sharp component can favor a different immediate step; the minimax criterion protects against all directions.

Changing variables to u=x and v=10y turns the objective into 0.5(u²+v²). Gradient descent in these variables induces a different update metric in the original coordinates. Preconditioning can improve the effective conditioning, but it is not merely renaming the same algorithm. Apparent sharpness depends on parameterization and units.

5. Test stationary points and flat directions

For s(x,y)=0.5(x²−y²), the Hessian is diag(1,−1) and the origin is stationary. Gradient descent gives xnext=(1−η)x and ynext=(1+η)y. Any nonzero y grows in magnitude for η>0, moving away from the saddle; exactly at the origin, the gradient is zero and deterministic updates stay there.

At a stationary point of a twice continuously differentiable function, a positive-definite Hessian is sufficient for a strict local minimum. An indefinite Hessian identifies a saddle. A positive-semidefinite Hessian is inconclusive: x⁴ and −x⁴ both have zero second derivative at zero but opposite local behavior.

A positive-definite Hessian at a nonstationary point does not mean that point minimizes the loss. Likewise, zero curvature does not imply zero gradient: f(x)=x has zero second derivative everywhere but a nonzero slope. For a positive-semidefinite quadratic that has a minimizer, zero-eigenvalue error components stay fixed under gradient descent. Positive-eigenvalue components can converge while the final minimizer depends on initialization. Local conditions at one point do not prove global convexity.

6. Inspect curvature without storing the matrix

define scalar objective and differentiation variables
                           ↓
        fix batch, random state and model state
                           ↓
       compute gradient and Hessian-vector products
                           ↓
      validate on tiny analytic / finite-difference cases
                           ↓
       inspect directional curvature and spectral estimates
                           ↓
         test a proposed optimization change on the task

A Hessian-vector product Hv is the directional derivative of the gradient along v. For a fixed vector v, differentiating gᵀv with respect to parameters also gives Hv for a symmetric Hessian. If v itself depends on θ and is differentiated, extra terms appear; hold the intended direction fixed.

The PyTorch primary tutorial demonstrates computing Hessians through derivative transforms and obtaining HVPs without explicitly materializing the full matrix. The engineering choice should account for supported operations, activation storage and repeated differentiation costs. Avoid assuming that a matrix-free computation is free or constant-memory in every model.

At one million parameters, a dense float32 Hessian contains 10¹² entries and consumes 4 TB in decimal units before workspace. A float32 direction vector takes 4 MB. HVP-based methods remove the need for that dense matrix, but still require model state, autodiff workspace and often multiple passes.

7. Validate what the diagnostic actually measures

On a smooth small model, compare Hv against [∇f(θ+εv)−∇f(θ−εv)]/(2ε). Sweep ε: large values introduce truncation error and tiny values can suffer cancellation. For the worked quadratic and v=(1,1), the exact product is (1,100), making it an easy implementation check.

Hold the data batch, dropout randomness and stateful normalization behavior fixed while checking derivatives. Otherwise differences can reflect different functions rather than curvature. Specify whether the loss includes regularization and whether differentiation is with respect to inputs or model parameters.

Power iteration applied to an indefinite Hessian ordinarily targets the eigenvalue of greatest magnitude when its convergence assumptions hold; that eigenvalue can be negative. It does not automatically estimate the largest positive curvature. A negative Rayleigh quotient vᵀHv/(vᵀv) demonstrates a negative-curvature direction, but a few positive sampled quotients do not prove positive semidefiniteness.

At nonsmooth activation boundaries, the ordinary smooth Taylor interpretation may fail. A library's derivative convention is not a proof that the function is twice differentiable there. Curvature also varies across batches; a favorable diagnostic on one batch is not evidence of better population loss or generalization.

8. Compare curvature-aware remedies

Newton's direction solves Hp=−g. On the positive-definite quadratic, a full Newton step reaches the minimizer in exact arithmetic. Solve the system rather than explicitly forming an inverse. For an indefinite Hessian, the direction need not be a descent direction; damping or a trust-region formulation must address the actual local model.

A diagonal preconditioner is cheaper but cannot capture arbitrary rotated coupling. More elaborate approximations can improve steps while increasing computation and sensitivity to noisy curvature. Evaluate total time to useful solution, numerical stability and task quality, not just the number of optimization steps.

Follow-ups: Why can a rate work from one initialization but diverge from another? What changes when H is only semidefinite? Why is the η bound local for a nonlinear loss? Can a largest-magnitude eigenvalue estimate be negative? How does coordinate rescaling alter apparent sharpness?

9. Self-review rubric

  • Separate gradient slope from Hessian curvature.
  • Derive eigencomponent dynamics and strict stability bounds.
  • Compute shrinking oscillation versus divergence correctly.
  • Qualify the minimax fixed-step and conditioning claims.
  • Distinguish stationary minima, saddles and inconclusive flatness.
  • Explain HVP computation and its remaining costs.
  • Control model state and test numerical derivatives.
  • Avoid treating local curvature as a global training guarantee.

Sources and related practice

PyTorch: Jacobians, Hessians and Hessian-vector products, publication date not stated; retrieved September 27, 2026. Primary reference for automatic-differentiation approaches to curvature computation. Mathematical examples, stability derivations and validation scenarios here are original worked practice.

Continue with optimizer momentum and gradient clipping.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.