Beyond Scaling Laws: Understanding Transformer Performance with Associative Memory
Xueyan Niu, Bo Bai, Lei Deng, Wei Han
TL;DR
The paper tackles why scaling up Transformer models does not always yield better performance and posits memorization of training data as a central mechanism. It develops a theory that treats Transformer layers as associative memories via Hopfield networks, using a distance-based layer energy and a global energy across layers constructed through majorization-minimization. A key result is a lower bound on cross-entropy and a predicted quadratic trade-off between model size and data size, $N=O(D^2)$, for well-separated patterns, with empirical evidence from GPT-2, vanilla Transformers, and OpenELM variants. This energy-based perspective links attention to nearest-neighbor retrieval, clarifies when memorization dominates learning, and offers guidance for selecting model/data scales in pre-training, while connecting to Chinchilla scaling and Hopfield innovations in the literature.
Abstract
Increasing the size of a Transformer does not always lead to enhanced performance. This phenomenon cannot be explained by the empirical scaling laws. Furthermore, the model's enhanced performance is closely associated with its memorization of the training samples. We present a theoretical framework that sheds light on the memorization during pre-training of transformer-based language models. We model the behavior of Transformers with associative memories using Hopfield networks, such that each transformer block effectively conducts an approximate nearest-neighbor search. In particular, the energy function in modern continuous Hopfield networks serves as an explanation for the attention mechanism, which we approximate with a distance-based energy function. By observing that the softmax function corresponds to the gradient of the LogSumExp function in the energy, and employing the majorization-minimization technique, we construct a global energy function designed to capture the layered architecture. We demonstrate a dependency between the model size and the dataset size for the model to achieve optimal performance, and we show that the achievable cross-entropy loss is bounded from below.
