Adam Accumulation to Reduce Memory Footprints of both Activations and Gradients for Large-scale DNN Training

Yijia Zhang, Yibo Han, Shijie Cao, Guohao Dai, Youshan Miao, Ting Cao, Fan Yang, Ningyi Xu

Abstract

As Deep Neural Network (DNN) models scale to billions of parameters, GPU memory capacity has become the primary bottleneck for training. While techniques like Gradient Accumulation (GA) and Gradient Release (GR) have been developed to mitigate memory pressure, they are fundamentally incompatible: GA preserves gradients to simulate large batch sizes, while GR seeks to delete them immediately to save space. We introduce Adam Accumulation (AdamA), a novel optimizer modification that resolves this contradiction. By integrating gradients directly into optimizer states ($m$ and $v$) as they are computed, AdamA enables the simultaneous reduction of activation and gradient memory. Our evaluation shows that AdamA reduces memory footprints by up to 23% and allows for training models up to 3.14x larger than standard baselines with negligible impact on throughput and no loss in convergence accuracy.

Introduction

The training of massive DNNs is often a battle against the physical limits of hardware. To manage memory, researchers typically rely on two strategies. Gradient Accumulation (GA) splits a large mini-batch into smaller micro-batches, calculating gradients for each sequentially to save on activation memory. Gradient Release (GR), on the other hand, frees up gradient memory layer-by-layer during the backward pass.

However, these two methods cannot be used effectively together. GA requires the gradients of every micro-batch to be stored until the final micro-batch is processed so they can be summed. Conversely, GR aims to discard gradients as soon as a layer's backward pass is complete. Because activations typically consume more memory, practitioners have historically prioritized GA, accepting the high memory cost of stored gradients. As models continue to grow, this gradient memory overhead is no longer negligible.

The AdamA Method

AdamA (Adam Accumulation) redefines the interaction between the gradient calculation and the optimizer update. In a standard Adam optimizer, the system waits for the total accumulated gradient of a mini-batch before updating the first-moment ($m$) and second-moment ($v$) states.

AdamA shifts this logic to an incremental update strategy:

  1. Immediate Integration: As soon as a micro-batch gradient is calculated for a specific layer, it is immediately "folded" into the optimizer’s $m$ and $v$ buffers.
  2. Immediate Release: Once the gradient information is integrated into the optimizer state, the gradient tensor is deleted. This eliminates the need to preserve a separate, massive gradient buffer throughout the accumulation cycle.
  3. Distributed Consistency: In multi-GPU environments, AdamA maintains efficiency by all-reducing the optimizer states at the end of the mini-batch rather than communicating gradients for every micro-batch. This ensures communication overhead remains consistent with standard distributed training.

Experimental Validation

To ensure AdamA is a robust, drop-in replacement for standard Adam, the researchers conducted extensive testing across multiple domains:

  • Natural Language Processing: BERT-Large (pre-training) and the GLUE benchmark, as well as a scaled BERT-4B (4 billion parameters) to test memory limits.
  • Computer Vision: ImageNet-1K training using ResNet-50, ResNet-101, and EfficientNet-B7.
  • Convergence Analysis: CIFAR-100 was utilized to verify that the sequential accumulation logic did not negatively impact the optimizer's convergence properties.

Mathematically, the authors demonstrated that while the update to the second moment ($v$) differs slightly—accumulating the squares of micro-batch gradients rather than the square of the total sum—the impact on training stability and final accuracy is negligible.

Key Results and Scaling

AdamA demonstrates significant improvements in both memory efficiency and model scalability:

  • Memory Footprint: AdamA achieved up to a 23% reduction in total memory usage compared to standard gradient accumulation. For the BERT-4B model, this saved over 20 GB of VRAM.
  • Model Scaling: When combined with existing frameworks like DeepSpeed ZeRO, AdamA allowed a standard DGX A100 system to fit models 1.26x to 3.14x larger than PyTorch and DeepSpeed baselines.
  • Throughput and Accuracy: The computational overhead of updating optimizer states more frequently is minimal, with training throughput degradation staying below 2%. Furthermore, AdamA reached identical accuracy levels to standard Adam across all NLP and Vision benchmarks.

Conclusion

AdamA provides a simple yet effective solution to the memory contradiction in large-scale training. By treating the optimizer state as the primary accumulator for gradient information, it unlocks the ability to use Gradient Accumulation and Gradient Release simultaneously. This approach is highly complementary to existing distributed training optimizations and offers a clear path for researchers to train larger models on existing hardware infrastructure.

Summary updated

BibTeX
@inproceedings{zhang2023adam,
  author = {Yijia Zhang and Yibo Han and Shijie Cao and Guohao Dai and Youshan Miao and Ting Cao and Fan Yang and Ningyi Xu},
  title = {{Adam Accumulation to Reduce Memory Footprints of both Activations and Gradients for Large-scale DNN Training}},
  booktitle = {ECAI},
  year = {2023},
  doi = {10.3233/faia230623},
}
Figure