Dynamical Mean-Field Theory of Self-Attention Neural Networks
Ángel Poc-López, Miguel Aguilera
TL;DR
The paper tackles the problem of understanding transformer dynamics by mapping self-attention to an asymmetric Hopfield network and formulating a nonequilibrium dynamical mean-field theory that uses a generating functional $Z(g)$, exact in the large-$N$ limit. With 1-bit token encodings, it derives closed-form mean-field updates for overlaps $m^\alpha_{a,t}$ and normalized attentions $\hat{A}^a_t$ and discusses a simplified softmax output. It observes nonequilibrium phase transitions leading to periodic, quasi-periodic, and chaotic attractors, with memory effects extending beyond the short context window. The approach promises interpretability benefits and potential reductions in training cost and can be extended to more realistic transformer settings and finite-size corrections.
Abstract
Transformer-based models have demonstrated exceptional performance across diverse domains, becoming the state-of-the-art solution for addressing sequential machine learning problems. Even though we have a general understanding of the fundamental components in the transformer architecture, little is known about how they operate or what are their expected dynamics. Recently, there has been an increasing interest in exploring the relationship between attention mechanisms and Hopfield networks, promising to shed light on the statistical physics of transformer networks. However, to date, the dynamical regimes of transformer-like models have not been studied in depth. In this paper, we address this gap by using methods for the study of asymmetric Hopfield networks in nonequilibrium regimes --namely path integral methods over generating functionals, yielding dynamics governed by concurrent mean-field variables. Assuming 1-bit tokens and weights, we derive analytical approximations for the behavior of large self-attention neural networks coupled to a softmax output, which become exact in the large limit size. Our findings reveal nontrivial dynamical phenomena, including nonequilibrium phase transitions associated with chaotic bifurcations, even for very simple configurations with a few encoded features and a very short context window. Finally, we discuss the potential of our analytic approach to improve our understanding of the inner workings of transformer models, potentially reducing computational training costs and enhancing model interpretability.
