Memory-Efficient Implementation of DenseNets

Geoff Pleiss, Danlu Chen, Gao Huang, Tongcheng Li, Laurens van der Maaten, Kilian Q. WeinbergerarXiv 2017

Introduction

Dense Convolutional Networks (DenseNets) have emerged as a highly parameter-efficient architecture for deep learning. By connecting each layer to every subsequent layer in a feed-forward fashion, DenseNets promote extensive feature reuse and alleviate the vanishing-gradient problem. This connectivity pattern allows DenseNets to achieve competitive performance on benchmarks like ImageNet and CIFAR with significantly fewer parameters than traditional architectures like ResNets.

DenseNet architecture illustrating the dense connectivity where each layer receives feature maps from all preceding layers.

The Memory Bottleneck

Despite their parameter efficiency, standard implementations of DenseNets suffer from excessive GPU memory consumption. In typical deep learning frameworks, intermediate feature maps—specifically the outputs of concatenation and pre-activation batch normalization—are stored in memory during the forward pass to facilitate gradient computation during backpropagation.

Because each layer in a DenseNet concatenates features from all previous layers, the total number of feature maps grows linearly with depth. Storing these maps for every layer leads to a quadratic $O(m^2)$ explosion in memory usage relative to the network depth $m$. This bottleneck historically limited DenseNets to approximately 160 layers on standard 12 GB GPUs, preventing the exploration of much deeper and more powerful models.

Proposed Efficient Implementation

The authors address this limitation by recognizing that the operations responsible for memory bloat—concatenation and batch normalization—are computationally inexpensive. They propose a memory-efficient implementation based on two key strategies: Shared Memory Allocations and On-the-fly Recomputation.

Comparison between naive and efficient implementations, highlighting the use of shared memory storage and memory pointers to reduce total allocation.
  1. Shared Storage for Forward Pass: Instead of allocating unique memory for every layer's intermediate outputs, the implementation uses a shared block of memory. During the forward pass, each layer writes its concatenated and normalized features into this shared space, overwriting previous data that is no longer immediately needed.
  2. On-the-Fly Recomputation: To compute gradients during the backward pass, the network re-calculates the necessary intermediate features. Since batch normalization and concatenation are fast operations, recomputing them adds only a small computational overhead while drastically reducing the persistent memory footprint.
  3. Shared Gradient Storage: Similar to the forward pass, gradient tensors are stored in shared memory allocations to prevent quadratic scaling of gradient storage.

Experimental Results

The proposed implementation successfully reduces the memory complexity of feature map storage from $O(m^2)$ to $O(m)$. This efficiency gain allows for significantly deeper models within the same hardware constraints. For instance, while a naive implementation maxes out at 160 layers on a 12 GB GPU, the efficient version can accommodate a 340-layer model—representing a 2.5x increase in depth and a 6x increase in parameters.

The computational cost of this memory saving is minimal. The recomputation strategy introduces only a 15% to 20% increase in training time per minibatch across frameworks like LuaTorch and PyTorch. Leveraging this efficiency, the authors trained a 264-layer DenseNet with 73 million parameters, achieving a state-of-the-art top-1 error of 20.26% on ImageNet, surpassing models like ResNeXt.

Conclusion

This work demonstrates that the quadratic memory scaling of DenseNets was an implementation artifact rather than an inherent architectural flaw. By trading a small amount of compute time for substantial memory savings, the proposed strategy enables the training of extremely deep DenseNets on standard hardware. This approach removes the primary barrier to scaling DenseNet architectures, paving the way for further advances in high-capacity, parameter-efficient deep learning models.

Summary updated

BibTeX
@misc{pleiss2017memory,
  author = {Geoff Pleiss and Danlu Chen and Gao Huang and Tongcheng Li and Laurens van der Maaten and Kilian Q. Weinberger},
  title = {{Memory-Efficient Implementation of DenseNets}},
  year = {2017},
  eprint = {1707.06990},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1707.06990},
}
Figure