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

TL;DR

Training massive Deep Neural Networks (DNNs) is often a battle against limited GPU memory. This paper introduces AdamA (Adam Accumulation), a novel optimizer modification that resolves a long-standing contradiction between two popular memory-saving techniques: gradient accumulation and gradient release. By integrating gradients directly into optimizer states as they are computed, AdamA reduces memory footprints by up to 23% and enables training models up to 3.14x larger than standard baselines with negligible impact on speed or accuracy.

What Problem Does This Paper Address?

In the world of large-scale AI, memory is the ultimate bottleneck. Researchers typically use two tricks to fit big models on GPUs:

  1. Gradient Accumulation (GA): Splits a large "mini-batch" into smaller "micro-batches" to save memory on activations (the intermediate outputs of layers).
  2. Gradient Release (GR): Frees up gradient memory layer-by-layer as soon as the backward pass for that layer is finished.

The problem? These two methods are fundamentally incompatible. Gradient accumulation requires you to keep the gradients of every micro-batch around until the very last one is finished so they can be summed up. Gradient release wants to delete them immediately. Because activations usually take up more space, researchers have historically chosen GA and just accepted the high gradient memory cost. As models scale to billions of parameters, however, the gradient memory itself becomes too large to ignore.

Methods

The authors propose AdamA, which changes when the optimizer does its work.

In standard Adam, you accumulate all gradients for a mini-batch and then update the optimizer's "states" ($m$ for momentum and $v$ for the squared gradients). In AdamA, the optimizer states are updated sequentially over micro-batches.

Specifically:

  • Immediate Integration: As soon as a micro-batch gradient is calculated for a layer, it is "folded" into the $m$ and $v$ buffers.
  • Immediate Release: Once the gradient is integrated into the optimizer state, the gradient tensor is deleted. This resolves the contradiction: you don't need to "preserve" the gradient because its information is already safely stored in the optimizer's memory.
  • Distributed Strategy: In multi-GPU setups, instead of communicating (all-reducing) gradients, AdamA all-reduces the optimizer states at the end of the mini-batch. This keeps communication overhead low and consistent with standard training.

Datasets

The researchers validated AdamA across a variety of standard benchmarks to ensure it didn't break model performance:

  • NLP: BERT-Large (pre-training on English Wikipedia and BooksCorpus) and fine-tuning on the GLUE benchmark. They also tested a scaled-up BERT-4B (4 billion parameters).
  • Vision: ImageNet-1K using ResNet-50, ResNet-101, and EfficientNet-B7.
  • Convergence Testing: CIFAR-100 was used for fine-grained tracking of the optimizer's behavior.

Key Insights and Ideas

  • The "Aha" Moment: The researchers realized that the optimizer state is essentially a "running summary" of gradient information. By treating the optimizer state as the primary accumulator, they eliminated the need for a separate, massive gradient buffer.
  • Mathematical Equivalence: A major contribution is the proof that AdamA yields the same convergence properties as standard Adam. While the update to the second moment ($v$) is slightly different (accumulating squares of micro-batch gradients vs. the square of the total sum), the authors demonstrate both theoretically and empirically that this difference is negligible.
  • Complementary Nature: AdamA isn't meant to replace existing tools like DeepSpeed's ZeRO; it’s designed to work with them. By combining AdamA with ZeRO-DP, the authors pushed the limits of model size further than either could achieve alone.

Key Results

  • Memory Savings: AdamA achieved up to a 23% reduction in total memory footprint compared to standard gradient accumulation. On a BERT-4B model, this translated to saving over 20 GB of VRAM when combined with other optimizations.
  • Model Scaling: Using AdamA allowed a standard DGX A100 system to fit models 1.26x to 3.14x larger than the PyTorch and DeepSpeed baselines.
  • Throughput: The "cost" of this memory saving is incredibly low. The training speed (throughput) degradation was less than 2% in most scenarios.
  • Accuracy: In all tests (GLUE tasks for NLP and ImageNet for Vision), AdamA reached the same accuracy levels as the standard Adam optimizer, proving it is a "drop-in" replacement for large-scale training.

Limitations and Future Work

  • Optimizer Specificity: The current implementation is specifically tailored for Adam and momentum-based optimizers. While these are the industry standards, the method would need adaptation for more exotic optimization algorithms.
  • Communication Volume: In distributed settings, all-reducing optimizer states (which are often 2x the size of gradients) could theoretically increase network traffic. However, the authors argue that because this happens only once per mini-batch, the impact is minimal.
  • Future Directions: The authors suggest exploring how this "accumulation-in-optimizer" logic could be applied to other memory-intensive parts of the training pipeline, potentially leading to even more compact training configurations.

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},
}

Loading related content...

Figure