We study the dynamical behavior of tokens in transformers from a control-theoretic perspective. Our model includes the feed-forward layer present after the self-attention mechanism, with the self-attention mechanism interpreted as an interacting particle system and the feed-forward layer as an independent control. Our main theoretical result establishes that the feed-forward network can steer the tokens arbitrarily close to consensus regardless of the key, query, and value matrices. Our result are easily extended to convergence to many clusters and to multi-head attention. We conduct numerical experiments to verify our results, and compare thresholding behavior from our theory to real-world LLMs.
Figures & tables
Figure 1: Setup 1 with A=I and V=J under softmax-normalized attention. Left: mean pairwise similarity R1 as a function of k/k∗ . Middle: mean distance to the target x0 . Right: zoomed in mean distance to the target x0 around k/k∗∈[0.9,1.1] . The vertical line marks k/k∗=1 . Experiment parameters: d=10 , n=100 , tfinal=30 , β=1 , dt=0.001 .
Figure 2: Setup 2, random Gaussian A,V . Left: mean pairwise similarity R1 as a function of k/k∗ . Middle: mean distance to the target x0 . Right: zoomed in mean distance to the target x0 around k/k∗∈[0.9,1.1] . The vertical line marks k/k∗=1 . Experiment parameters: d=10 , n=100 , tfinal=10 , β=1 , dt=0.001 .
Figure 3: nanoGPT: measured feed-forward amplitude k^ and softmax attention scale kℓ,raw∗ and accounting for LayerNorm kℓ,norm∗ by layer. White regions signify when the maximum FFN amplitude exceeds attention bound.
Figure 4: Pythia-410M: measured feed-forward amplitude k^ and softmax attention scale kℓ,raw∗ and accounting for LayerNorm kℓ,norm∗ by layer. White regions signify when the maximum FFN amplitude exceeds attention bound..
Figure 5: TinyLlama-1.1B: measured feed-forward amplitude k^ and softmax attention scale kℓ,raw∗ and accounting for RMSNorm kℓ,norm∗ by layer. White regions signify when the maximum FFN amplitude exceeds attention bound.