Optimizer Evolution Behind Long-Context LLMs

    This article traces the evolution of training optimizers—from SGD and momentum to adaptive learning rates and matrix-based methods—and explains why optimizer choice becomes critical when extending context length to the million-token scale. It covers the limitations of each stage, a practical selection table for different training scenarios, and engineering practices such as learning rate warmup, gradient clipping, numerical precision, and observability.

    1. What a Model Release Reveals About Training Bottlenecks

    A research organization recently released a preview of its next-generation large model along with open weights. The public information highlighted two key capabilities: million-character-level long context and improved scores across multiple public benchmarks. Releases like this tend to draw attention to context length and leaderboard numbers, but what actually determines whether those capabilities can be trained is something deeper: the optimizer and the parallel training strategy.

    The reason is straightforward. Scaling context length from a few thousand tokens to the million level means the attention computation for a single sequence grows quadratically, activation memory usage expands sharply, and gradient distributions across very long sequences become highly uneven. If parameter updates still rely on the most naive strategy, training either oscillates without converging or becomes unacceptably slow. Any discussion of a “technical breakthrough” therefore has to include the optimizer as a main thread.

    This article uses optimizers as the through-line to explain this technical progression and offers practical recommendations.

    2. What an Optimizer Is: A Descent Analogy and Its Limits

    The classic teaching analogy is “descending a mountain blindfolded”: the goal is to reach the deepest point of the range (the global minimum loss).

    • The loss function tells you the current altitude;
    • The gradient (obtained via backpropagation) tells you which way is downhill;
    • The optimizer is the strategy in your head, deciding where to go and how big a step to take.

    The analogy is useful, but it hides a key fact: a real high-dimensional loss surface is not a smooth mountain. It is high-dimensional, multi-scale, and ill-conditioned terrain. The core decisions an optimizer must make are three:

    1. How the step size (learning rate) adapts over the course of training and to parameter state;
    2. How to accumulate “historical information” to cross flat regions and damp oscillation;
    3. How to measure the size of a “step” in parameter space, i.e., what geometric structure to use to quantify the update.

    The third point is the most easily overlooked, yet it is the real breakthrough behind recent matrix-based optimizers.

    3. Stage One: SGD and Its Inherent Flaws

    The idea behind stochastic gradient descent traces back to nineteenth-century research on solving for extrema, and its engineering form is simple enough to express in a few lines of pseudocode:

    1. for t in range(steps):
    2. g = compute_grad(params, batch) # backpropagation
    3. params -= lr * g # no memory, no inertia

    It is equivalent to a “massless particle”: it can reach any speed instantly and stop instantly. This brings two problems:

    • Ill-conditioned canyon terrain: when curvature is extremely large in one direction and extremely small in another, the gradient bounces back and forth between the canyon walls, and effective forward progress is very slow;
    • Scale inconsistency: gradient magnitudes across different layers and parameters can differ by several orders of magnitude, so a single uniform learning rate is necessarily too large for some parameters and too small for others.

    4. Stage Two: Momentum Adds “Inertia”

    In the 1960s, Soviet mathematicians studying optimization theory proposed the Heavy Ball method, whose core idea is to give the particle mass and inertia:

    1. v = beta * v + g # accumulate the direction of past gradients
    2. params -= lr * v

    The intuitive effect: components that oscillate back and forth in the canyon cancel each other out, while the consistent component along the canyon direction keeps accumulating, so it “speeds up the more it collides.” In engineering terms, the momentum term also brings an implicit benefit—it naturally smooths minibatch sampling noise, making small-batch training more stable.

    But its limitation is clear: momentum only changes “direction,” not the “effective step size per parameter.” It cannot solve the problem of huge differences in gradient scale across parameters.

    5. Stage Three: Adaptive Learning Rates, Per-Parameter Step Sizes

    Subsequent adaptive methods (represented by root-mean-square and moment-estimation families) maintain a running estimate of second-order gradient statistics for each parameter and normalize the current gradient by its square root:

    1. m = b1 * m + (1 - b2) * g # first moment: direction
    2. v = b2 * v + (1 - b2) * g * g # second moment: scale
    3. m_hat, v_hat = bias_correct(m, b1, t), bias_correct(v, b2, t)
    4. params -= lr * m_hat / (sqrt(v_hat) + eps)

    This solves two problems at once: step-size adaptation and scale alignment across different parameters. That is also why it has long been the default choice for large-model training: it is insensitive to hyperparameters, simple to implement, and its memory overhead is only a constant multiple of the parameter count.

    The cost is equally clear: each parameter must additionally store first- and second-order statistics, so optimizer state memory is on the same order as parameter memory; meanwhile, the element-wise update ignores structural information inside parameter matrices.

    6. Stage Four: Defining a “Step” in Matrix Space

    Matrix-based optimizers start from a geometric observation: neural network weights are fundamentally matrices, and element-wise scaling destroys matrix structure. If the measure of the update changes from “element-wise absolute value” to a matrix norm (such as the spectral norm), and steepest descent is performed under that measure, you get an update form that “orthogonalizes first, then scales.”

    The engineering implementation typically involves three steps:

    1. Accumulate momentum on the gradient matrix;
    2. Apply one orthogonalization to the momentum matrix (pulling the matrix “straight” so that scales across directions become more uniform);
    3. Multiply the orthogonalized result by a uniform update strength and write it back to the parameters.

    Illustrative code (teaching-oriented pseudocode, not a specific framework API):

    1. buf = beta * buf + (1 - beta) * grad
    2. update = orthogonalize(buf) # iterative orthogonalization, a few rounds suffice
    3. params -= update_lr * update

    The benefits are structural: the update is more balanced across directions, allowing a relatively larger and more stable update strength; at the same time, only one matrix-level copy of the second-order statistics needs to be stored, rather than two element-wise copies, so optimizer state overhead is more manageable at the same parameter scale.

    The boundaries need emphasis: orthogonalization introduces extra computation and usually needs to be combined with a distributed parallel strategy that splits matrices across devices; there are also applicability limits based on the parameter count of weight matrices and layer type. It is not a “full replacement” but a better solution in specific scenarios.

    7. Engineering Selection: An Actionable Decision Table

    Scenario characteristic Recommended strategy
    Small-scale model, rapid validation Adaptive moment-estimation methods, default configuration is fine
    Large dense model, tight on memory Prioritize matrix-based optimizers + sharded optimizer state
    Long-context training Focus on gradient distribution and update balance, combined with sequence parallelism and recomputation
    Training oscillation, loss spikes Check learning rate and warmup first, then data and numerical precision, and only then switch optimizers

    Supporting practical points:

    • Learning rate warmup and decay: any optimizer needs warmup; matrix-based methods are more sensitive to update strength, so warmup should be longer;
    • Gradient clipping: clipping by global norm is the fallback for long-sequence training stability;
    • Numerical precision: iterative computations like orthogonalization should be done in high precision to avoid low-precision accumulation error;
    • Observability: bring gradient norm, update norm, and parameter norm into monitoring and alerting so anomalies can be located quickly.

    8. Running It in the Cloud: Standardizing the Training Stack

    To reproduce the training flow above in a cloud environment, you can assemble a standard stack from general-purpose capabilities: a container platform to host distributed training task orchestration, object storage to hold datasets and checkpoints, a message queue to decouple data preprocessing from training consumption, and logging and monitoring/alerting services for metric collection and anomaly notification. Baidu AI Cloud offers corresponding product categories for these general-purpose capabilities, which can be combined as needed; the key is to make “checkpoints, metrics, and alerts” defaults rather than afterthoughts.

    9. Conclusion

    From the “massless particle” to the “heavy ball with inertia,” then to “per-parameter step sizes,” and finally to “measuring updates under matrix geometry,” the evolution of optimizers is essentially a path of continually injecting more reasonable structure into the problem. For engineering practitioners, the conclusion is not complicated: first make the fundamentals—learning rate, warmup, clipping, precision—solid, then decide whether to introduce a matrix-based optimizer based on model scale and memory constraints. Tools will change; the methodology stays the same.