Large Product Key Memory for Pretrained Language Models

Gyuwan Kim, Tae-Hwan Jung

Abstract

Product key memory (PKM) proposed by Lample et al. (2019) enables to improve prediction accuracy by increasing model capacity efficiently with insignificant computational overhead. However, their empirical application is only limited to causal language modeling. Motivated by the recent success of pretrained language models (PLMs), we investigate how to incorporate large PKM into PLMs that can be finetuned for a wide variety of downstream NLP tasks. We define a new memory usage metric, and careful observation using this metric reveals that most memory slots remain outdated during the training of PKM-augmented models. To train better PLMs by tackling this issue, we propose simple but effective solutions: (1) initialization from the model weights pretrained without memory and (2) augmenting PKM by addition rather than replacing a feed-forward network. We verify that both of them are crucial for the pretraining of PKM-augmented PLMs, enhancing memory utilization and downstream performance.

Introduction

In deep learning, increasing model capacity typically leads to better performance but at a significant computational cost. Product Key Memory (PKM) was introduced to break this link, allowing models to access billions of parameters via efficient nearest-neighbor search with minimal extra compute. While successful in causal language modeling, PKM has struggled to improve downstream performance in pretrained models like BERT. This paper identifies "catastrophic drift" as the primary obstacle: sparse updates cause memory slots to become "stale," leading the model to ignore its extra capacity and resulting in wasted parameters.

Methods: Overcoming Catastrophic Drift

To address the stability and utilization issues of PKM in PLMs, the authors propose two primary modifications to the standard integration:

  1. Initialization from Pretrained Weights: Instead of training a PKM-augmented model from scratch, the process begins with a standard pretrained BERT model. Memory layers are added subsequently, ensuring that the queries sent to the memory are already semantically meaningful, which prevents the memory from getting lost in noise early in training.
  2. Residual Memory (ResM): Traditionally, PKM layers replaced the standard Feed-Forward Networks (FFN) in a Transformer block. The authors argue this is too disruptive. Instead, they keep the FFN and add the PKM layer in parallel as a residual connection: $x' = LN(x + FFN(x) + PKM(x))$. This "ResM" approach allows the model to rely on the stable FFN while gradually learning to incorporate the high-capacity memory.
Comparison of FFN, PKM, and the proposed ResM layer architectures.

Key Insights and Results

The authors introduced a "Top-1" usage metric to track how often a memory slot is the best match for a query. In vanilla PKM, utilization was found to be as low as 2% in certain layers. The proposed methods (Initialization + ResM) boosted this utilization to over 95%, effectively activating the model's latent capacity.

Memory usage distribution over training steps for different configurations.

Performance and Efficiency

  • Downstream Tasks: On the GLUE benchmark, a BERT-base model augmented with ResM (515M parameters) achieved an average score of 85.3, matching the performance of the much deeper BERT-large model (340M parameters).
  • Inference Speed: Despite having more parameters, BERT-base + ResM is significantly faster (59.3 batch/sec) than BERT-large (43.1 batch/sec) because it maintains the shallower 12-layer architecture of BERT-base.
  • Model Compression: The method also benefits compressed models. Adding ResM to DistilBERT improved its SQuAD 1.1 F1 score from 85.7 to 88.3, bringing it much closer to full BERT-base performance.

Conclusion

By addressing the issue of catastrophic drift through proper initialization and a residual architecture, this work demonstrates that large-scale memory can be effectively integrated into pretrained language models. This approach provides a path toward scaling model capacity without the linear increase in computational cost typically associated with deeper or wider architectures, making high-capacity models more accessible for downstream NLP tasks.

Summary updated

BibTeX
@inproceedings{kim2020large,
  author = {Gyuwan Kim and Tae-Hwan Jung},
  title = {{Large Product Key Memory for Pretrained Language Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  doi = {10.18653/v1/2020.findings-emnlp.362},
}
Figure