betaFeedback

WorksComputer Science

Asymptotic Behavior of Transformers

Abstract

In this paper we study the behavior of transformer networks generating text over long periods of time. We show that even a three-token, single-layer attention-only transformer can fail to converge. We then study a rich class of transformers with arbitrary finite depth, layer normalization, MLPs, RoPE encodings, and an arbitrary mix of local and global layers. Every transformer in this class has a softmax temperature threshold above which its empirical cache distribution converges to a unique limit, independent of initial conditions. We show further that, while each transformer has a temperature threshold, the supremum of this set is infinite, so there is no global minimal temperature that forces all transformers to converge.

Introduction

In this paper we study what happens if an autoregressive transformer is allowed to generate for a very long time. Most theoretical analyses of transformers fix the sequence length, or ask how performance changes when the context window is extended ([17, 15, 35]). Here we ask a different question: we fix the model and study the generation process itself as the number of generated tokens tends to infinity.

As a side note, while we think this question is mathematically natural, we are also motivated by the observation that modern models sometimes seem to “lock in” to a particular state ([31, 14]). Sometimes this state is annoyingly bad, such that even with great efforts the model cannot be convinced to let a particular approach or argument go. Other times the state is pleasingly good, perhaps encoding an effective understanding of a problem that represents a useful starting point for many further explorations—in this case we might wish to checkpoint the model in this good state, to use it as a resource. These observations led us to wonder, even without a human in the loop, whether a model might enter a state that continues to influence its behavior forever. This paper provides a partial answer.

Single-Layer Transformers. Our first goal is to understand this question in a simple setting: a single-layer attention-only transformer without positional encodings, MLPs, or normalization ([37, 17, 38]). In this model, different occurrences of the same token are indistinguishable to attention, so the entire history is summarized by the empirical token distribution PtP_t. As tt grows large, the change to the historical distribution in a single step goes to zero; hence, for fixed-size finite windows and sufficiently large tt, we may view the historical state of the model as frozen.

The next token logits depend only on the current token and the history, so freezing the historical distribution at some PP causes the simplified transformer to behave like a finite-state Markov chain with transition matrix MPM_P. The historical distribution will slowly drift towards the steady state of this Markov chain, π∗(P)\pi^{*}(P), but as it does so, the Markov chain itself will evolve, resulting in a new drift direction. We show that the empirical distribution PtP_t tracks the ODE almost surely [2].

dPdt=π∗(P)−P.\frac{dP}{dt} = \pi^{*}(P) - P.

Thus the long-run behavior of this model is described by a deterministic dynamical system, even though the underlying token sequence remains random.

The softmax temperature τ\tau enters this ODE in a particularly simple way. Differentiating the output softmax contributes a factor 1/τ1/\tau, and we use this to show that, for this model, there is a finite temperature above which the map P↦π∗(P)P \mapsto\pi^{*}(P) is a contraction. In this regime the ODE has a unique globally attracting fixed point and PtP_t converges to it almost surely, independently of the initial prompt; as τ→∞\tau\to\infty, this fixed point approaches the uniform distribution. At lower temperatures the ODE description remains valid, but uniqueness of the limiting set is no longer guaranteed; in fact, even this simplified model need not converge.

Multi-Layer Transformers. We next consider fixed-depth transformers, allowing arbitrary mixtures of global and fixed-window local attention layers [1, 42], RoPE positional encodings [34], MLPs, residual connections, and normalization. Here the empirical token distribution is no longer sufficient to describe the history. The key/value vectors stored at a position depend on the context in which that position was generated, so two occurrences of the same token can contribute different entries to the global KV cache.

Nevertheless, each historical position contributes only a fixed-dimensional vector to this cache. We therefore represent the unbounded global cache by the empirical distribution ηt\eta_t of these vectors. The dimension of an individual cache vector depends on the fixed architecture but not on the generation time. In this sense the entire historical state remains fixed-dimensional at each historical position even though the number of stored positions grows without bound.

RoPE position encodings introduce an additional state variable: the current rotation phase. With the global cache frozen at η\eta, the finite local-attention windows imply that only a fixed number WW of recent tokens is needed in addition to the current RoPE phase ω\omega. The resulting process over WW-grams is governed by a sequence of phase-dependent transition matrices Qη,ωQ_{\eta,\omega}.

Again with frozen history η\eta, at any fixed positive temperature, every output token has a probability bounded away from zero. Every WW-gram can be reached from every other in WW steps, and the effect of the initial WW-gram decays geometrically. This gives a unique phase-dependent family πη(ω)\pi_{\eta}(\omega) describing the asymptotic distribution of the recent tokens. We show that this frozen-cache description remains accurate over sufficiently long blocks that the local state at the start of the block is forgotten as the system moves towards the frozen-cache limiting behavior.

The RoPE phase itself does not converge, but the averages along its orbit do. Averaging the phase-dependent local behavior therefore defines a map Γ(η)\Gamma(\eta): the average distribution over all RoPE phases of the next cache vector when the current cache is frozen at η\eta. Since the empirical cache changes by only 1/(t+1)1/(t+1) at each step, a natural time scale for state evolution is

st=∑j=1t1j=log⁡t+O(1).s_t=\sum_{j=1}^{t}\frac{1}{j}=\log t+O(1).

On this scale we obtain the measure-valued ODE

dηds=Γ(η)−η.\frac{d\eta}{ds}=\Gamma(\eta)-\eta.

We prove that the actual empirical cache process almost surely tracks this ODE over every fixed interval of the ss-time scale. Thus the long-run behavior of the full multi-layer transformer is again reduced to a deterministic dynamical system, now over probability distributions on a fixed-dimensional cache space.

This description by itself does not imply convergence: the ODE may (and in fact does) have more complicated non-convergent trajectories. We therefore return to the role of temperature. The feed-forward ordering of transformer layers gives a useful triangular structure: the cache vector written by a global layer can depend only on the caches of earlier global layers. Using a weighted distance across layers, this triangular dependence can be made arbitrarily small. The remaining feedback through token sampling is suppressed by the 1/τ1/\tau derivative of the output softmax. We use these two facts to show that every fixed transformer in our model has a finite temperature threshold above which Γ\Gamma is a contraction. Above this threshold the cache ODE has a unique globally attracting fixed point, and the empirical cache converges to it almost surely.

The threshold, however, cannot be chosen uniformly over all transformers. We give an explicit three-token example showing that even a single-layer, NoPE, attention-only transformer with no MLP can fail to converge almost surely. Moreover, for every finite temperature τ\tau, scaling its output embeddings by τ\tau leaves the next token probabilities unchanged. Thus for every finite temperature there is such a simplified transformer that fails to converge, even though every fixed transformer converges once its temperature is sufficiently large.

The order of quantifiers is important. For every fixed transformer, sufficiently high temperature forces convergence; but for every fixed finite temperature there is some transformer that fails to converge. Hence there is no universal finite temperature that guarantees convergence over the entire class.

Our results therefore give two complementary descriptions of long-generation behavior. First, slowly changing empirical state turns the stochastic generation process into a deterministic ODE on an appropriate time scale. Second, sufficiently high temperature controls the feedback in this ODE and forces convergence for each fixed model, while no single temperature can do so uniformly for all models.

Background

Throughout the paper, Σ\Sigma denotes a finite vocabulary with ∣Σ∣=V|\Sigma|=V, and xt∈Σx_t\in\Sigma is the token generated at time tt. Let Ft\mathcal{F}_t denote the information contained in the generated history (x1,…,xt)(x_1,\ldots,x_t), and let τ>0\tau>0 denote the sampling temperature. We write ΔV−1\Delta^{V-1} for the probability simplex.

For vectors, ⟨⋅,⋅⟩\langle\cdot,\cdot\rangle and ∥⋅∥\|\cdot\| denote the Euclidean inner product and norm; for matrices, ∥⋅∥\|\cdot\| denotes the induced operator norm. For distributions μ,ν\mu,\nu, ∥μ−ν∥tv:=sup⁡A∣μ(A)−ν(A)∣\|\mu-\nu\|_{\mathrm{tv}}:=\sup_A|\mu(A)-\nu(A)| denotes the total variation distance, and d1(μ,ν):=sup⁡Lip⁡(φ)≤1∣∫φ dμ−∫φ dν∣d_1(\mu,\nu):=\sup_{\operatorname{Lip}(\varphi)\leq1}\left|\int\varphi\,d\mu-\int\varphi\,d\nu\right| denotes the 1-Wasserstein distance. Two distances on distributions are equivalent if they differ by at most constant factors. We use δ⋅\delta_{\cdot} for the Kronecker delta and δz\delta_z for the unit point mass at zz.

Stochastic Approximation. We repeatedly use the dynamical systems approach to stochastic approximation of Benaïm [2]. Informally speaking, for an update of the form

Xt+1=Xt+γt(F(Xt)+noise),X_{t+1} = X_t + \gamma_t\left(F(X_t) + \text{noise}\right),

where the step sizes γt\gamma_t are decreasing and satisfy ∑tγt=∞\sum_t \gamma_t = \infty and ∑tγt2<∞\sum_t \gamma_t^2 < \infty, the process, viewed on the accumulated time scale st=∑j<tγjs_t = \sum_{j<t} \gamma_j, tracks the ODE dX/ds=F(X)\mathrm{d}X/\mathrm{d}s = F(X) over every fixed interval of ss-time. Under the usual boundedness and noise conditions, its limiting set is an internally chain transitive (ICT)1 set of this ODE. We use this framework in § 3 to obtain the ODE for the empirical token distribution, and in § 5 to obtain the analogous ODE for the empirical cache distribution. Once the corresponding ODE has a unique globally attracting fixed point, this tracking gives convergence of the stochastic process. We also use Benaïm’s result that stochastic approximation does not converge to a linearly unstable equilibrium under nondegenerate noise in § 6.

Single-Layer Transformer

In this section we study a simple transformer model. The model has a single layer with one attention head, and lacks positional embeddings (NoPE), layer normalization, and MLPs. Let dd be the hidden dimension. The model is parameterized by fixed input and output embedding matrices Ein,Eout∈RV×dE_{\mathrm{in}}, E_{\mathrm{out}} \in\mathbb{R}^{V \times d}, and standard attention projection matrices WQ,WK,WV∈Rd×dW_Q, W_K, W_V \in\mathbb{R}^{d \times d}.

At step tt, the state is given by the current token xtx_t and the historical context. With NoPE, attention to each token of the history is independent of the token’s location and so, the history is captured by the empirical distribution Pt∈ΔV−1P_t \in\Delta^{V-1}, where Pt(v)P_t(v) is the frequency of token vv up to time tt.

For a query token uu and key/value token ww, the unnormalized attention score is su,w=1d⟨(Ein[u]WQ),(Ein[w]WK)⟩s_{u,w} = \frac{1}{\sqrt{d}}\langle(E_{\mathrm{in}}[u]W_Q),(E_{\mathrm{in}}[w]W_K)\rangle. The attention weight that uu pays to ww over history PtP_t is:

αu,w(Pt)=Pt(w)exp⁡(su,w)Zu(Pt),where\alpha_{u,w}(P_t) = \frac{P_t(w)\exp(s_{u,w})}{Z_u(P_t)}, \qquad\text{where}
Zu(Pt)=∑w=1VPt(w)exp⁡(su,w).(1)Z_u(P_t) = \sum_{w=1}^{V} P_t(w)\exp(s_{u,w}). \tag*{(1)}

Let ϕw=Ein[w]WV\phi_w = E_{\mathrm{in}}[w]W_V denote the value vector for token ww. The self-attention output is ou(Pt)=∑w=1Vαu,w(Pt)ϕwo_u(P_t) = \sum_{w=1}^{V}\alpha_{u,w}(P_t)\phi_w. The probability of generating the next token ww given query uu and history PtP_t, sampled at temperature τ>0\tau> 0, defines the transition matrix MPt∈RV×VM_{P_t} \in\mathbb{R}^{V \times V} (see Figure 1):

Full-sequence attention model

Figure 1. A stripped-down model of a transformer with NoPE, no MLPs, and an unbounded context window parameterized by historical distribution PtP_t.

MPt(u,w)=exp⁡(⟨ou(Pt),Eout[w]⟩/τ)∑w′=1Vexp⁡(⟨ou(Pt),Eout[w′]⟩/τ).M_{P_t}(u,w) = \frac{\exp\left(\langle o_u(P_t),E_{\mathrm{out}}[w]\rangle/\tau\right)}{\sum_{w'=1}^{V}\exp\left(\langle o_u(P_t),E_{\mathrm{out}}[w']\rangle/\tau\right)}.

Limiting Dynamics

We first describe the asymptotic evolution of the empirical distribution PtP_t by an ordinary differential equation (ODE). Observe that PtP_t updates iteratively as:

Pt+1(v)=Pt(v)+1t+1(I(xt+1=v)−Pt(v)).P_{t+1}(v) = P_t(v) + \frac{1}{t+1}\left(\mathbb{I}(x_{t+1}=v)-P_t(v)\right).

To analyze the long-run behavior of PtP_t, we appeal to the theory of stochastic approximation. To show that the discrete stochastic process tracks a deterministic limiting ODE, we verify the standard conditions for stochastic approximation [2]:

  1. Step-size sequence: The update step size γt:=1t+1\gamma_t := \frac{1}{t+1} satisfies the conditions: ∑tγt=∞\sum_t \gamma_t = \infty and ∑tγt2<∞\sum_t \gamma_t^2 < \infty.

  2. Compact state space: PtP_t lies in the simplex ΔV−1\Delta^{V-1}, which is compact.

  3. Smoothness: The ODE has drift π∗(P)−P\pi^*(P) - P, where π∗(P)\pi^*(P) is the stationary distribution of MPM_P. Since τ>0\tau> 0 and the logits are bounded on the simplex, each entry in MPM_P is bounded away from zero; thus, MPM_P is uniformly ergodic. Since MPM_P also depends smoothly on PP, π∗(P)\pi^*(P) is continuously differentiable (and hence Lipschitz) on the simplex.

  4. Markovian state noise and martingale difference: Since the next token xt+1x_{t+1} is sampled from row xtx_t of MPtM_{P_t}, its conditional expectation given Ft\mathcal{F}_t is MPt(xt,⋅)M_{P_t}(x_t,\cdot) rather than π∗(Pt)\pi^*(P_t). We therefore decompose the update increment as:

I(xt+1=v)−Pt(v)=(π∗(Pt)(v)−Pt(v))⏟mean-field drift+(MPt(xt,v)−π∗(Pt)(v))⏟Markovian state noise+(I(xt+1=v)−MPt(xt,v))⏟martingale difference\mathbb{I}(x_{t+1}=v)-P_t(v)=\underbrace{\left(\pi^*(P_t)(v)-P_t(v)\right)}_{\text{mean-field drift}}+\underbrace{\left(M_{P_t}(x_t,v)-\pi^*(P_t)(v)\right)}_{\text{Markovian state noise}}+\underbrace{\left(\mathbb{I}(x_{t+1}=v)-M_{P_t}(x_t,v)\right)}_{\text{martingale difference}}

Lemma 1. For every fixed τ>0\tau> 0, the empirical distribution PtP_t tracks the ODE a.s.

dPdt=π∗(P)−P.\frac{dP}{dt}=\pi^*(P)-P.

Hence, the limiting set of PtP_t is an ICT of this ODE a.s.

Proof. Using (iv), the update is given by

Pt+1−Pt=γt(π∗(Pt)−Pt+ξt+1+ηt+1),P_{t+1}-P_t=\gamma_t\left(\pi^*(P_t)-P_t+\xi_{t+1}+\eta_{t+1}\right),

where

ξt+1=MPt(xt,⋅)−π∗(Pt),ηt+1=I(xt+1=⋅)−MPt(xt,⋅).\xi_{t+1}=M_{P_t}(x_t,\cdot)-\pi^*(P_t),\qquad\eta_{t+1}=\mathbb{I}(x_{t+1}=\cdot)-M_{P_t}(x_t,\cdot).

Note that ηt+1\eta_{t+1} is a bounded martingale difference, and so ∑tγtηt+1\sum_t \gamma_t\eta_{t+1} converges (a.s.) as ∑tγt2<∞\sum_t \gamma_t^2 < \infty from (i).

For the Markovian term ξt+1\xi_{t+1}, uniform ergodicity from (iii) implies that there is a uniformly bounded function gPg_P, Lipschitz-continuous in PP, satisfying

gP(x)−∑yMP(x,y)gP(y)=MP(x,⋅)−π∗(P).g_P(x) - \sum_y M_P(x,y)g_P(y) = M_P(x,\cdot) - \pi^*(P).

Thus

ξt+1=gPt(xt)−gPt(xt+1)+ζt+1,\xi_{t+1} = g_{P_t}(x_t) - g_{P_t}(x_{t+1}) + \zeta_{t+1},

where

ζt+1=gPt(xt+1)−∑yMPt(xt,y)gPt(y),\zeta_{t+1} = g_{P_t}(x_{t+1}) - \sum_y M_{P_t}(x_t,y)g_{P_t}(y),

is a bounded martingale difference. After multiplication by γt\gamma_t, the first two terms telescope up to a boundary term, which vanishes, and errors of order ∣γt−γt−1∣|\gamma_t-\gamma_{t-1}| and γt∥Pt−Pt−1∥=O(γt2)\gamma_t\lVert P_t-P_{t-1}\rVert= O(\gamma_t^2), which are summable. Also, ∑tγtζt+1\sum_t \gamma_t\zeta_{t+1} converges (a.s.). Hence the accumulated Markovian noise has vanishing tails.

Since P↦π∗(P)−PP \mapsto\pi^*(P)-P is Lipschitz, the proof follows from stochastic approximation [2]. □\square

Jacobian

In this section, we study the limiting behavior of our simple transformer. In particular, we show that there is a temperature threshold above which the limit of the empirical distribution PtP_t is a unique fixed point.

From Lemma 1, the transformer tracks the ODE in the limit, so we study now whether all solutions converge to the same limit, or whether different limiting sets are possible. To do this, we analyze the Jacobian J∈RV×VJ \in\mathbb{R}^{V\times V} of the map π∗(P)\pi^*(P). This Jacobian characterizes how the steady state of the Markov chain moves in response to a local change in the history. Its entries are

Jw,v=∂π∗(w)∂P(v).J_{w,v} = \frac{\partial\pi^*(w)}{\partial P(v)}.

Note that taking a partial derivative with respect to a single component P(v)P(v) while holding all other components P(j≠v)P(j\ne v) constant points in a direction that leaves the probability simplex (since the sum of the components will no longer equal 1). Since the formulas above extend smoothly to a neighborhood of the simplex, we can use these derivatives to assemble the full Jacobian in RV×V\mathbb{R}^{V\times V}. Since ∑wπ∗(w)=1\sum_w \pi^*(w)=1, only perturbations whose coordinates sum to zero correspond to valid changes of the probability distribution. Restricting the Jacobian to these perturbations gives the correct local behavior on the simplex.

Lemma 2. It holds that

∂π∗∂P(v)=∂π∗∂P(v)MP+π∗∂MP∂P(v).\frac{\partial\pi^*}{\partial P(v)} = \frac{\partial\pi^*}{\partial P(v)}M_P + \pi^*\frac{\partial M_P}{\partial P(v)}.

Proof. We trace the chain of derivatives with respect to P(v)P(v):

  1. We differentiate the normalization term ZuZ_u in (1):

∂Zu∂P(v)=exp⁡(su,v).\frac{\partial Z_u}{\partial P(v)} = \exp(s_{u,v}).

Applying the quotient rule to αu,k\alpha_{u,k} in (1):

∂αu,k∂P(v)=δk,vexp⁡(su,k)Zu−P(k)exp⁡(su,k)exp⁡(su,v)Zu2=exp⁡(su,v)Zu(δk,v−αu,k).\frac{\partial\alpha_{u,k}}{\partial P(v)} = \frac{\delta_{k,v}\exp(s_{u,k})Z_u-P(k)\exp(s_{u,k})\exp(s_{u,v})}{Z_u^2} = \frac{\exp(s_{u,v})}{Z_u}(\delta_{k,v}-\alpha_{u,k}).

Summing over all kk to find the shift in the attention output ouo_u:

∂ou∂P(v)=∑k=1V∂αu,k∂P(v)ϕk=exp⁡(su,v)Zu(ϕv−ou).(2)\frac{\partial o_u}{\partial P(v)}=\sum_{k=1}^{V}\frac{\partial\alpha_{u,k}}{\partial P(v)}\phi_k=\frac{\exp(s_{u,v})}{Z_u}(\phi_v-o_u). \tag*{(2)}

(ii) Let zu,w=⟨ou,Eout[w]⟩z_{u,w}=\langle o_u,E_{\mathrm{out}}[w]\rangle be the logit for token ww. Its derivative is linear: ∂zu,w∂P(v)=⟨∂ou∂P(v),Eout[w]⟩\frac{\partial z_{u,w}}{\partial P(v)}=\left\langle\frac{\partial o_u}{\partial P(v)},E_{\mathrm{out}}[w]\right\rangle. The transition probability MP(u,w)M_P(u,w) is a softmax over these logits scaled by τ\tau. Applying the standard softmax derivative, the chain rule, and using (2),

∂MP(u,w)∂P(v)=∑y∈V∂MP(u,w)∂zu,y∂zu,y∂P(v)=∑y∈V1τMP(u,w)(δw,y−MP(u,y))⟨∂ou∂P(v),Eout[y]⟩=1τMP(u,w)⟨∂ou∂P(v),Eout[w]⟩−∑y∈VMP(u,y)⟨∂ou∂P(v),Eout[y]⟩.\begin{aligned} \frac{\partial M_P(u,w)}{\partial P(v)} &=\sum_{y\in V}\frac{\partial M_P(u,w)}{\partial z_{u,y}}\frac{\partial z_{u,y}}{\partial P(v)}\\ &=\sum_{y\in V}\frac{1}{\tau}M_P(u,w)(\delta_{w,y}-M_P(u,y))\left\langle\frac{\partial o_u}{\partial P(v)},E_{\mathrm{out}}[y]\right\rangle\\ &=\frac{1}{\tau}M_P(u,w)\left\langle\frac{\partial o_u}{\partial P(v)},E_{\mathrm{out}}[w]\right\rangle -\sum_{y\in V}M_P(u,y)\left\langle\frac{\partial o_u}{\partial P(v)},E_{\mathrm{out}}[y]\right\rangle. \end{aligned}

Let eˉu=∑y∈VMP(u,y)Eout[y]\bar e_u=\sum_{y\in V}M_P(u,y)E_{\mathrm{out}}[y] be the expected output embedding over the entire vocabulary for query uu. Rewriting, we obtain

∂MP(u,w)∂P(v)=1τMP(u,w)exp⁡(su,v)Zu⟨ϕv−ou,Eout[w]−eˉu⟩.(3)\frac{\partial M_P(u,w)}{\partial P(v)} =\frac{1}{\tau}M_P(u,w)\frac{\exp(s_{u,v})}{Z_u}\left\langle\phi_v-o_u,E_{\mathrm{out}}[w]-\bar e_u\right\rangle. \tag*{(3)}

(iii) Finally, we derive the Jacobian of the stationary distribution Jw,v=∂π∗(w)∂P(v)J_{w,v}=\frac{\partial\pi^*(w)}{\partial P(v)}. Since π∗\pi^* is the stationary distribution of MPM_P, it satisfies the equilibrium condition π∗=π∗MP\pi^*=\pi^*M_P. Differentiating,

∂π∗∂P(v)=∂π∗∂P(v)MP+π∗∂MP∂P(v).\frac{\partial\pi^*}{\partial P(v)}=\frac{\partial\pi^*}{\partial P(v)}M_P+\pi^*\frac{\partial M_P}{\partial P(v)}.

□\square

Let cvT=∂π∗∂P(v)c_v^T=\frac{\partial\pi^*}{\partial P(v)} denote the row vector corresponding to the vvth column of the Jacobian JJ, and let rvT=π∗∂MP∂P(v)r_v^T=\pi^*\frac{\partial M_P}{\partial P(v)} represent the direct perturbation vector. Rearranging the terms gives:

cvT(I−MP)=rvT(4)c_v^T(I-M_P)=r_v^T \tag*{(4)}

To isolate cvTc_v^T, we define F=(I−MP+1π∗)−1F=(I-M_P+\mathbf{1}\pi^*)^{-1}, which satisfies (I−MP)F=I−1π∗(I-M_P)F=I-\mathbf{1}\pi^*. Multiplying both sides of (4) by FF on the right yields:

cvT(I−MP)F=rvTF.(5)c_v^T(I-M_P)F=r_v^TF. \tag*{(5)}

Furthermore, since cvTc_v^T is the derivative of a probability distribution, its elements sum to zero, i.e., cvT1=0c_v^T\mathbf{1}=0. This cancels the rank-one term 1π∗\mathbf{1}\pi^{*}, yielding a closed-form solution for the Jacobian column:

cvT=rvTF.c_v^T=r_v^T F.

We next show a bound on the norm of the Jacobian, in terms of the temperature.

Lemma 3. There exist constants C,τ0<∞C,\tau_0<\infty such that, for all τ≥τ0\tau\ge\tau_0,

sup⁡P∈ΔV−1∥J(P)∥≤Cτ.\sup_{P\in\Delta^{V-1}}\|J(P)\|\le\frac{C}{\tau}.

Proof. By (2), ∂ou/∂P(v)\partial o_u/\partial P(v) is uniformly bounded over P∈ΔV−1P\in\Delta^{V-1}. Since all remaining factors in (3) except 1/τ1/\tau are bounded on the simplex, we obtain

∥∂MP∂P(v)∥=O(1τ).\left\|\frac{\partial M_P}{\partial P(v)}\right\|=O\left(\frac{1}{\tau}\right).

As τ→∞\tau\to\infty, every row of MPM_P converges uniformly in PP to the uniform distribution uu. Since

π∗(P)=π∗(P)MP,\pi^{*}(P)=\pi^{*}(P)M_P,
∥π∗(P)−u∥≤max⁡x∥MP(x,⋅)−u∥,\|\pi^{*}(P)-u\|\le\max_x\|M_P(x,\cdot)-u\|,

so π∗(P)→u\pi^{*}(P)\to u uniformly as well. Hence I−MP+1π∗→II-M_P+\mathbf{1}\pi^{*}\to I uniformly in PP, so F=(I−MP+1π∗)−1F=(I-M_P+\mathbf{1}\pi^{*})^{-1} remains uniformly bounded for all sufficiently large τ\tau. Using cvT=π∗(∂MP/∂P(v))Fc_v^T=\pi^{*}(\partial M_P/\partial P(v))F, and since ∥π∗∥\|\pi^{*}\| and ∥F∥\|F\| are bounded, we obtain ∥cv∥=O(1/τ)\|c_v\|=O(1/\tau) for every column cvc_v of JJ. Since there are only VV columns, sup⁡P∥J(P)∥=O(1/τ)\sup_P\|J(P)\|=O(1/\tau).

Using these, we show that a temperature threshold exists, which is the main result in this section.

Theorem 4. There is a temperature τc\tau_c such that P↦π∗(P)P\mapsto\pi^{*}(P) is a contraction for all τ>τc\tau>\tau_c. Hence, it has a unique fixed point P∗P^{*}, which is globally attracting under the ODE.

Proof. Choose τc>max⁡{C,τ0}\tau_c>\max\{C,\tau_0\}, where C,τ0C,\tau_0 are the constants in Lemma 3. Since the simplex is convex, P↦π∗(P)P\mapsto\pi^{*}(P) is a contraction and has a unique fixed point P∗P^{*}. Writing the ODE as dPdt=π∗(P)−P\frac{dP}{dt}=\pi^{*}(P)-P, let e(t)=P(t)−P∗e(t)=P(t)-P^{*}. Since π∗(P∗)=P∗\pi^{*}(P^{*})=P^{*} and using

∥π∗(P)−π∗(P∗)∥≤q∥P−P∗∥,q=sup⁡P∥J(P)∥<1,\|\pi^{*}(P)-\pi^{*}(P^{*})\|\le q\|P-P^{*}\|,\qquad q=\sup_P\|J(P)\|<1,

we have

12ddt∥e(t)∥2=⟨e(t),π∗(P(t))−π∗(P∗)−e(t)⟩≤−(1−q)∥e(t)∥2.\frac{1}{2}\frac{d}{dt}\|e(t)\|^2=\langle e(t),\pi^{*}(P(t))-\pi^{*}(P^{*})-e(t)\rangle\le-(1-q)\|e(t)\|^2.

Integrating this inequality,

∥P(t)−P∗∥≤e−(1−q)t∥P(0)−P∗∥,\|P(t)-P^{*}\|\le e^{-(1-q)t}\|P(0)-P^{*}\|,

so P∗P^{*} is globally attracting. Since ∥P(t)−P∗∥\|P(t)-P^{*}\| decreases strictly away from P∗P^{*}, {P∗}\{P^{*}\} is the only ICT set of the ODE.

Combining Lemma 1 and Theorem 4, for every τ>τc\tau>\tau_c, we have lim⁡t→∞Pt=P∗\lim_{t\to\infty}P_t=P^{*} (a.s.). Moreover, as τ→∞\tau\to\infty, P∗P^{*} converges to the uniform distribution, since MPM_P converges uniformly in PP to the transition matrix with every row uniform. For τ≤τc\tau\le\tau_c, however, the above argument no longer guarantees uniqueness of the limiting set. Multiple limiting ICT sets are not ruled out and the behavior in this below-threshold temperature regime may depend on the specific model parameters.

A Simple Example

Let us consider a trivial example that shows three surprising facts about this simple transformer:

  1. It may non-deterministically approach one of multiple limits.

  2. The likelihood of each limit may depend on the starting conditions.

  3. As the temperature increases, the same transformer will transition into approaching a single limit, independent of starting conditions.

Our example has only two tokens, and the hidden dimension is one, so embeddings and weight matrices are simply scalars. For a∈R+a \in\mathbb{R}^{+}, the model is fully specified by these values:

Ein[1]=1,Ein[2]=−1,WQ=WK=0,WV=1,Eout[1]=a,Eout[2]=−a.E_{\mathrm{in}}[1] = 1,\qquad E_{\mathrm{in}}[2] = -1,\qquad W_{Q} = W_{K} = 0,\qquad W_{V} = 1,\qquad E_{\mathrm{out}}[1] = a,\qquad E_{\mathrm{out}}[2] = -a.

Let p=P(1)p = P(1) be the fraction of token 1 in the history. Uniform attention gives o(P)=2p−1o(P) = 2p - 1, and every row of MPM_{P} assigns probability

q(p)=12(1+tanh⁡(aτ(2p−1)))q(p) = \frac{1}{2}\left(1+\tanh\left(\frac{a}{\tau}(2p-1)\right)\right)

to token 1. Hence π∗(P)=(q(p),1−q(p))\pi^{*}(P) = (q(p),1-q(p)) and, with x=2p−1x = 2p-1, the limiting ODE becomes

dxdt=tanh⁡(aτx)−x.\frac{dx}{dt} = \tanh\left(\frac{a}{\tau}x\right)-x.

For τ>a\tau> a, the right-hand map is a contraction and x=0x = 0 is the unique globally attracting fixed point. For τ<a\tau< a, x=0x = 0 is unstable and two symmetric attracting fixed points ±x∗\pm x_{*} appear. Thus even this two-token example exhibits the temperature-dependent transition underlying Theorem 4. Note that Mori and Hisakado [20]; Hisakado and Mori [12] present a similar analysis exhibiting the same variation in steady state.

Despite the interesting dynamics of the steady state, the historical token distribution for these models does approach a limit for every positive temperature, even if this limit might be a random variable. In § 6, we show that even this is not guaranteed by giving an explicit three-token construction with a proof of non-convergence of the token distribution.

Multi-Layer Transformer

The analysis for a single-layer transformer uses the fact that, without position encodings, the history is summarized by the empirical token distribution. This does not hold for a multi-layer transformer, where the key and value vectors stored at a historical position depend on the context in which that position was generated. Nevertheless, for a fixed-width, fixed-depth transformer, each historical position contributes only a fixed-dimensional vector to the global KV cache. We therefore represent the unbounded history by an empirical distribution over these vectors.

Throughout this section, the number of layers and heads is fixed, and every local attention layer is causal with a fixed window of width at most ww. Besides the global KV cache, the model has no recurrent state other than the finite KV caches used to power the local layers. As in a standard transformer block, the keys and values stored by an attention layer are computed from the input to that layer, before its attention output is produced. All projections, MLPs, residual maps, and normalization maps are assumed to be uniformly Lipschitz on the reachable set and all reachable hidden states, queries, keys, values, local cache states, and pre-temperature output logits are uniformly bounded. All constants below may depend on the architecture and its weights, but not on the generation time. For local RoPE layers, attention depends only on relative offsets within the fixed local window, so no absolute phase state is needed.

Phase portraits illustrating the high- and low-temperature equilibria

Figure 2. A two-token example illustrating the temperature transition: x=2p−1x = 2p - 1 and dx/dt=tanh⁡((a/τ)x)−x\mathrm{d}x/\mathrm{d}t = \tanh((a/\tau)x) - x. For τ>a\tau> a, the uniform state is the unique globally attracting equilibrium. For τ<a\tau< a, it becomes unstable and two symmetric stable equilibria appear.

We consider a transformer with both global attention layers, whose attention window has the full history, and local attention layers with a fixed window. Let LglobL_{\mathrm{glob}} and LlocL_{\mathrm{loc}} be the numbers of global and local attention layers respectively, each with hh heads of dimension dd.

Let θℓ,a=(θℓ,a,1,…,θℓ,a,d/2)\boldsymbol{\theta}_{\ell,a} = (\theta_{\ell,a,1},\ldots,\theta_{\ell,a,d/2}) be the RoPE frequencies of head (ℓ,a)(\ell,a), and define the RoPE rotation as:

R(pθℓ,a):=diag⁡(R(pθℓ,a,1),…,R(pθℓ,a,d/2)).R(p\boldsymbol{\theta}_{\ell,a}) := \operatorname{diag}\bigl(R(p\theta_{\ell,a,1}),\ldots,R(p\theta_{\ell,a,d/2})\bigr).

where

R(α)=(cos⁡α−sin⁡αsin⁡αcos⁡α).R(\alpha) = \begin{pmatrix} \cos\alpha& -\sin\alpha\\ \sin\alpha& \cos\alpha \end{pmatrix}.

For each historical position pp, let kℓ,a,prawk^{\mathrm{raw}}_{\ell,a,p} be the unrotated key, and let

kℓ,a,prot=R(pθℓ,a)⋅kℓ,a,praw,k^{\mathrm{rot}}_{\ell,a,p} = R(p\boldsymbol{\theta}_{\ell,a}) \cdot k^{\mathrm{raw}}_{\ell,a,p},

be the rotated key. The collection of global cache quantities generated at position pp is

zp=(kℓ,a,prot,vℓ,a,p)ℓ∈[Lglob], a∈[h]∈R2dhLglob.z_p = \bigl(k^{\mathrm{rot}}_{\ell,a,p},v_{\ell,a,p}\bigr)_{\ell\in[L_{\mathrm{glob}],\,a\in[h]} \in\mathbb{R}^{2dhL_{\mathrm{glob}}}.}

Let Z\mathcal{Z} be the closure of the set of all reachable zpz_p; by the boundedness assumption, Z\mathcal{Z} is compact. Let θ\boldsymbol{\theta} denote the collection of RoPE frequencies across all global heads, and let ωt=tθ(mod2π)\boldsymbol{\omega}_t = t\boldsymbol{\theta}\pmod{2\pi} denote the vector of current RoPE phases. Let

ηt=1t∑p=1tδzp\eta_t = \frac{1}{t}\sum_{p=1}^{t}\delta_{z_p}

be the empirical distribution of global cache vectors, where δz\delta_z denotes a unit point mass at zz. Thus, the global cache changes slowly: each new token changes its empirical distribution by only O(1/t)O(1/t).

For each z∈Zz \in\mathcal{Z}, let kℓ,arot(z)k^{\mathrm{rot}}_{\ell,a}(z) and vℓ,a(z)v_{\ell,a}(z) denote its key and value coordinates for global layer ℓ\ell and head aa. For a query qℓ,a,trot=R(tθℓ,a)⋅qℓ,a,trawq^{\mathrm{rot}}_{\ell,a,t} = R(t\boldsymbol{\theta}_{\ell,a}) \cdot q^{\mathrm{raw}}_{\ell,a,t}, the corresponding global attention output is

oℓ,a(t)=∫Zvℓ,a(z)⋅exp⁡(⟨qℓ,a,trot,kℓ,arot(z)⟩d)dηt(z)∫Zexp⁡(⟨qℓ,a,trot,kℓ,arot(z)⟩d)dηt(z).(6)o_{\ell,a}(t)=\frac{\int_{\mathcal{Z}}v_{\ell,a}(z)\cdot\exp\left(\frac{\left\langle q^{\mathrm{rot}}_{\ell,a,t},k^{\mathrm{rot}}_{\ell,a}(z)\right\rangle}{\sqrt{d}}\right)d\eta_t(z)}{\int_{\mathcal{Z}}\exp\left(\frac{\left\langle q^{\mathrm{rot}}_{\ell,a,t},k^{\mathrm{rot}}_{\ell,a}(z)\right\rangle}{\sqrt{d}}\right)d\eta_t(z)}. \tag*{(6)}

Since the reachable queries and keys are bounded, the denominator in (5) is bounded away from zero uniformly in tt.

Thus, once the RoPE rotation is incorporated into the stored key, its historical location is no longer needed. To characterize long-run RoPE phases, let

Hθ:={nθ(mod2π):n∈Z}‾,H_\theta:= \overline{\{n\theta\pmod{2\pi}: n\in\mathbb{Z}\}},

be the closure of phases visited in the limit. Let μθ\mu_\theta denote the uniform probability distribution on HθH_\theta. We now show that averages along the RoPE phases converge to the average under μθ\mu_\theta.

Lemma 5. For any continuous function f:Hθ→Cf:H_\theta\to\mathbb{C},

sup⁡α∈Hθ∣1T∑n=1Tf(α+nθ)−∫Hθf(ω) dμθ(ω)∣⟶0.\sup_{\alpha\in H_\theta}\left|\frac{1}{T}\sum_{n=1}^{T}f(\alpha+n\theta)-\int_{H_\theta}f(\omega)\,d\mu_\theta(\omega)\right|\longrightarrow0.

Proof. Consider α=0\alpha=0. For an integer vector mm of the same dimension as θ\theta, let χm(ω)=ei⟨m,ω⟩\chi_m(\omega)=e^{i\langle m,\omega\rangle}. Then,

1T∑n=1Tχm(nθ)⟶{1,⟨m,θ⟩∈2πZ,0,otherwise.\frac{1}{T}\sum_{n=1}^{T}\chi_m(n\theta)\longrightarrow \begin{cases} 1, & \langle m,\theta\rangle\in2\pi\mathbb{Z},\\ 0, & \text{otherwise}. \end{cases}

The average of the same function under the uniform distribution on HθH_\theta has the same value. Since finite linear combinations of χm\chi_m uniformly approximate every continuous function on HθH_\theta, the result follows. The same calculation with α+nθ\alpha+n\theta instead of nθn\theta differs only by the factor ei⟨m,α⟩e^{i\langle m,\alpha\rangle}, whose absolute value is one, so the convergence is uniform in α\alpha.

To understand the impact of the local layers, note that each such layer has width at most ww, and so its output can introduce dependence on at most w−1w-1 additional earlier token positions. Thus, once the global attention outputs are fixed, the remaining computation depends only on the most recent W=1+Lloc(w−1)W=1+L_{\mathrm{loc}}(w-1) tokens. Let ut=(xt−W+1,…,xt)∈ΣWu_t=(x_{t-W+1},\ldots,x_t)\in\Sigma^W be this WW-gram (with fixed padding when t<Wt<W). Any fixed transformer in our model may be viewed as a function mapping from utu_t and the global cache state to a new ut+1u_{t+1} and global KV cache column output.

Frozen Cache Dynamics

In this section, we first hold the global cache fixed and study the evolution of utu_t over a block of kk steps. The motivation for this approach is as follows. Each new output modifies the global cache by only O(1/t)O(1/t), so for k=o(t)k=o(t), sup⁡0≤j≤kd1(ηt+j,ηt)=O(k/t)=o(1)\sup_{0\leq j\leq k}d_1(\eta_{t+j},\eta_t)=O(k/t)=o(1); thus the cache does indeed behave as if frozen. Once we understand the frozen cache behavior, we study how the drift during the frozen regime will eventually result in a new global cache state (possible, as ∑t′>t1/t′\sum_{t'>t}1/t' diverges), and what the trajectory over these evolving global cache states will look like.

Let η\eta be a probability distribution on Z\mathbb{Z} representing the (frozen) global cache state. With the global cache fixed, the recent WW tokens and the current RoPE phase determine the next step. u∈ΣWu \in\Sigma^{W} and phase ω∈Hθ\omega\in H_{\theta}, let qη,ω(a∣u)=Pr⁡[xt+1=a∣ut=u,ωt=ω,η]q_{\eta,\omega}(a \mid u) = \Pr[x_{t+1} = a \mid u_t = u, \omega_t = \omega, \eta] be the next token distribution produced by the transformer. For u,u′∈ΣWu, u' \in\Sigma^{W}, define the transition matrix:

Qη,ω(u,u′)=Pr⁡[ut+1=u′∣ut=u,ωt=ω,η].Q_{\eta,\omega}(u,u') = \Pr[u_{t+1} = u' \mid u_t = u, \omega_t = \omega, \eta].

Thus Qη,ω(u,u′)>0Q_{\eta,\omega}(u,u') > 0 only if u′u' is obtained from uu by dropping its first symbol and appending one new token. We first establish a uniform lower bound on next token probabilities. This will imply that every WW-gram can be reached from every other in WW steps and hence the product of the transition matrices contract.

We assume that τ≥τmin⁡>0\tau\geq\tau_{\min} > 0. By the boundedness assumption, there is a constant B<∞B < \infty such that every pre-temperature output logit satisfies ∣ℓηout(n,u,ω)∣≤B\lvert\ell^{\mathrm{out}}_{\eta}(n,u,\omega) \rvert\leq B for all u∈ΣWu \in\Sigma^{W}, ω∈Hθ\omega\in H_{\theta}, and a∈Σa \in\Sigma. Therefore,

qη,ω(a∣u)≥ϵ:=exp⁡(−2B/τmin⁡)V>0.(7)q_{\eta,\omega}(a \mid u) \geq\epsilon:= \frac{\exp(-2B/\tau_{\min})}{V} > 0. \tag*{(7)}

Since the phase changes by θ\theta after each step, the mm-step transition matrix starting at phase ω\omega is

Qη,ω[m]:=Qη,ω⋅Qη,ω+θ⋯⋅Qη,ω+(m−1)θ.Q_{\eta,\omega}^{[m]} := Q_{\eta,\omega} \cdot Q_{\eta,\omega+\theta} \cdots\cdot Q_{\eta,\omega+(m-1)\theta}.

Starting from any WW-gram, any particular WW-gram u′=(y1,…,yW)u' = (y_1,\ldots,y_W) can be reached in WW steps by generating y1,…,yWy_1,\ldots,y_W. By (6), each of these tokens has conditional probability at least ϵ\epsilon. Hence

Qη,ω[W](u,u′)≥ϵW,Q_{\eta,\omega}^{[W]}(u,u') \geq\epsilon^{W},

for every u,u′∈ΣWu,u' \in\Sigma^{W}, uniformly in η\eta and ω\omega.

Let β=VWϵW∈(0,1]\beta= V^{W}\epsilon^{W} \in(0,1]. Since every entry of the WW-step transition matrix is at least ϵW\epsilon^{W}, for any two probability distributions λ,λ′\lambda,\lambda' on ΣW\Sigma^{W}, we have

∥λ⋅Qη,ω[m]−λ′⋅Qη,ω[m]∥tv≤(1−β)⌊m/W⌋∥λ−λ′∥tv.(8)\left\lVert\lambda\cdot Q_{\eta,\omega}^{[m]} - \lambda' \cdot Q_{\eta,\omega}^{[m]} \right\rVert_{\mathrm{tv}} \leq(1-\beta)^{\lfloor m/W \rfloor}\left\lVert\lambda-\lambda' \right\rVert_{\mathrm{tv}}. \tag*{(8)}

Thus, with the cache fixed, the effect of the initial WW-gram decays geometrically. Since the RoPE phase changes at each step, the process is governed by a sequence of transition matrices rather than by one fixed matrix; we study its limiting behavior.

Lemma 6. For every fixed η\eta, (i) there is a unique family {πη(ω)}ω∈Hθ\{\pi_{\eta}(\omega)\}_{\omega\in H_{\theta}} of probability distributions such that πη(ω+θ)=πη(ω)⋅Qη,ω\pi_{\eta}(\omega+\theta) = \pi_{\eta}(\omega) \cdot Q_{\eta,\omega} and (ii) for every initial distribution λ\lambda,

∥λ⋅Qη,ω[m]−πη(ω+mθ)∥tv≤(1−β)⌊m/W⌋.\left\lVert\lambda\cdot Q_{\eta,\omega}^{[m]} - \pi_{\eta}(\omega+m\theta) \right\rVert_{\mathrm{tv}} \leq(1-\beta)^{\lfloor m/W \rfloor}.

Proof. Fix ω\omega and any distribution λ\lambda on ΣW\Sigma^{W}. Consider

λ⋅Qη,ω−mθ⋅Qη,ω−(m−1)θ⋯⋅Qη,ω−θ.(9)\lambda\cdot Q_{\eta,\omega-m\theta} \cdot Q_{\eta,\omega-(m-1)\theta} \cdots\cdot Q_{\eta,\omega-\theta}. \tag*{(9)}

If a longer product is used, its last mm transition matrices are the same as those in (8), but with a possibly different distribution at their starting point. By (7), changing that starting distribution changes the result by at most (1−β)⌊m/W⌋(1-\beta)^{\lfloor m/W \rfloor}. Hence (8) converges as m→∞m \to\infty, and its limit does not depend on λ\lambda. Define this limit to be πη(ω)\pi_{\eta}(\omega).

Shifting ω\omega by θ\theta in (8) gives (i). Finally, apply (7) to λ\lambda and πη(ω)\pi_{\eta}(\omega); (ii) now follows from (i). Uniqueness also follows from the same bound.

Since only a fixed number of recent positions enter the local computation and all computations are Lipschitz, replacing the cache states used at those positions by the current cache ηt\eta_t changes the next step distribution by O(1/t)O(1/t). Recalling Ft\mathcal{F}_t is the history up to time tt,

∥Pr⁡[ut+1∈⋅∣Ft]−Qηt,ωt(ut,⋅)∥tv=O(1/t).\left\|\Pr[u_{t+1} \in\cdot\mid\mathcal{F}_t] - Q_{\eta_t,\omega_t}(u_t,\cdot)\right\|_{\mathrm{tv}} = O(1/t).

We next show that this frozen cache description remains accurate over time intervals on which the empirical cache changes only slightly.

Lemma 7. (i) There is a constant LπL_\pi such that

sup⁡ω∈Hθ∥πη(ω)−πη′(ω)∥tv≤Lπ⋅d1(η,η′).\sup_{\omega\in H_\theta}\left\|\pi_\eta(\omega)-\pi_{\eta'}(\omega)\right\|_{\mathrm{tv}} \le L_\pi\cdot d_1(\eta,\eta').

(ii) Moreover, let k=k(p)k=k(p) satisfy k→∞k\to\infty and k2/p→0k^2/p\to0. Then

∥Pr⁡[up+k∈⋅∣Fp]−πηp(ωp+k)∥tv⟶0.\left\|\Pr[u_{p+k}\in\cdot\mid\mathcal{F}_p]-\pi_{\eta_p}(\omega_{p+k})\right\|_{\mathrm{tv}}\longrightarrow0.

Proof. We first prove (i). Under our assumptions, there is a constant LQL_Q such that

sup⁡η,ω∥Qη,ω(u,⋅)−Qη′,ω(u,⋅)∥tv≤LQ⋅d1(η,η′).(10)\sup_{\eta,\omega}\left\|Q_{\eta,\omega}(u,\cdot)-Q_{\eta',\omega}(u,\cdot)\right\|_{\mathrm{tv}}\le L_Q\cdot d_1(\eta,\eta'). \tag*{(10)}

Indeed, for the first global layer this follows directly from (5): its terms are uniformly bounded and Lipschitz in zz, and the denominator is uniformly bounded away from zero. The resulting attention output therefore changes by O(d1(η,η′))O(d_1(\eta,\eta')). Repeating this argument through the fixed number of layers, using the Lipschitz assumptions, proves (9).

Combining (9) with (8) gives (i): comparing the products defining πη(ω)\pi_\eta(\omega) and πη′(ω)\pi_{\eta'}(\omega) term by term, a change rr steps in the past is reduced geometrically in rr, and summing these changes gives the stated bound. Similarly, continuity of Qη,ωQ_{\eta,\omega} in ω\omega implies continuity of πη(ω)\pi_\eta(\omega) in ω\omega.

We now return to the actual cache, which changes after every step tt. From the definition of ηt\eta_t,

ηt+1=ηt+1t+1(δzt+1−ηt).\eta_{t+1}=\eta_t+\frac{1}{t+1}\left(\delta_{z_{t+1}}-\eta_t\right).

Since each cache update has size O(1/t)O(1/t),

sup⁡0≤j≤kd1(ηp+j,ηp)=O(kp).\sup_{0\le j\le k}d_1(\eta_{p+j},\eta_p)=O\left(\frac{k}{p}\right).

Therefore, by (9),

sup⁡0≤j<ksup⁡u∥Qηp+j,ωp+j(u,⋅)−Qηp,ωp+j(u,⋅)∥tv=O(kp).\sup_{0\le j<k}\sup_u\left\|Q_{\eta_{p+j},\omega_{p+j}}(u,\cdot)-Q_{\eta_p,\omega_{p+j}}(u,\cdot)\right\|_{\mathrm{tv}}=O\left(\frac{k}{p}\right).

Comparing the two kk-step products one step at a time, the errors from replacing ηp+j\eta_{p+j} by ηp\eta_p add up to O(k2/p)O(k^2/p). The O(1/t)O(1/t) error in the actual one-step transition accumulates to O(k/p)O(k/p), which is smaller. Hence, conditioned on Fp\mathcal{F}_p, the distribution of up+ku_{p+k} differs by O(k2/p)O(k^2/p) from the distribution obtained by holding the cache fixed at ηp\eta_p. Lemma 6 thus gives

∥Pr⁡[up+k∈⋅∣Fp]−πηp(ωp+k)∥tv≤(1−β)⌊k/W⌋+O(k2p).\left\|\Pr[u_{p+k}\in\cdot\mid\mathcal{F}_p]-\pi_{\eta_p}(\omega_{p+k})\right\|_{\mathrm{tv}} \le(1-\beta)^{\left\lfloor k/W\right\rfloor}+O\left(\frac{k^2}{p}\right).

Both terms vanish under k→∞k\to\infty and k2/p→0k^2/p\to0, proving (ii). □

Thus, over a block that is long enough for the recent tokens to forget their initial state but short enough that the global cache changes little, their distribution is determined asymptotically by the cache state at the start of the block and the current RoPE phase. Although the instantaneous distribution may depend on the RoPE phase, Lemma 5 allows this phase dependence to be averaged over a long block.

Slow Cache Dynamics

Lemma 7 describes the recent token distribution while the global cache changes only slightly. We now use this to study the average evolution of the cache itself.

For a fixed η\eta, u∈ΣWu \in\Sigma^{W}, ω∈Hθ\omega\in H_{\theta}, and a generated token a∈Σa \in\Sigma, let G(η,u,ω,a)∈ZG(\eta,u,\omega,a) \in\mathcal{Z} denote the new global cache vector inserted at the next position, whose RoPE phase is ω+θ\omega+\theta. The Lipschitz assumptions above mean that GG is Lipschitz in η\eta with respect to d1d_{1} and in ω\omega. Define

Γ(η):=∫Hθ∑u∈ΣW∑a∈Σπη(ω)(u)⋅qη,ω(a∣u)⋅δG(η,u,ω,a) dμθ(ω).\Gamma(\eta) := \int_{H_{\theta}} \sum_{u \in\Sigma^{W}} \sum_{a \in\Sigma} \pi_{\eta}(\omega)(u) \cdot q_{\eta,\omega}(a \mid u) \cdot\delta_{G(\eta,u,\omega,a)} \, d\mu_{\theta}(\omega).

Thus Γ(η)\Gamma(\eta) is the average distribution of the next cache vector when the recent tokens have adjusted to the frozen cache η\eta and the RoPE phase is averaged.

Since the empirical cache updates with step size 1/(t+1)1/(t+1), its natural continuous time scale is st:=∑j=1t1j=log⁡t+O(1)s_t := \sum_{j=1}^{t} \frac{1}{j} = \log t + O(1); we use ss for this slow time variable. The corresponding equation for the empirical cache is

dηds=Γ(η)−η.(11)\frac{d\eta}{ds} = \Gamma(\eta)-\eta. \tag*{(11)}

Since ηs\eta_s is a probability distribution rather than a finite-dimensional vector, we interpret (11) by testing it against Lipschitz functions: for every φ:Z→R\varphi: \mathcal{Z} \to\mathbb{R},

dds∫Zφ(z) dηs(z)=∫Zφ(z) dΓ(ηs)(z)−∫Zφ(z) dηs(z).\frac{d}{ds} \int_{\mathcal{Z}} \varphi(z) \, d\eta_s(z) = \int_{\mathcal{Z}} \varphi(z) \, d\Gamma(\eta_s)(z) - \int_{\mathcal{Z}} \varphi(z) \, d\eta_s(z).

For a Lipschitz φ:Z→R\varphi: \mathcal{Z} \to\mathbb{R}, let

η(φ):=∫Zφ(z) dη(z),\eta(\varphi) := \int_{\mathcal{Z}} \varphi(z) \, d\eta(z),
Gφ(η,u,ω):=∑a∈Σqη,ω(a∣u)⋅φ(G(η,u,ω,a)).G_{\varphi}(\eta,u,\omega) := \sum_{a \in\Sigma} q_{\eta,\omega}(a \mid u) \cdot\varphi(G(\eta,u,\omega,a)).

Thus, η(φ)\eta(\varphi) is the average value of φ\varphi under the current cache distribution and Gφ(η,u,ω)G_{\varphi}(\eta,u,\omega) is the expected value of φ\varphi on the next cache entry, given frozen cache, current local state, and current phase. The next theorem shows that, over a long block on which the cache changes only slightly, the average change of η(φ)\eta(\varphi) is asymptotically Γ(η)(φ)−η(φ)\Gamma(\eta)(\varphi)-\eta(\varphi).

Theorem 8. Let k=k(p)k=k(p) satisfy k→∞k \to\infty and k2/p→0k^{2}/p \to0. Then, for every Lipschitz φ:Z→R\varphi: \mathcal{Z} \to\mathbb{R},

1k∑j=0k−1E[φ(zp+j+1)−ηp+j(φ)∣Fp]=Γ(ηp)(φ)−ηp(φ)+o(1),\frac{1}{k}\sum_{j=0}^{k-1}\mathbb{E}\left[\varphi(z_{p+j+1})-\eta_{p+j}(\varphi)\mid\mathcal{F}_{p}\right] = \Gamma(\eta_{p})(\varphi)-\eta_{p}(\varphi)+o(1),

where

Γ(η)(φ):=∫Zφ(z) dΓ(η)(z).\Gamma(\eta)(\varphi) := \int_{\mathcal{Z}} \varphi(z) \, d\Gamma(\eta)(z).

Proof. As noted before Lemma 7,

E[φ(zt+1)∣Ft]=Gφ(ηt,ut,ωt)+O(1/t).\mathbb{E}[\varphi(z_{t+1}) \mid\mathcal{F}_{t}] = G_{\varphi}(\eta_{t},u_{t},\omega_{t}) + O(1/t).

Over a block of kk steps beginning at time pp,

d1(ηp+j,ηp)=O(k/p),0≤j≤k.d_{1}(\eta_{p+j},\eta_{p}) = O(k/p), \qquad0 \le j \le k.

By the Lipschitz bounds above, we may therefore replace ηp+j\eta_{p+j} by ηp\eta_p at a total averaged cost O(k/p)O(k/p).

The same comparison used in the proof of Lemma 7 gives, uniformly for 0≤j≤k0 \leq j \leq k,

∥Pr⁡[up+j∈⋅∣Fp]−πηp(ωp+j)∥tv≤C((1−β)⌊j/W⌋+j2p),\left\lVert\Pr[u_{p+j} \in\mathord{\cdot} \mid\mathcal{F}_p] - \pi_{\eta_p}(\omega_{p+j}) \right\rVert_{\mathrm{tv}} \leq C\left((1-\beta)^{\lfloor j/W\rfloor}+\frac{j^2}{p}\right),

for a constant CC. Averaging over jj therefore gives

1k∑j=0k−1E[Gφ(ηp,up+j,ωp+j)∣Fp]=1k∑j=0k−1∑u∈ΣWπηp(ωp+j)(u)Gφ(ηp,u,ωp+j)+o(1).(12)\begin{aligned} \frac{1}{k}\sum_{j=0}^{k-1}\mathbb{E}[G_\varphi(\eta_p,u_{p+j},\omega_{p+j})\mid\mathcal{F}_p] \\ &=\frac{1}{k}\sum_{j=0}^{k-1}\sum_{u\in\Sigma^W}\pi_{\eta_p}(\omega_{p+j})(u)G_\varphi(\eta_p,u,\omega_{p+j})+o(1). \tag*{(12)} \end{aligned}

The function

ω↦∑u∈ΣWπηp(ω)(u)Gφ(ηp,u,ω)\omega\mapsto\sum_{u\in\Sigma^W}\pi_{\eta_p}(\omega)(u)G_\varphi(\eta_p,u,\omega)

is continuous. These functions depend continuously on η\eta and ω\omega. Since the possible cache distributions form a compact set, this family can be uniformly approximated by finitely many such functions. Lemma 5 therefore applies uniformly over this family and the RHS of (12) converges to

∫Hθ∑u∈ΣWπηp(ω)(u)Gφ(ηp,u,ω) dμθ(ω)=Γ(ηp)(φ).\int_{H_\theta}\sum_{u\in\Sigma^W}\pi_{\eta_p}(\omega)(u)G_\varphi(\eta_p,u,\omega)\,d\mu_\theta(\omega)=\Gamma(\eta_p)(\varphi).

Also, since d1(ηp+j,ηp)=O(k/p)d_1(\eta_{p+j},\eta_p)=O(k/p) for 0≤j≤k0\leq j\leq k,

1k∑j=0k−1E[ηp+j(φ)∣Fp]=ηp(φ)+o(1).\frac{1}{k}\sum_{j=0}^{k-1}\mathbb{E}[\eta_{p+j}(\varphi)\mid\mathcal{F}_p]=\eta_p(\varphi)+o(1).

Combining these estimates completes the proof.

Thus Γ(η)−η\Gamma(\eta)-\eta gives the average change of the empirical cache on the ss-time scale; but nothing here requires solutions of (11) to converge. Note that the bounds above also imply that Γ\Gamma is Lipschitz with respect to d1d_1: for some LΓ<∞L_\Gamma<\infty, d1(Γ(η),Γ(η′))≤LΓ⋅d1(η,η′)d_1(\Gamma(\eta),\Gamma(\eta'))\leq L_\Gamma\cdot d_1(\eta,\eta'). Indeed, this follows by comparing the corresponding factors πη\pi_\eta, qη,ωq_{\eta,\omega}, GG in the definition of Γ\Gamma. Thus (11) has a unique solution for any initial cache distribution.

Let η^(s)\widehat{\eta}(s) interpolate the values η^(st)=ηt\widehat{\eta}(s_t)=\eta_t linearly between consecutive sts_t’s. Theorem 8 identifies the average change of the cache over short blocks. The next result shows that these local approximations combine to describe the full cache trajectory on the ss-time scale.

Corollary 9. Let η(t)(s)\eta^{(t)}(s) be the solution of (11) with η(t)(0)=ηt\eta^{(t)}(0)=\eta_t. Then, for every fixed T<∞T<\infty,

sup⁡0≤s≤Td1(η^(st+s),η(t)(s))⟶0a.s.\sup_{0\leq s\leq T}d_1\left(\widehat{\eta}(s_t+s),\eta^{(t)}(s)\right)\longrightarrow0 \qquad\text{a.s.}

Thus ηt\eta_t tracks (11) a.s.

Proof. For a Lipschitz function φ:Z→R\varphi:\mathcal{Z}\to\mathbb{R}, the empirical cache update gives

ηt+1(φ)−ηt(φ)=1t+1(φ(zt+1)−ηt(φ)).\eta_{t+1}(\varphi)-\eta_t(\varphi)=\frac{1}{t+1}\left(\varphi(z_{t+1})-\eta_t(\varphi)\right).

By Theorem 8, over blocks that grow to infinity but remain short relative to the current time, the average conditional change is Γ(η)(φ)−η(φ)+o(1)\Gamma(\eta)(\varphi)-\eta(\varphi)+o(1), where η\eta is the cache state at the start of the block. Since the cache changes by o(1)o(1) across such a block and Γ\Gamma is Lipschitz, we can use the current cache state within the block. Partitioning any fixed interval of the ss-time scale into such blocks, Theorem 8 therefore shows that the accumulated difference between the conditional change and Γ(η)−η\Gamma(\eta)-\eta tends to zero.

The remaining random term is bounded and has conditional mean zero. After multiplying by 1/(t+1)1/(t+1), its weighted sum converges (a.s.) because ∑t1(t+1)2<∞\sum_t \frac{1}{(t+1)^2}<\infty. The O(1/t)O(1/t) approximation error used in § 5.1 contributes only O(1/t2)O(1/t^2) after multiplication by the step size, and is therefore summable as well.

Since Z\mathcal{Z} is compact, controlling finitely many 1-Lipschitz test functions up to an arbitrarily small error is enough to control d1d_1; hence the same bounds hold uniformly in the definition of d1d_1. Consequently, over every fixed interval of the ss-time scale, η^\widehat{\eta} satisfies

η^(st+s)=ηt+∫0s(Γ(η^(st+r))−η^(st+r)) dr+o(1),\widehat{\eta}(s_t+s)=\eta_t+\int_0^s\left(\Gamma\left(\widehat{\eta}(s_t+r)\right)-\widehat{\eta}(s_t+r)\right)\,dr+o(1),

where the error tends to zero uniformly for 0≤s≤T0\le s\le T in the distance d1d_1.

The exact solution η(t)\eta^{(t)} satisfies the same equation without the o(1)o(1) term. Since Γ\Gamma is Lipschitz, their distance is at most

o(1)+(LΓ+1)∫0sd1(η^(st+r),η(t)(r)) dr.o(1)+(L_\Gamma+1)\int_0^s d_1\left(\widehat{\eta}(s_t+r),\eta^{(t)}(r)\right)\,dr.

Repeated substitution in this inequality shows that, uniformly for 0≤s≤T0\le s\le T,

d1(η^(st+s),η(t)(s))≤o(1)e(LΓ+1)T;d_1\left(\widehat{\eta}(s_t+s),\eta^{(t)}(s)\right)\le o(1)e^{(L_\Gamma+1)T};

the RHS vanishes (a.s.).

High-Temperature Convergence

Corollary 9 shows that the empirical cache tracks (11), but does not imply that solutions of (11) converge. We now show that convergence does hold at sufficiently high temperature for every fixed transformer.

In this section we make the dependence on the temperature τ\tau explicit, writing qη,ω(τ)q^{(\tau)}_{\eta,\omega}, Qη,ω(τ)Q^{(\tau)}_{\eta,\omega}, πη(τ)\pi^{(\tau)}_{\eta}, and Γτ\Gamma_\tau. Let z~=(z(1),…,z(Lglob))\tilde{z}=(z^{(1)},\ldots,z^{(L_{\mathrm{glob}})}) be the cache vector where z(j)z^{(j)} contains the keys and values stored by the jjth global layer, and let η(j)\eta^{(j)} be the corresponding marginal of η\eta. Likewise, let G(η,u,ω,a)=(G(1)(η,u,ω,a),…,G(Lglob)(η,u,ω,a))G(\eta,u,\omega,a)=\left(G^{(1)}(\eta,u,\omega,a),\ldots,G^{(L_{\mathrm{glob}})}(\eta,u,\omega,a)\right).

For 0<δ<10<\delta<1, define

∥z−z′∥δ:=∑j=1Lglobδj−1∥z(j)−z′(j)∥.\lVert z-z'\rVert_\delta:=\sum_{j=1}^{L_{\mathrm{glob}}}\delta^{j-1}\lVert z^{(j)}-z'^{(j)}\rVert.

and let d1,δd_{1,\delta} denote the 1-Wasserstein distance induced by this norm. Since the number of layers is finite, d1,δd_{1,\delta} and d1d_1 are equivalent. We can now show the following contraction result on the expected next cache state for two different histories:

Lemma 10. For every small δ>0\delta>0, there are A(δ)A(\delta) and CδC_\delta with A(δ)→0A(\delta)\to0 as δ→0\delta\to0 such that

d1,δ(Γτ(η),Γτ(η′))≤(A(δ)+Cδτ)d1,δ(η,η′).(13)d_{1,\delta}\left(\Gamma_\tau(\eta),\Gamma_\tau(\eta')\right)\le\left(A(\delta)+\frac{C_\delta}{\tau}\right)d_{1,\delta}(\eta,\eta'). \tag*{(13)}

Proof. By the ordering of the layers, G(j)G^{(j)} can depend on the global cache only through global layers 1,…,j−11,\ldots,j-1. Hence there are constants Cji<∞C_{ji}<\infty such that

∥G(j)(η,u,ω,a)−G(j)(η′,u,ω,a)∥≤∑i<jCjid1(i)(η(i),η′(i)).\left\|G^{(j)}(\eta,u,\omega,a)-G^{(j)}(\eta',u,\omega,a)\right\| \le\sum_{i<j} C_{ji}d_1^{(i)}(\eta^{(i)},\eta'^{(i)}).

uniformly in u,ω,au,\omega,a, where d1(i)d_1^{(i)} denotes the distance d1d_1 on the cache coordinates of layer ii. This follows from (5) and the Lipschitz assumptions, applied through the layers; in particular, G(1)G^{(1)} does not depend on η\eta.

A function of z(i)z^{(i)} that is 1-Lipschitz in that coordinate is δ−(i−1)\delta^{-(i-1)}-Lipschitz under ∥⋅∥δ\|\cdot\|_\delta. Therefore,

d1(i)(η(i),η′(i))≤δ−(i−1)⋅d1,δ(η,η′).d_1^{(i)}(\eta^{(i)},\eta'^{(i)}) \le\delta^{-(i-1)}\cdot d_{1,\delta}(\eta,\eta').

It follows that

∥G(η,u,ω,a)−G(η′,u,ω,a)∥δ≤A(δ)⋅d1,δ(η,η′),\left\|G(\eta,u,\omega,a)-G(\eta',u,\omega,a)\right\|_\delta\le A(\delta)\cdot d_{1,\delta}(\eta,\eta'),

where

A(δ):=∑j=2Lglob∑i<jCji⋅δj−i.A(\delta):=\sum_{j=2}^{L_{\mathrm{glob}}}\sum_{i<j} C_{ji}\cdot\delta^{j-i}.

Thus A(δ)→0A(\delta)\to0 as δ→0\delta\to0.

We next consider the next token distribution. The argument used for (9), stopped just before the final softmax, shows that the pre-temperature output logits are Lipschitz in η\eta. Since the derivative of softmax(x/τ)(x/\tau) is O(1/τ)O(1/\tau), for every fixed δ\delta there is a constant Cδ<∞C_\delta<\infty such that, for all sufficiently large τ\tau,

sup⁡u,ω∥qη,ω(τ)(⋅∣u)−qη′,ω(τ)(⋅∣u)∥tv≤Cδτ⋅d1,δ(η,η′).\sup_{u,\omega}\left\|q_{\eta,\omega}^{(\tau)}(\cdot\mid u)-q_{\eta',\omega}^{(\tau)}(\cdot\mid u)\right\|_{\mathrm{tv}}\le\frac{C_\delta}{\tau}\cdot d_{1,\delta}(\eta,\eta').

The same bound therefore holds for the corresponding transition matrices Qη,ω(τ)Q_{\eta,\omega}^{(\tau)}.

For sufficiently large τ\tau, the lower bound in (6), and hence the contraction in (7), can be chosen uniformly in τ\tau. Repeating the proof of Lemma 6 therefore gives

sup⁡ω∈Hθ∥πη(τ)(ω)−πη′(τ)(ω)∥tv≤Cδτ⋅d1,δ(η,η′),\sup_{\omega\in H_\theta}\left\|\pi_\eta^{(\tau)}(\omega)-\pi_{\eta'}^{(\tau)}(\omega)\right\|_{\mathrm{tv}}\le\frac{C_\delta}{\tau}\cdot d_{1,\delta}(\eta,\eta'),

after increasing CδC_\delta if necessary.

We can now compare Γτ(η)\Gamma_\tau(\eta) and Γτ(η′)\Gamma_\tau(\eta').

(i) If the weights πη(τ)(ω)(u)qη,ω(τ)(a∣u)\pi_\eta^{(\tau)}(\omega)(u)q_{\eta,\omega}^{(\tau)}(a\mid u) are kept fixed and only the point G(η,u,ω,a)G(\eta,u,\omega,a) is replaced by G(η′,u,ω,a)G(\eta',u,\omega,a), the change is at most A(δ)⋅d1,δ(η,η′)A(\delta)\cdot d_{1,\delta}(\eta,\eta').

(ii) If the points are kept fixed and the weights are changed, the bounds above give a change of at most Cδτ⋅d1,δ(η,η′)\frac{C_\delta}{\tau}\cdot d_{1,\delta}(\eta,\eta'). Hence

d1,δ(Γτ(η),Γτ(η′))≤(A(δ)+Cδτ)d1,δ(η,η′).□d_{1,\delta}\left(\Gamma_\tau(\eta),\Gamma_\tau(\eta')\right)\le\left(A(\delta)+\frac{C_\delta}{\tau}\right)d_{1,\delta}(\eta,\eta').\quad\square

We have the ingredients to prove high-temperature convergence.

Theorem 11. For every transformer satisfying the assumptions of this section, there is a finite τc\tau_c such that, for every τ>τc\tau>\tau_c, Γτ\Gamma_\tau has a unique fixed point ητ∗\eta_\tau^*. Every solution of dηds=Γτ(η)−η\frac{d\eta}{ds}=\Gamma_\tau(\eta)-\eta converges exponentially to ητ∗\eta_\tau^*, and d1(ηt,ητ∗)⟶0d_1(\eta_t,\eta_\tau^*)\longrightarrow0 a.s.

Proof. Choose δ>0\delta> 0 small enough that A(δ)<1/4A(\delta) < 1/4, and choose τc\tau_c large such that all the preceding large temperature bounds hold and τc>4Cδ\tau_c > 4C\delta. By (13), for every τ>τc\tau> \tau_c, Γτ\Gamma_\tau is a contraction under d1,δd_{1,\delta}; let κ<1\kappa< 1 be its contraction constant. Since Z\mathcal{Z} is compact, iterating Γτ\Gamma_\tau gives a unique fixed point ητ∗\eta_\tau^*.

Let ηs\eta_s be any solution of the ODE. Its integral form is

ηs=e−sη0+∫0se−(s−r)Γτ(ηr) dr.\eta_s=e^{-s}\eta_0+\int_0^s e^{-(s-r)}\Gamma_\tau(\eta_r)\,dr.

Using Γτ(ητ∗)=ητ∗\Gamma_\tau(\eta_\tau^*)=\eta_\tau^* and the contraction bound,

d1,δ(ηs,ητ∗)≤e−sd1,δ(η0,ητ∗)+κ∫0se−(s−r)d1,δ(ηr,ητ∗) dr,d_{1,\delta}(\eta_s,\eta_\tau^*)\le e^{-s}d_{1,\delta}(\eta_0,\eta_\tau^*)+\kappa\int_0^s e^{-(s-r)}d_{1,\delta}(\eta_r,\eta_\tau^*)\,dr,

and repeated substitution gives

d1,δ(ηs,ητ∗)≤e−(1−κ)sd1,δ(η0,ητ∗).(14)d_{1,\delta}(\eta_s,\eta_\tau^*)\le e^{-(1-\kappa)s}d_{1,\delta}(\eta_0,\eta_\tau^*). \tag*{(14)}

It remains to return to the stochastic cache process. Since d1,δd_{1,\delta} and d1d_1 are equivalent, Corollary 9 also gives uniform tracking in d1,δd_{1,\delta} over every fixed interval of the ss-time scale. Choose T>0T > 0 and let ρ:=e−(1−κ)T<1\rho:= e^{-(1-\kappa)T} < 1; choose times t0<t1<⋯t_0 < t_1 < \cdots so that stm+1−stm→Ts_{t_{m+1}}-s_{t_m}\to T. Applying Corollary 9 on each interval and using (14),

d1,δ(ηtm+1,ητ∗)≤ρ d1,δ(ηtm,ητ∗)+o(1)a.s.d_{1,\delta}(\eta_{t_{m+1}},\eta_\tau^*)\le\rho\,d_{1,\delta}(\eta_{t_m},\eta_\tau^*)+o(1)\qquad\text{a.s.}

Hence d1,δ(ηtm,ητ∗)→0d_{1,\delta}(\eta_{t_m},\eta_\tau^*)\to0 (a.s.) The same bound on the intervals between consecutive tmt_m yields d1,δ(ηt,ητ∗)⟶0d_{1,\delta}(\eta_t,\eta_\tau^*)\longrightarrow0 (a.s.) Now, the equivalence of d1,δd_{1,\delta} and d1d_1 completes the proof. □

Thus every fixed transformer has a sufficiently high-temperature regime in which the empirical cache converges. The threshold τc\tau_c may depend on the architecture and its weights.

Non-Convergence

We now give an example showing that even the simplified single-layer transformer of § 3 need not converge. Let Σ={1,2,3}\Sigma= \{1,2,3\}, d=2d = 2, and temperature τ=1\tau= 1. Define

v1=(1,0),v2=(−12,32),v3=(−12,−32),v_1=(1,0),\qquad v_2=\left(-\frac{1}{2},\frac{\sqrt{3}}{2}\right),\qquad v_3=\left(-\frac{1}{2},-\frac{\sqrt{3}}{2}\right),

and let Ein[i]=viE_{\mathrm{in}}[i]=v_i. Set

WQ=WK=0,WV=I.W_Q=W_K=0,\qquad W_V=I.

All attention scores are then zero, so for every query token the attention output is

o(P)=∑i=13P(i)vi.o(P)=\sum_{i=1}^{3}P(i)v_i.

Fix a constant c>6c > 6 and choose the output embeddings cyclically as

Eout[1]=−2c3v2,Eout[2]=−2c3v3,Eout[3]=−2c3v1.E_{\mathrm{out}}[1]=-\frac{2c}{3}v_2,\qquad E_{\mathrm{out}}[2]=-\frac{2c}{3}v_3,\qquad E_{\mathrm{out}}[3]=-\frac{2c}{3}v_1.

Since

⟨o(P),vi⟩=32P(i)−12,\langle o(P), v_i \rangle= \frac{3}{2}P(i) - \frac{1}{2},

the output logits, up to a common additive constant, are

−cP(2),−cP(3),−cP(1).-cP(2), \qquad-cP(3), \qquad-cP(1).

Thus every row of MPM_P is the same distribution q(P)q(P), where, with indices interpreted cyclically,

qi(P)∝exp⁡(−cP(i+1)),i=1,2,3.q_i(P) \propto\exp(-cP(i+1)), \qquad i=1,2,3.

Consequently π∗(P)=q(P)\pi^*(P)=q(P) and the limiting ODE is

dPdt=q(P)−P.\frac{dP}{dt}=q(P)-P.

This ODE has a unique fixed point

Pˉ=(13,13,13).\bar{P}=\left(\frac{1}{3},\frac{1}{3},\frac{1}{3}\right).

Indeed, at any fixed point,

P(i)>P(j)⟺P(i+1)<P(j+1).P(i)>P(j) \quad\Longleftrightarrow\quad P(i+1)<P(j+1).

If, for example, P(1)>P(2)P(1)>P(2), then P(3)>P(2)P(3)>P(2), which implies P(3)>P(1)P(3)>P(1), which in turn implies P(2)>P(1)P(2)>P(1), a contradiction. Hence all three coordinates must be equal.

The fixed point is unstable when c>6c>6. The Jacobian of qq at Pˉ\bar{P}, restricted to the tangent plane {x:1⊤x=0}\{x: \mathbf{1}^{\top}x=0\}, is

Jq(Pˉ)=−c3S,S(x1,x2,x3)=(x2,x3,x1).J_q(\bar{P})=-\frac{c}{3}S,\qquad S(x_1,x_2,x_3)=(x_2,x_3,x_1).

The two eigenvalues of the Jacobian of q(P)−Pq(P)-P on this plane are

c6−1±i3c6.\frac{c}{6}-1 \pm i\frac{\sqrt{3}c}{6}.

Their real parts are positive for c>6c>6, so Pˉ\bar{P} is a linearly unstable equilibrium.

Finally, the stochastic process itself cannot converge. Since qi(P)q_i(P) is uniformly bounded away from zero on the simplex, the sampling noise is nondegenerate in every direction tangent to the simplex. The standard non-convergence result for linearly unstable equilibria in stochastic approximation ([2 Section 9]) therefore gives

Pr⁡[Pt→Pˉ]=0.\Pr[P_t\to\bar{P}]=0.

By Lemma 1, if PtP_t converged, its limit would have to be a fixed point of the ODE. Since Pˉ\bar{P} is the only fixed point, PtP_t does not converge almost surely.

Note that the limiting ODE in this construction is a cyclic three-strategy logit best-response dynamic, closely related to the rock–paper–scissors models studied by Hommes and Ochea [13]. Our contribution is to realize this dynamic within an explicit single-layer, attention-only transformer and establish the non-convergence of its empirical token frequencies.

Thus, we have a single-layer, NoPE, attention-only transformer that fails to converge almost surely at temperature 1. To extend this to any given temperature τ0>0\tau_0>0, we multiply all of its output embeddings by τ0\tau_0. Since output logits are divided by τ0\tau_0 before the softmax, the next token distribution q(P)q(P) is unchanged by this operation. Thus the same ODE and the same non-convergence argument apply at temperature τ0\tau_0. We obtain the following stronger statement.

Phase portrait of the three-token example

Figure 3. Phase portrait of the three-token example in § 6, with c=7c = 7. The unique equilibrium Pˉ=(1/3,1/3,1/3)\bar{P} = (1/3, 1/3, 1/3) is a repelling focus. The teal curve is a numerically computed attracting periodic orbit of the limiting ODE. Trajectories starting inside (orange) and outside (gray) the orbit spiral toward it in a counterclockwise direction. The shaded sectors indicate the most probable next token: red for token 1, green for token 2, and blue for token 3. The trajectories represent the limiting deterministic dynamics, not individual stochastic sample paths.

Theorem 12. For every temperature τ0>0\tau_0 > 0, there is a single-layer, NoPE, attention-only transformer with no MLP whose empirical token distribution fails to converge almost surely when sampled at temperature τ0\tau_0.

Recall Theorem 11, which fixes the transformer and then takes the temperature sufficiently large. In contrast, in Theorem 12, the temperature τ0\tau_0 is fixed and the transformer is allowed to depend on τ0\tau_0. Thus every fixed transformer has a high temperature convergence regime, but there is no finite temperature that guarantees convergence uniformly over all transformers.

Related Work

Dynamical and mean-field analyses of attention. Several recent works study self-attention as a dynamical or mean-field system. This includes work on clustering in self-attention [10], mean-field models with layer normalization [4], meta-stable clustering [3], synchronization phenomena [24], and broader mean-field formulations of transformer dynamics [29, 36]. Other work gives exact mean-field analyses in simplified attention models [8] and studies mean-field descriptions of in-context feature learning [18]. These papers primarily analyze the evolution of representations across layers, training, or an idealized population. Our setting instead follows a fixed autoregressive model forward in generation time, where the empirical history itself changes after every generated token.

There are also other mathematical views of attention. Katharopoulos et al. [16] show that linearized autoregressive attention admits a recurrent formulation, Ramsauer et al. [27] relate softmax attention to modern Hopfield networks and associative memory, and Dong et al. [9] study rank collapse under repeated pure self-attention. Our use of stochastic approximation follows Benaïm [2] to compare a slowly changing stochastic process with an ODE.

Related dynamical analyses. Other works include symmetry breaking in attention [33], synchronization-inspired transformer architectures [19], and residual-aware cumulative attention dynamics [11]. These works study related dynamical phenomena, but not the infinite-generation limit we consider.

Transformers and positional information. Vaswani et al. [37] use absolute sinusoidal position encodings while later work use relative position representations, e.g., directly into self-attention [32], combining a recurrent memory across segments [6], or adding a distance-dependent linear bias to the attention scores [25]. RoPE rotates query and key vectors as a function of position so that their inner product depends on relative position [34].

The choice of positional representation is closely related to length generalization. Kazemnejad et al. [17] compare several positional schemes, including RoPE, ALiBi, and NoPE, and observe good length generalization for NoPE on many tasks.

This phenomenon has also been studied theoretically for NoPE [38], and more broadly for length generalization in causal transformers [15]. Randomized positional encodings have also been used in this context [30].

Length extrapolation and RoPE. A different line of research asks how a model trained at one context length can be used at a larger one. Sun et al. [35] study architectural choices for length extrapolation. Position interpolation rescales position indices for pretrained RoPE models [5], YaRN modifies RoPE scaling to extend context windows efficiently [23], and LongRoPE uses non-uniform interpolation and progressive extension to reach longer contexts [7]. Other work studies limitations and variants of RoPE itself, including the relation between the RoPE base and usable context length [41], the distribution of information across RoPE frequencies [22], and wavelet-based rotary encodings [28]. These works are concerned with extrapolating a trained model to longer inputs. We, on the other hand, study the limiting behavior of a fixed model.

Long-context attention and memory. Another line of work changes the attention or memory mechanism itself. Transformer-XL reuses hidden states from previous segments [6], and the Compressive Transformer stores older states in compressed form [26]. Longformer combines local windowed attention with selected global attention [1], while BigBird uses a sparse mixture of local, random, and global connections [42]. Memorizing Transformers augment the model with retrieval from a memory of past key–value representations [39]. StreamingLLM retains a small set of initial “attention sink” tokens together with a recent window [40], while Infini-attention combines local attention with a bounded compressive memory [21]. In contrast, we keep ordinary global attention and study the statistics of its growing KV cache.

Conclusion

We studied the long-run behavior of transformers through the slowly changing empirical state generated by their own outputs. In both the single-layer and multi-layer settings, the stochastic process tracks an ODE on an appropriate time scale. For every fixed transformer in our model, sufficiently high temperature makes this ODE contractive and forces convergence to a unique limiting state. This threshold is model-dependent: at every fixed finite temperature, some transformer can have a limiting ODE that does not converge. Thus temperature controls long-run stability, but there is no universal finite temperature that guarantees convergence for all transformers.

AI use statement

In this work, we used generative AI tools only to formulate mathematical claims; provide critical ingredients for proving mathematical claims; assist in the writing of proofs. We have not used generative AI tools to help develop theoretical models or conceptual frameworks; propose or refine hypotheses; interpret results; generate synthetic data sets; design or provide feedback on research methodology or experiments; implement methods; assist with translation; clean and reformat datasets; support qualitative and thematic data analysis are not applicable to this work. Additionally, we used generative AI tools to draft parts of a research paper; identify relevant literature. All LLM-assisted proofs were checked and fully rewritten by the authors. We take responsibility for the final content of this work, including text, claims, or artifacts produced with the aid of generative AI.

References

  1. [1]Iz Beltagy, Matthew E. Peters, and Arman Cohan. Longformer: The long-document transformer. arXiv, 2004.05150, 2020.arxiv.org/abs/2004.05150
  2. [2]Michel Benaïm. Dynamics of stochastic approximation algorithms. In Séminaire de Probabilités XXXIII, volume 1709, pages 1–68. Springer, 1999.DOI
  3. [3]Giuseppe Bruno, Federico Pasqualotto, and Andrea Agazzi. Emergence of meta-stable clustering in mean-field transformer models. In ICLR, 2025.arxiv.org/abs/2410.23228
  4. [4]Martin Burger, Samira Kabri, Yury Korolev, Tim Roith, and Lukas Weigand. Analysis of mean-field models arising from self-attention dynamics in transformer architectures with layer normalization. Phil. Trans. Royal Soc. A: Math., Phys., Engg. Sci., 383(2298), 2025.arxiv.org/abs/2501.03096
  5. [5]Shouyuan Chen, Sherman Wong, Liangjian Chen, and Yuandong Tian. Extending context window of large language models via positional interpolation. arXiv, 2306.15595, 2023.arxiv.org/abs/2306.15595
  6. [6]Zihang Dai, Zhilin Yang, Yiming Yang, Jaime Carbonell, Quoc Le, and Ruslan Salakhutdinov. Transformer-XL: Attentive language models beyond a fixed-length context. In ACL, pages 2978–2988, 2019.arxiv.org/abs/1901.02860
  7. [7]Yiran Ding, Li Lyna Zhang, Chengruidong Zhang, Yuanyuan Xu, Ning Shang, Jiaheng Xu, Fan Yang, and Mao Yang. LongRoPE: Extending LLM context window beyond 2 million tokens. In ICML, pages 11091–11104, 2024.arxiv.org/abs/2402.13753
  8. [8]Elvis Dohmatob. Understanding softmax attention layers: Exact mean-field analysis on a toy problem. In NeurIPS, 2025.DOI
  9. [9]Yihe Dong, Jean-Baptiste Cordonnier, and Andreas Loukas. Attention is not all you need: Pure attention loses rank doubly exponentially with depth. In ICML, pages 2793–2803, 2021.arxiv.org/abs/2103.03404
  10. [10]Borjan Geshkovski, Cyril Letrouit, Yury Polyanskiy, and Philippe Rigollet. The emergence of clusters in self-attention dynamics. In NeurIPS, 2023.DOI
  11. [11]Hanna Herasimchyk, Robin Labryga, Tomislav Prusina, and Sören Laue. A structural theory of position bias in transformers. arXiv, 2602.16837, 2026.arxiv.org/abs/2602.16837
  12. [12]Masato Hisakado and Shintaro Mori. Two kinds of phase transitions in a voting model. J. Phys. A: Math. Theor., 45(34):345002, 2012.
  13. [13]Cars H. Hommes and Marius I. Ochea. Multiple equilibria and limit cycles in evolutionary games with Logit Dynamics. Games Econ. Behav., 74(1):434–441, 2012.DOI
  14. [14]Jie Huang, Xinyun Chen, Swaroop Mishra, Huai­xiu Steven Zheng, Adams Wei Yu, Xinying Song, and Denny Zhou. Large language models cannot self-correct reasoning yet. In ICLR, 2024.arxiv.org/abs/2310.01798
  15. [15]Xinting Huang, Andy Yang, Satwik Bhattamishra, Yash Sarrof, Andreas Krebs, Hattie Zhou, Preetum Nakkiran, and Michael Hahn. A formal framework for understanding length generalization in transformers. In ICLR, 2025.arxiv.org/abs/2410.02140
  16. [16]Angelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas, and François Fleuret. Transformers are RNNs: Fast autoregressive transformers with linear attention. In ICML, pages 5156–5165, 2020.arxiv.org/abs/2006.16236
  17. [17]Amirhossein Kazemnejad, Inkit Padhi, Karthikeyan Natesan Ramamurthy, Payel Das, and Siva Reddy. The impact of positional encoding on length generalization in transformers. In NeurIPS, 2023.arxiv.org/abs/2305.19466
  18. [18]Juno Kim and Taiji Suzuki. Transformers learn nonlinear features in-context: nonconvex mean-field dynamics on the attention landscape. In ICML, 2024.arxiv.org/abs/2402.01258
  19. [19]Jingkun Liu, Yisong Yue, Max Welling, and Yue Song. Krause synchronization transformers. In ICML, 2026.arxiv.org/abs/2602.11534
  20. [20]Shintaro Mori and Masato Hisakado. Correlation function for generalized Pólya urns: Finite-size scaling analysis. Phy. Rev. E, 92(5):052112, 2015.DOI
  21. [21]Tsendsuren Munkhdalai, Manaal Faruqui, and Siddharth Gopal. Leave no context behind: Efficient infinite context transformers with infini-attention. arXiv, 2404.07143, 2024.arxiv.org/abs/2404.07143
  22. [22]Yui Oka, Kentaro Hanafusa, Taku Hasegawa, Kyosuke Nishida, and Kuniko Saito. Probing rotary position embeddings through frequency entropy. In ICLR, 2026.
  23. [23]Bowen Peng, Jeffrey Quesnelle, Honglu Fan, and Enrico Shippole. YaRN: Efficient context window extension of large language models. In ICLR, 2024.arxiv.org/abs/2309.00071
  24. [24]Yury Polyanskiy, Philippe Rigollet, and Andrew Yao. Synchronization of mean-field models on the circle. arXiv, 2507.22857, 2025.arxiv.org/abs/2507.22857
  25. [25]Ofir Press, Noah A. Smith, and Mike Lewis. Train short, test long: Attention with linear biases enables input length extrapolation. In ICLR, 2022.arxiv.org/abs/2108.12409
  26. [26]Jack W. Rae, Anna Potapenko, Siddhant M. Jayakumar, Chloe Hillier, and Timothy P. Lillicrap. Compressive transformers for long-range sequence modelling. In ICLR, 2020.arxiv.org/abs/1911.05507
  27. [27]Hubert Ramsauer et al. Hopfield networks is all you need. In ICLR, 2021.arxiv.org/abs/2008.02217
  28. [28]Isaac Reid, Arijit Sehanobish, Cederik Höfs, Bruno Kacper Mlodozeniec, Leonhard Vulpius, Federico Barbero, Adrian Weller, Krzysztof Marcin Choromanski, Richard E. Turner, and Petar Velicković. Rotary position encodings for graphs. In ICML, 2026.arxiv.org/abs/2509.22259
  29. [29]Philippe Rigollet. The mean-field dynamics of transformers. In ICM, pages 389–404, 2026.
  30. [30]Anian Ruoss, Grégoire Delétang, Tim Genewein, Jordi Grau-Moya, Röbert Csordás, Mehdi Bennani, Shane Legg, and Joel Veness. Randomized positional encodings boost length generalization of transformers. In ACL, 2023.
  31. [31]Mrinank Sharma, Meg Tong, Tomasz Korbak, David Duvenaud, Amanda Askell, Samuel R. Bowman, Esin Durmus, Zac Hatfield-Dodds, Scott R. Johnston, Shauna Kravec, Timothy Maxwell, Sam McCandlish, Kamal Ndousse, Oliver Rausch, Nicholas Schiefer, Da Yan, Miranda Zhang, and Ethan Perez. Towards understanding sycophancy in language models. In ICLR, 2024.arxiv.org/abs/2310.13548
  32. [32]Peter Shaw, Jakob Uszkoreit, and Ashish Vaswani. Self-attention with relative position representations. In NAACL, pages 464–468, 2018.arxiv.org/abs/1803.02155
  33. [33]Eva Silverstein, Daniel Kunin, and V. Shyam. Symmetry breaking in transformers for efficient and interpretable training. arXiv, 2601.22257, 2026.arxiv.org/abs/2601.22257
  34. [34]Jianlin Su, Murtadha H. M. Ahmed, Yu Lu, Shengfeng Pan, Wen Bo, and Yunfeng Liu. Roformer: Enhanced transformer with rotary position embedding. Neurocomputing, 568:127063, 2024.arxiv.org/abs/2104.09864
  35. [35]Yutao Sun, Li Dong, Barun Patra, Shuming Ma, Shaohan Huang, Alon Benhaim, Vishrav Chaudhary, Xia Song, and Furu Wei. A length-extrapolatable transformer. In ACL, pages 14590–14604, 2023.
  36. [36]Hamidou Tembine, Manzoor Ahmed Khan, and Issa Bamia. Mean-field-type transformers. Mathematics, 12(22):3506, 2024.
  37. [37]Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. Attention is all you need. In NIPS, 2017.arxiv.org/abs/1706.03762
  38. [38]Jie Wang, Tao Ji, Yuanbin Wu, Hang Yan, Tao Gui, Qi Zhang, Xuanjing Huang, and Xiaoling Wang. Length generalization of causal transformers without position encoding. In ACL (Findings), 2024.arxiv.org/abs/2404.12224
  39. [39]Yuhui Wu, Markus N. Rabe, DeLesley Hutchins, and Christian Szegedy. Memorizing transformers. In ICLR, 2022.arxiv.org/abs/2203.08913
  40. [40]Guangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han, and Mike Lewis. Efficient streaming language models with attention sinks. In ICLR, 2024.arxiv.org/abs/2309.17453
  41. [41]Mingyu Xu, Xin Men, Bingning Wang, Qingyu Zhang, Hongyu Lin, Yaojie Lu, Xianpei Han, and Weipeng Chen. Base of rope bounds context length. In NeurIPS, pages 87386–87410, 2024.arxiv.org/abs/2405.14591
  42. [42]Manzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie, Chris Alberti, Santiago Ontanon, Philip Pham, Anirudh Ravula, Qifan Wang, Li Yang, and Amr Ahmed. Big bird: Transformers for longer sequences. In NeurIPS, 2020.arxiv.org/abs/2007.14062

Paper details

vlnc:W_xqkdxe3c
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 10

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents