Adam Optimizer › Memory Implications for Large Model Training

Michael BrenndoerferApril 24, 20252 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 68Adam Optimizer › Memory Implications for Large Model Training
Reading section 15 of 18 · Memory Implications for Large Model Training · 2 minSection 15 of 18 · 2 min

Book contents

Section 15 of 18 · 2 min read

Adam Optimizer › Memory Implications for Large Model TrainingOne section · Sections in this chapter15 / 18 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

At large scale, Adam's memory requirements become a significant engineering constraint. Consider a language model with NN parameters. A standard training setup in float32 requires:

  • NN floats for the model parameters themselves
  • NN floats for the parameter gradients (computed during backpropagation)
  • 2N2N floats for the Adam first and second moments

The total is 4N4N floats, four times the model's parameter count. For float32 training, each float is 4 bytes, so a 7 billion parameter model requires 4×7×109×4=1124 \times 7 \times 10^9 \times 4 = 112 GB of memory just for the training state. This far exceeds the capacity of any single GPU (which typically has 40-80 GB of HBM memory), requiring distributed training across many devices.

Several strategies reduce this memory footprint:

ZeRO (Zero Redundancy Optimizer) from Microsoft DeepSpeed shards the optimizer state, gradients, and parameters across all GPUs in a distributed training job. In the most aggressive mode (ZeRO-3), each GPU holds only 1/NGPU1/N_{\text{GPU}} of the model weights, gradients, and Adam moments. The memory per GPU scales inversely with the number of GPUs, making it possible to train models far larger than any single GPU's capacity.

8-bit Adam (Dettmers et al., 2022, available via the bitsandbytes library) quantizes the optimizer states to 8-bit integers, reducing the 8 bytes per parameter for Adam state (two float32 tensors) to 2 bytes per parameter. The quantization is done with a dynamic block-wise scheme that preserves the optimizer's behavior almost exactly, with negligible accuracy loss. This is perhaps the most practical approach for single-GPU training of large models.

Mixed precision training uses float16 for the forward and backward passes (saving memory on activations and intermediate computations) while keeping the optimizer state and master copy of the weights in float32. The Adam step itself is computed in float32 and then cast back to float16 for the next forward pass. This is the standard approach for training transformers on modern hardware and roughly halves memory usage compared to full float32 training.