Optimizer Selection and Memory Management in Large-Scale Training

    This article explains why optimizer state, rather than compute, is often the hidden bottleneck in large-scale model training. It compares element-wise adaptive optimizers with matrix-level orthogonalized updates, outlines practical engineering concerns such as numerical stability and hyperparameter tuning, and provides a reusable framework for estimating memory usage. Readers will also find a deployment checklist covering equivalence testing, parameter grouping, precision strategy, observability, and fault tolerance.

    1. Background: Optimizer State Is a Hidden Cost Driver

    In the pre-training of large-parameter models, compute procurement is usually the most visible cost item. However, what really compresses the available training space is often the optimizer state. Take the long-dominant element-wise adaptive optimization methods as an example: to maintain an adaptive step size for each parameter, they need to store two state copies per weight—the first moment and the second moment. In mixed-precision training, if these states are kept in fp32, then at a parameter scale of around 1.6T, these two copies alone can consume memory and host RAM on the order of tens of TB.

    The knock-on effects are:

    • Activation and batch size that fit on a single device are severely squeezed, making it hard to scale up the global batch;
    • Memory reserved for extending context length is taken up by optimizer state;
    • Parallel partitioning strategies are forced to be more aggressive, communication overhead rises, and scaling efficiency drops.

    Therefore, optimizer selection is not just a question of “faster or slower convergence”; it is a key variable that directly determines compute output per unit and engineering complexity.

    2. The Essential Difference Between Two Optimization Paradigms

    2.1 Element-wise Adaptation: Precise but Expensive

    Element-wise methods treat a weight matrix as N mutually independent scalars, estimate the first- and second-order gradient statistics for each scalar separately, and then decide the update magnitude for each one. The advantage is strong anisotropic adaptability, which is friendly to sparse parameters or parameters with large scale differences; the cost is that the state size corresponds one-to-one with the parameters, so memory overhead grows linearly.

    2.2 Matrix-level Orthogonalized Updates: A Holistic Geometric View

    Matrix-level methods treat the entire weight matrix as an indivisible high-dimensional geometric object, orthogonalize the “matrix formed by fusing gradient and momentum,” and then add it to the weights as a whole. The intuition is to make the scale of the update direction tend toward balance across all singular directions, avoiding a few directions dominating the update. Because there is no need to maintain two element-wise states per parameter, state memory is significantly reduced.

    An easy-to-understand analogy: element-wise methods are like individuals fighting on their own, requiring a separate step-size instruction for each individual; matrix-level methods first arrange individuals into a formation and then advance as a whole at a unified pace, with lower command overhead.

    Illustrative pseudocode (structure only, not a specific implementation):

    1. # Element-wise adaptive (structural illustration)
    2. m = beta1 * m + (1 - beta1) * g
    3. v = beta2 * v + (1 - beta2) * g * g
    4. w -= lr * (m / (sqrt(v) + eps))
    5. # Matrix-level orthogonalized update (structural illustration)
    6. buf = beta * buf + (1 - beta) * g # only one momentum state
    7. u = orthogonalize(buf) # orthogonalize the matrix as a whole
    8. w -= lr * u

    3. Common Concerns About Orthogonalized Updates and Engineering Responses

    The most typical concern after such methods emerged is: “A neat formation is not practical on a real battlefield, since gradients themselves are anisotropic and their noise distribution is uneven.” This concern is indeed valid in engineering and needs to be addressed item by item in practice:

    1. Scope of application: usually applied only to 2D weight matrices in hidden layers; embedding layers, output heads, normalization, and biases are still safer with adaptive methods.
    2. Approximation of orthogonalization: exact orthogonalization is costly, so engineering practice generally uses iterative approximation, where the number of iterations is the direct knob for the “accuracy–overhead” tradeoff.
    3. Numerical stability: under low precision, iterative approximation is prone to degradation, so higher-precision accumulation is recommended on critical paths.
    4. Learning rate and coupling: the scale of the holistic update differs from that of element-wise updates, so an independent learning rate, warmup, and decay strategy are needed, along with scale alignment.
    5. Mixed use: parameter groups where the two methods coexist need separate hyperparameters and schedules to avoid mutual interference.

    4. How to Calculate the Memory Bill: A Reusable Estimation Framework

    Let the parameter count be P. Under mixed precision, weights and gradients are each counted as 2 bytes, and each element-wise adaptive state is 4 bytes:

    • Weights + gradients: about 4P bytes;
    • Two adaptive states: about 8P bytes;
    • One momentum state for the matrix-level method: about 4P bytes.

    Estimating with P = 1.6×10¹², the state portion alone can differ by about 6.4 TB. This explains why streamlining state can directly buy larger batch and context space. It should be emphasized that actual usage is also affected by parallel partitioning, communication buffers, activation recomputation, and temporary workspaces, so measurements should be the source of truth.

    5. Deployment Practice Checklist

    • First run small-scale equivalence validation: compare loss curves and gradient norms under the same data and random seed;
    • Parameter grouping: specify which tensors use matrix-level updates and which retain adaptive methods;
    • Precision strategy: use higher precision for orthogonalization iterations and state accumulation;
    • Hyperparameter retuning: learning rate, warmup, weight decay, and gradient clipping need to be re-searched;
    • Observability: integrate logging services and monitoring alerts to track update norms, approximation residuals, and throughput;
    • Elasticity and fault tolerance: combine container platforms and object storage for checkpointing and recovery to reduce the risk of long-cycle training.

    6. Conclusion

    The real value of an optimizer lies in “effective progress per unit of memory and per unit of compute.” By reducing state copies and deciding updates in a holistic geometric way, matrix-level orthogonalized updates provide a cost-controllable alternative path for large-scale training. However, it is not an unconditional replacement; it needs to be mixed by tensor type and paired with governance of precision, hyperparameters, and observability. On cloud environments such as Baidu AI Cloud, the above selection methods can be consolidated into reproducible and measurable training engineering standards by leveraging general capabilities like container platforms, object storage, logging services, and monitoring alerts.