L-BFGS

Also known as: Limited-memory Broyden-Fletcher-Goldfarb-Shanno algorithm

On this page 7

L-BFGS, the Limited-memory Broyden-Fletcher-Goldfarb-Shanno algorithm, is a quasi-Newton method for unconstrained optimization that builds an implicit approximation of the inverse Hessian from only the last few gradient differences. In artificial intelligence and machine learning, it is a standard solver for smooth, deterministic objective functions such as logistic regression, conditional random fields and full-batch model fitting.

The method keeps the fast convergence of BFGS while reducing memory from quadratic to linear in the number of parameters. That trade makes it practical for problems with millions of variables, where storing a dense Hessian or its inverse would be impossible.

How L-BFGS approximates curvature

L-BFGS approximates second-order information by storing m pairs of vectors instead of a full matrix. Each pair contains the step s = x(k+1) – x(k) and the gradient change y = g(k+1) – g(k), which together describe how the gradient responded to the most recent move.

At every iteration, the algorithm computes a search direction with the two-loop recursion. The first loop runs backward through the stored pairs, the second runs forward, and between them an initial diagonal scaling, usually gamma = s’y / y’y, sets the step scale. The result equals the product of an implicit inverse Hessian approximation with the gradient, obtained in roughly 4mn floating-point operations for n parameters.

After the direction is found, a line search chooses the step length. Most implementations require the strong Wolfe conditions, which guarantee sufficient decrease and enforce positive curvature (s’y > 0). That curvature condition keeps the approximation positive definite, so every computed direction remains a descent direction.

The main stages of one iteration are summarized below, together with their purpose and approximate cost.

StagePurposeApproximate cost
Gradient evaluationMeasure the local slopeOne forward and backward pass
Two-loop recursionTurn gradient into a curvature-aware directionAbout 4mn operations
Line searchPick a step satisfying Wolfe conditionsOne to a few function evaluations
Memory updateAdd the newest pair, discard the oldestAbout 2n stored values
Stages of one L-BFGS iteration

Key parameters and their effects

The behavior of L-BFGS depends on a small set of parameters, and the memory size m matters most. Values between 3 and 20 are typical, and m = 10 is a common default; larger values capture more curvature but rarely help beyond about 20 on ordinary problems.

The following table lists the parameters that practitioners adjust most often and the effect of each one.

ParameterTypical valueEffect
Memory size m5 to 20More curvature information, more memory
Gradient tolerance1e-5 to 1e-8Controls when to stop
Wolfe constant c11e-4Strictness of sufficient decrease
Wolfe constant c20.9Strictness of the curvature condition
Maximum iterations100 to 10,000Caps total work on hard problems
Main L-BFGS parameters

Two widely used variants extend the basic method. L-BFGS-B adds simple bound constraints on each variable through a projected gradient and a generalized Cauchy point, and OWL-QN handles L1 regularization by working within orthants where the absolute-value term is differentiable.

L-BFGS sits between first-order methods and the full Newton’s method. It uses only gradients, like gradient descent, yet it adapts the step to local curvature, which gives superlinear-like progress on many smooth problems without forming the Hessian matrix.

The comparison below places L-BFGS next to the neighboring methods of the optimization toolbox.

MethodInformation usedMemoryBest suited to
Gradient descentGradient onlyO(n)Simple or very noisy problems
Newton’s methodExact HessianO(n squared)Small, highly accurate problems
Full BFGSDense inverse Hessian estimateO(n squared)Medium problems up to thousands of variables
L-BFGSLast m gradient pairsO(mn)Large smooth deterministic problems
Conjugate gradientPrevious directionO(n)Large problems with very tight memory
AdamRunning gradient momentsO(n)Stochastic minibatch deep learning
L-BFGS and neighboring optimization methods

Against the conjugate gradient method, L-BFGS usually needs fewer function evaluations for a modest increase in memory. Against Adam and other adaptive methods, it converges faster on full-batch objectives but is poorly suited to noisy minibatch gradients, which corrupt the stored curvature pairs.

Where L-BFGS is used in machine learning

L-BFGS is the default choice for medium and large smooth problems whose full gradient can be computed exactly. Common examples include multinomial logistic regression, maximum entropy models, Gaussian process hyperparameter fitting and the training of conditional random fields.

Scientific computing and deep learning also use it in narrower roles. Physics-informed neural networks often switch to L-BFGS after an Adam warm-up phase, neural style transfer optimizes image pixels with it, and many statistical libraries rely on it for maximum likelihood estimation.

The decision table below shows when the method is a strong candidate and when another optimizer is more appropriate.

SituationRecommended choiceReason
Smooth convex loss, full batchL-BFGSFast, reliable convergence
Box constraints on variablesL-BFGS-BHandles bounds natively
L1-regularized sparse modelOWL-QNCopes with nondifferentiable terms
Minibatch deep network trainingAdam or SGDNoise breaks curvature estimates
Very few variables, high accuracyNewton’s methodExact curvature is affordable
Choosing whether to use L-BFGS

Limitations and common mistakes

The method assumes a reasonably smooth objective with reliable gradients. When those assumptions fail, the curvature model becomes misleading, and the optimizer may stall, take tiny steps or terminate early with a line search failure.

  • Stochastic gradients produce inconsistent y vectors; stochastic L-BFGS variants exist but require careful averaging or large batches.
  • Skipping the curvature check allows s’y to become nonpositive and destroys positive definiteness.
  • Poorly scaled features slow convergence; standardizing inputs usually helps more than enlarging m.
  • Nonsmooth terms such as hinge losses or L1 penalties need a specialized variant rather than plain L-BFGS.
  • Non-convex objectives may lead the method to a local optimum or a saddle region, as with any local optimizer.

A frequent diagnostic error is to treat an abnormal line search termination as convergence. Checking the final gradient norm, rather than trusting the exit message alone, separates a genuine optimum from a numerical failure.

In everyday language

Imagine walking down a foggy hillside to reach the lowest point. You can feel the slope under your feet. You cannot see the whole valley. L-BFGS remembers your last few steps and how the slope changed after each one.

From that short memory, it guesses the shape of the ground ahead. It then takes longer steps on gentle slopes and shorter steps where the ground curves sharply. Because it keeps only a handful of notes, it stays light even on enormous problems. The key idea is simple: a little memory of the past makes each new step smarter.

Seen in the real world

A data science team at an online retailer trains a multinomial logistic regression model to route customer support tickets into 40 categories. The model has about 2 million sparse features from word and phrase counts, and the full training set of 600,000 tickets fits in memory.

Plain gradient descent needed several thousand iterations and careful learning rate tuning. The team switched to L-BFGS with memory size 10 and a gradient tolerance of 1e-6. The solver reached the same validation accuracy in about 180 iterations, and training time fell from roughly two hours to under 15 minutes on the same server.

Later the team added L1 regularization to shrink the feature set and moved to OWL-QN. The final model kept fewer than 15 percent of the features with no measurable loss in accuracy.