Optimizer Selection and Memory Optimization in Large-Scale Model Training

    This article examines why optimizer state has become a primary consumer of GPU memory in large-scale model training and compares element-wise adaptive optimizers with matrix-level orthogonalized approaches. It outlines the engineering gaps required to scale orthogonalized updates, including parameter grouping, distributed consistency, computation overlap, and numerical stability, and presents a practical combination of memory-saving techniques such as state compression, sharding and offloading, mixed precision, recomputation, observability, and elastic orchestration. Readers will find guidance on matching optimizer choices to model scale, parallelism strategy, and cost budgets.

    1. The Starting Point: Optimizer State Is Becoming the Main Memory Consumer

    In large-scale model training, GPU memory is often the first bottleneck to surface. When assessing whether training is feasible, many teams look at parameter count first, then estimate activation memory, while overlooking one fact: the optimizer itself is a major memory consumer.

    Take the mainstream element-wise adaptive methods as an example. To maintain an adaptive learning rate for each parameter, they need to store two additional states per parameter: the first moment and the second moment. In mixed-precision training, if master parameter copies and gradient copies are added on top, the state-related memory alone can reach several times the parameter scale. For a model on the order of a trillion parameters, this overhead can consume a memory budget in the tens of terabytes.

    The consequences are a chain reaction: the room left for batch size and context length is severely compressed, forcing teams to reduce batch size, shorten sequences, or introduce more parallel partitioning and recomputation. Training throughput drops and end-to-end cost rises. This is why “optimizer selection” has turned from an academic detail into an engineering necessity.

    2. The Fundamental Difference Between Two Optimization Approaches

    2.1 Element-wise Optimization: Splitting a Matrix into Unrelated Scalars

    The implicit assumption of element-wise adaptive methods is that every element in a weight matrix is an independent individual, each maintaining its own momentum and second-order statistics and each deciding its own update step size. The advantage is strong adaptivity and robustness to sparse gradients and parameters of different scales; the cost is that state overhead scales strictly linearly with the number of parameters, and the update direction lacks matrix-level structural constraints.

    An intuitive analogy: it is like letting a pile of iron balls roll down a slope independently, with each ball calculating separately how far to roll next. It is precise, but the coordination cost is extremely high.

    2.2 Matrix-Level Orthogonalized Optimization: Treating the Matrix as a Geometric Whole

    Another approach treats the weight matrix as an indivisible high-dimensional geometric object. It also maintains momentum, but does not store second-order statistics for each element. When performing the actual update, it first orthogonalizes the matrix produced by fusing the gradient with the momentum, obtaining an orthogonal (or approximately orthogonal) update matrix, and then adds it to the weights as a whole.

    This brings two direct benefits:

    • State memory drops significantly, usually keeping only one momentum-level state;
    • The update is constrained to structurally more reasonable transformations such as overall rotation or reflection, avoiding runaway step sizes in individual dimensions. In small- and medium-scale racing experiments, it often reaches the target loss in fewer training steps.

    By analogy, the former is scattered troops fighting independently, while the latter arranges all elements into a formation and advances at a unified pace, with clearly higher command efficiency.

    3. The Key Engineering Gaps Between “Running on Small Models” and “Usable at Scale”

    Matrix-level orthogonalized methods were initially validated only on small models at the hundred-million-parameter level, and the skepticism is reasonable: do the step savings observed at small scale still hold at hundreds of billions or trillions of parameters? In large-scale distributed environments, will the extra matrix-decomposition-style computation actually slow down throughput?

    To bridge this gap, engineering must address at least four things:

    1. Parameter grouping: Attention layers, embedding layers, normalization layers, and the output head differ in sensitivity to update scale. Typically, element-wise adaptive methods are retained for these parts, while matrix-level updates are enabled only for the 2D weight matrices in hidden layers, forming a hybrid optimization strategy.
    2. Distributed consistency: When tensor parallelism, pipeline parallelism, and data parallelism are combined, a 2D weight may be partitioned across multiple devices. Orthogonalization requires cross-device communication or local aggregation first, and the communication volume is strongly tied to the partitioning scheme, so it must be factored into the design.
    3. Computation overhead amortization: The extra matrix operations introduced by orthogonalization should overlap with backpropagation, and a reasonable number of iterations should balance precision against speed.
    4. Numerical stability: States stored in low precision easily accumulate errors during orthogonalization, so appropriate working precision and normalization strategies must be chosen.

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

    1. for step in batches:
    2. grads = backward(model, step)
    3. for name, p in model.named_parameters():
    4. g = grads[name]
    5. if p.ndim == 2 and is_hidden_weight(name):
    6. # Matrix-level: accumulate momentum, orthogonalize as a whole, then update uniformly
    7. buf = momentum * buf + g
    8. update = orthogonalize(buf)
    9. p -= lr * update
    10. else:
    11. # Element-wise adaptive: handle embeddings, normalization, output head, etc.
    12. m = beta1 * m + (1 - beta1) * g
    13. v = beta2 * v + (1 - beta2) * g * g
    14. p -= lr * (m / (sqrt(v) + eps))

    4. A Practical Combination of Memory Optimization Techniques

    The optimizer is only one page of the memory ledger; actual training requires combining the following general techniques:

    • Optimizer state compression: Choose optimization methods with lighter state, or reduce the storage precision of states;
    • Sharding and offloading: Partition optimizer state along the data-parallel dimension and, when necessary, offload it to host memory or the storage tier, trading bandwidth for capacity;
    • Mixed precision and recomputation: Trade computation for memory, while preserving master weight precision to avoid hurting convergence stability;
    • Memory observability: Use general monitoring, alerting, and logging services to continuously track peak memory, fragmentation rate, and throughput, turning tuning from experience-driven into data-driven;
    • Elastic resource orchestration: Perform elastic scaling and fault-tolerant rescheduling on top of a container platform to reduce the interruption cost of long-running training.

    In related practices at Baidu AI Cloud, these capabilities are typically combined into a complete training support solution: a container platform hosts distributed training jobs, object storage holds checkpoints and datasets, and monitoring, alerting, and logging services provide observability, allowing teams to focus on the model and algorithms themselves.

    5. Selection Recommendations

    The conclusion is not complicated: there is no absolute winner among optimizers, only the degree of match with scale, parallelism strategy, and cost budget. For small- and medium-scale work aimed at the fastest convergence validation, matrix-level orthogonalized methods are worth trying first. For ultra-large-scale production training, the more reliable path is a combination of “hybrid optimization + state sharding and offloading + mixed precision and recomputation,” starting with convergence and throughput comparison experiments on a small-scale cluster before gradually scaling up.