GPU Memory Usage Optimization for Backward Propagation in Deep Network Training

Ding-Yong Hong, Tzu-Hsien Tsai, Ning Wang, Pangfeng Liu, Jan-Jan Wu

Introduction

As Deep Neural Networks (DNNs) grow in complexity and depth, they increasingly encounter a hard physical constraint: GPU memory. During the training process, a model generates intermediate data, known as activations, during the forward pass. These activations must be stored because they are essential for calculating gradients during the subsequent backward pass. For massive models or large batch sizes, storing all intermediate activations often leads to "Out of Memory" (OOM) errors, halting the training process entirely.

The Memory-Compute Trade-off

A common strategy to mitigate this issue is rematerialization, also known as checkpointing. Instead of saving every activation, the system saves only a subset of "checkpoints." Missing activations are then recomputed on the fly during the backward pass. While this saves memory, it introduces a computational overhead. The core challenge lies in the "Checkpoint Selection Problem": identifying the mathematically optimal set of layers to checkpoint to minimize peak memory usage without making training prohibitively slow.

Methods: Aligning Theory with Framework Reality

Previous attempts to solve the checkpoint selection problem often relied on simple heuristics or computationally expensive algorithms. Furthermore, many theoretical models failed to account for the actual memory management behavior of modern deep learning frameworks like PyTorch.

Algorithm 1: Standard Neural Network Training process highlighting forward and backward phases.

By tracing PyTorch’s execution, researchers identified two critical discrepancies that previous models ignored:

  1. Early Release: PyTorch does not retain all checkpoints indefinitely; it releases them as soon as they are no longer required for gradient computation.
  2. Gradient Buffers: Frameworks must allocate memory for the gradients themselves ($r_i$), a factor often overlooked in earlier optimization models.

By incorporating these real-world constraints, the researchers developed a refined model. They initially improved the standard dynamic programming approach from $O(n^3 \log n)$ to $O(n^3)$. However, the most significant breakthrough came from identifying a monotonic property in the optimization function: the index yielding minimum memory usage for a given layer is always less than or equal to the index for the subsequent layer. This discovery allowed the development of a linear-time ($O(n)$) algorithm using a monotonic queue.

Key Results and Evaluation

The proposed algorithm was evaluated using standard computer vision benchmarks, specifically VGG-19 and AlexNet on the ImageNet dataset, using NVIDIA GeForce RTX 3090 hardware.

  • Memory Efficiency: For VGG-19 with a batch size of 128, the new algorithm achieved a 23% reduction in peak memory usage compared to the classic sublinear $O(\sqrt{n})$ method (6,444 MiB vs. 8,404 MiB).
  • Increased Capacity: The optimization enabled larger batch sizes. On VGG-19, the new method supported a batch size of 400, whereas the default PyTorch implementation and the $O(\sqrt{n})$ method suffered OOM errors at 320 and 384, respectively.
  • Computational Speed: The optimization process itself is extremely efficient, taking only 1.1 milliseconds to find the optimal checkpoint subset for VGG-19. While checkpointing adds roughly 33% more time per batch due to recomputation, this is a necessary trade-off for training models that would otherwise exceed memory limits.

Conclusion and Future Work

This research demonstrates that aligning theoretical optimization with the specific memory management logic of deep learning frameworks can yield significant performance gains. The jump from cubic to linear-time complexity makes this approach highly scalable for very deep networks. Future work aims to generalize this $O(n)$ approach from linear feedforward chains to arbitrary computation graphs (ACGs) with complex branching, and to further investigate hardware-level "preserved memory" to achieve even tighter memory bounds.

Summary updated

BibTeX
@article{hong2025gpu,
  author = {Ding-Yong Hong and Tzu-Hsien Tsai and Ning Wang and Pangfeng Liu and Jan-Jan Wu},
  title = {{GPU Memory Usage Optimization for Backward Propagation in Deep Network Training}},
  journal = {J. Parallel Distributed Comput.},
  year = {2025},
}
Figure