CNN with large memory layers

Rasul Karimov, Yury Malkov, Karim Iskakov, Victor LempitskyarXiv 2021

In the quest for more powerful neural networks, the standard playbook is simple: add more layers. However, this brute-force scaling leads to a quadratic surge in training costs. What if we could increase a model's capacity by millions of parameters without a proportional explosion in computation?

This thesis, authored by Rasul Karimov at the Skolkovo Institute of Science and Technology, explores the adaptation of Product Key Memory (PKM)—a technique originally designed to scale massive language models like BERT—to the world of Computer Vision.

TL;DR

This work adapts product key memory layers to CNNs, allowing models to access massive parameter banks with high efficiency. By introducing a novel "re-initialization trick" to prevent memory cells from going "dead" during training, the author demonstrates significant accuracy gains in image classification and camera relocalization tasks.

What Problem Does This Paper Address?

Deep learning models face a fundamental scalability bottleneck: in a standard architecture, every input must interact with every parameter. As datasets grow, we want models with higher capacity, but increasing the parameter count usually makes training and inference prohibitively slow.

While "sparse" methods (like Mixture of Experts) exist to let inputs only activate a subset of the network, they are notoriously difficult to optimize on GPUs and often suffer from the "dying neuron" problem, where certain parts of the network stop receiving gradients and become useless. Karimov tackles these issues by bringing efficient memory lookups to vision tasks and proposing a fix for underutilized memory cells.

Methods

The core of the approach is the Product Key Memory layer. Instead of a standard dense layer, the network generates a "query" that looks up the most relevant "values" from a massive external memory.

  • Product Keys for Efficiency: To avoid the high cost of searching through millions of keys, the keys are decomposed into a Cartesian product of two smaller sets ($K_1 \times K_2$). This allows the model to search a memory of size $N$ with a complexity of only $O(\sqrt{N})$.
  • The Re-initialization Trick: This is the paper's primary contribution. During training, many memory keys often become "dead"—they are never selected and thus never learn. The author introduces a mechanism that identifies these underutilized keys, removes them, and re-spawns new keys by sampling from "successful" keys and adding a small amount of Gaussian noise.
  • Integration: The memory layers were integrated into standard architectures like ResNet by replacing or augmenting Bottleneck and Squeeze-and-Excitation (SE) blocks.

Datasets

The author evaluated the approach across several domains:

  • CIFAR-10 & ImageNet-2012: Standard benchmarks for image classification and reconstruction.
  • King’s College Dataset: Used for 6-DOF camera relocalization (determining a camera's exact position and orientation from a single image).
  • Toy Random Labels: A synthetic dataset used to test the "memorization" capacity of the memory layers.

Key Insights and Ideas

  • Breaking the "Dying Key" Cycle: Without re-initialization, memory utilization in vision tasks was abysmal (often 1-2%). With the re-initialization trick, utilization jumped to 60-75%, proving that active management of sparse parameters is essential for vision models.
  • Memorization vs. Generalization: The memory layer is a "powerful memorizer." It could perfectly fit a dataset with completely random labels. However, in relocalization tasks, the model didn't just memorize; it showed spatial correlation, meaning it learned to associate specific memory cells with specific physical locations in the environment.
  • The GPU Mismatch: A fascinating "aha moment" was the realization that while memory layers reduce total FLOPs (floating-point operations), they can actually be slower on current GPUs. This is because GPUs are optimized for massive matrix multiplications, not the "random access" patterns required by sparse memory lookups.

Key Results

  • Classification Boost: On CIFAR-10, a ResNet-20 augmented with the memory/re-initialization trick achieved 93.51% top-1 accuracy, outperforming the baseline ResNet-20 (92.73%) and nearly matching the performance of the much deeper ResNet-110.
  • Relocalization Accuracy: In the PoseNet experiments (King's College dataset), the memory-augmented model significantly reduced training loss and improved translation/rotation accuracy compared to the baseline.
  • Reconstruction: In autoencoder tasks, adding memory layers led to a steady decline in reconstruction error, capturing finer details that the baseline model missed.

Limitations and Future Work

Despite the accuracy gains, the author notes several hurdles:

  • Hardware Bottlenecks: The current implementation suffers from increased inference time due to how modern GPUs handle random memory access. Future work could involve custom CUDA kernels to optimize these lookups.
  • Regularization: Standard techniques like Dropout performed poorly with memory layers. The author suggests that more elaborate, specialized regularization strategies are needed to prevent overfitting.
  • Hyperparameter Sensitivity: The performance is highly dependent on the "temperature" of the similarity search ($\alpha$) and the frequency of the re-initialization schedule, which currently requires careful manual tuning.

Summary updated

Abstract

This work is centred around the recently proposed product key memory structure \cite{large_memory}, implemented for a number of computer vision applications. The memory structure can be regarded as a simple computation primitive suitable to be augmented to nearly all neural network architectures. The memory block allows implementing sparse access to memory with square root complexity scaling with respect to the memory capacity. The latter scaling is possible due to the incorporation of Cartesian product space decomposition of the key space for the nearest neighbour search. We have tested the memory layer on the classification, image reconstruction and relocalization problems and found that for some of those, the memory layers can provide significant speed/accuracy improvement with the high utilization of the key-value elements, while others require more careful fine-tuning and suffer from dying keys. To tackle the later problem we have introduced a simple technique of memory re-initialization which helps us to eliminate unused key-value pairs from the memory and engage them in training again. We have conducted various experiments and got improvements in speed and accuracy for classification and PoseNet relocalization models. We showed that the re-initialization has a huge impact on a toy example of randomly labeled data and observed some gains in performance on the image classification task. We have also demonstrated the generalization property perseverance of the large memory layers on the relocalization problem, while observing the spatial correlations between the images and the selected memory cells.
BibTeX
@misc{karimov2021cnn,
  author = {Rasul Karimov and Yury Malkov and Karim Iskakov and Victor Lempitsky},
  title = {{CNN with large memory layers}},
  year = {2021},
  eprint = {2101.11685},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2101.11685},
}
Figure