Optimizer Memory Optimization for Large-Scale Model Training: A New Paradigm
This article breaks down where GPU memory actually goes during large-scale model training and why optimizer states, not parameters, dominate the footprint. It quantifies state memory growth into the multi-terabyte range, then compares two optimization paths: sharding and offloading states without changing the optimizer math, versus changing the update rule itself with momentum-only, low-rank, or block-wise adaptive methods. It also provides a reusable evaluation framework covering memory peak, throughput, convergence, stability, and operations, plus practical rollout recommendations.
1. Where the Memory Actually Goes
In training models with extremely large parameter counts, the first intuition is often that memory is consumed mainly by the parameters themselves. Breaking it down shows that parameters are only the tip of the iceberg. With mixed-precision training, for example, several categories of data typically coexist in memory:
- Low-precision parameter copies used for forward and backward computation;
- High-precision master parameter copies for numerical stability and weight updates;
- Gradients required for backpropagation;
- State variables maintained by the optimizer;
- Activations and temporary buffers, along with communication buffers.
Among these, what stays resident over the long run as training steps accumulate, and cannot be released or reused, is the optimizer state. This is the key concern of the original material: adaptive moment estimation optimizers have long been the default choice for training workloads, but to gain per-parameter adaptive step sizes, they must store two statistics for every parameter, the first moment and the second moment.
2. Quantifying the Growth: Why State Variables Balloon to Over Ten Terabytes
Understanding the magnitude matters more than memorizing the conclusion. Assume a model with roughly 1.6 trillion parameters, mixed-precision training, a high-precision master copy kept for the master parameters following common industry practice, and two optimizer state tensors of the same length as the parameter count. The memory required for the state portion alone can be approximated as:
State memory ≈ parameter count × number of state copies × bytes per state element≈ 1.6e12 × 2 × 4 bytes≈ 12.8 TB
This does not yet include the master parameter copy, gradients, or activations. Comparing this with the low-precision parameters at “parameter count × 2 bytes” reveals an imbalanced ratio: the information used to “remember how to take the next step” is several times larger than the model knowledge itself.
This growth triggers a chain of consequences:
- Compressed batch size: Space left for activations and communication buffers is squeezed, the number of samples a single device can hold drops, and gradient noise characteristics change accordingly.
- Limited context length: Attention activations grow with sequence length, and the larger the state footprint, the shorter the supported context window.
- Forced higher parallelism: Adding sharding dimensions to fit the state introduces more communication, driving up communication volume and synchronization overhead.
- Non-linear cost increase: Adding devices does not amortize cost linearly; failure rates, checkpoint size, and recovery time all worsen at the same time.
It is worth stressing that checkpoint size is amplified by the state as well. Saving a full state snapshot can mean writing more than ten terabytes of data, which directly determines whether failure recovery takes minutes or hours.
3. Optimization Path One: Shard and Offload the State
The first class of approaches does not change the optimizer’s mathematical form; it only changes where the data is placed.
- Tensor-dimension sharding: Split parameters, gradients, and states across devices along matrix dimensions so each state copy resides only in a local shard. This is standard practice for ultra-large-scale training, at the cost of extra collective communication on every update.
- State offloading: Place states in host memory or even slower storage tiers, fetching them on demand during computation. This significantly relieves memory pressure but introduces a bandwidth bottleneck, and requires overlap with computation to hide latency.
- Precision compression: Store states at a lower bit width, trading numerical risk for space, which needs to be paired with more robust update rules and finer numerical monitoring.
In engineering practice, these three are usually combined, with memory watermark, communication share, and per-step time monitored to judge whether the configuration is reasonable.
4. Optimization Path Two: Change the Update Rule Itself
The second class of approaches is more fundamental: if two same-length states are a burden, can comparable convergence behavior be achieved with fewer statistics? The industry has several general technical routes:
- Momentum-based methods: Maintain only one momentum buffer of the same length as the parameters, approximating adaptive capability through global or block-wise scale normalization, which directly halves state usage.
- Low-rank state decomposition: Instead of storing the full second-order statistics, store low-rank factors or block statistics, using approximation in place of exact adaptivity.
- Block-wise adaptivity: Partition the parameter matrix into blocks and maintain statistics at the block level, trading coarse-grained adaptivity for lower memory usage.
The value of these methods lies not in “a particular model used it,” but in turning a memory problem into an approximation-quality problem. Evaluation must look at three metrics at the same time: peak memory per step, steps required to reach the target quality, and end-to-end wall-clock time. Looking only at memory reduction while ignoring an increase in convergence steps is a common evaluation pitfall.
An abstract sketch of the update logic is shown below:
# Illustrates the update structure only, not a specific implementationm = beta * m + (1 - beta) * grad # single momentum statescale = rms_norm(grad, block_size=1024) # block-wise scale normalization replacing per-parameter second momentparam -= lr * m / (scale + eps)
5. How to Tell Whether an Optimization Is Actually Worth It
It is recommended to build a reusable evaluation table containing at least:
| Dimension | Focus |
|---|---|
| Peak memory | Per-device peak, state share, activation share |
| Throughput | Per-step time, communication wait share |
| Convergence | Steps and data volume needed to reach baseline quality |
| Stability | Loss spike frequency, gradient norm distribution |
| Operations | Checkpoint size, recovery time, failure frequency |
Only when “memory drops × throughput does not regress × convergence steps do not increase significantly” all hold at once can the optimization be considered truly landed.
6. Practical Recommendations
- First break down memory usage to clarify the respective shares of state, master parameters, gradients, and activations, then decide the optimization direction.
- Prioritize sharding and offloading that do not change the mathematical form, since the risk is lowest.
- Then evaluate low-rank or momentum-based update rules, and be sure to run convergence-alignment experiments at small scale.
- Design the checkpoint strategy and fault-tolerance mechanism together, so the saved memory is not eaten up by recovery time.
- When running training on platforms such as Baidu AI Cloud, generic capabilities like container platforms, object storage, log services, and monitoring alerts can be combined to build an observable and recoverable training pipeline.
In summary, the memory bottleneck in ultra-large model training is essentially a trade-off between “adaptive capability” and “state size.” Quantifying this trade-off, breaking it down, and validating it item by item is the reusable engineering methodology.
