WorksMathematics
From Low-Dimensional Chaos to High-Dimensional Dynamics in Self-Attention Systems
Abstract
Continuous-time particle models of self-attention are often studied under symmetry assumptions that yield a gradient structure and constrain the dynamics to convergence toward equilibria. We investigate the behavior of these systems beyond the gradient setting, considering autonomous projected self-attention models with constant query, key, and value matrices and particles constrained to an ellipse. For three particles, the equations define a vector field on the three-dimensional torus. We derive explicit synchronized periodic solutions and compute their Floquet multipliers, establishing the existence of non-gradient dynamics. Numerical explorations using bifurcation diagrams, Poincare sections, periodic-orbit continuation, a nd Lyapunov exponents reveal attracting periodic orbits, invariant-torus-like behavior, and strong evidence of chaos. We then construct higher-dimensional systems by coupling these low-dimensional building blocks through masked and multi-head attention mechanisms. We discuss the persistence of normally hyperbolic invariant manifolds under weak coupling and investigate how the coupling architecture influences the resulting dynamics. Numerical experiments reveal the emergence of additional expanding directions, including a 60-particle system in which 26 of the 40 computed Lyapunov exponents exceed 0.01. These results demonstrate the richness of the dynamical behavior possible in simplified self-attention systems and motivate further investigation of the invariant structures organizing their high-dimensional dynamics.
Introduction
The 2017 paper Attention Is All You Need by Vaswani et al. [1] introduced a novel network architecture called a transformer and spurred rapid advances in text-based generative artificial intelligence (AI). In the years since, transformers have become ubiquitous in Large Language Models (LLMs) including OpenAI’s ChatGPT, Anthropic’s Claude, and Meta’s Llama [2, 3, 4] to name only a few. Indeed, GPT stands for Generative Pre-trained Transformer [5].
Very roughly speaking, the attention mechanism (formalized in Equation (1) below) treats a language token as a particle on a compact manifold and a text prompt as a cloud of such particles. The transformer is a layered network which reorganizes the point cloud, so that an appropriate average of the output state provides the most likely next token. As the cloud of particles passes through the network, each particle nudges — and is nudged — by the others. The strength of the adjustment is determined by the current state of the whole cloud. Projection onto the constraint manifold prevents unbounded growth of particle trajectories.
A concise mathematical description of this operation replaces network depth, in an appropriate limit, by continuous time. This results in a system of differential equations on the constraint manifold (see Equation (2) below), where field interactions between particles encode prompt context. That is, the same language token follows a different path, and shapes the trajectories of its neighbors differently, depending on the relative positions of the particles.
The particle-system viewpoint of attention has roots in the work of Lu et al. [6] and in the measure-theoretic treatments of Vuckovic et al. [7] and also Sander et al. [8]. For more discussion from a decidedly mathematical physics perspective, we refer to the work of Geshkovski, Letrouit, Polyanskiy, and Rigollet [9, 10], whose approach we follow below, and to Polyanskiy, Rigollet, and Yao [11] for the case of the circle.
To formalize the discussion, let be the dimension of the token embedding space, and be a symmetric, positive-definite matrix. Define the ellipsoid
and the projection operator by
Let denote the width of the context window, that is, the number of language tokens in the prompt (i.e. the number of particles in the system). We write to denote the individual tokens, and to represent the entire prompt. That is, represents a state of the self-attention transformer.
Let and be smooth, matrix-valued functions. These are referred to as the query, key, and value matrices, respectively. (See Remark 1 below for the meaning of these terms in machine learning applications). For , define the attention coefficients, or attention weights, by
The denominator is referred to as the normalization of the attention weight, and the parameter is referred to as the temperature of the system. The equations of motion for the continuous-time, single-head, self-attention particle system are given by the following projected vector field
These provide the equations of motion for the particle system on the ellipsoid. The output of the transformer is an appropriate average of the state of the system after some specified time .
Remark 1 (Interpretation of the attention mechanism). These choices, and the accompanying terminology, are more thoroughly justified and contextualized in [9, 10]. The interested reader is referred also to [6, 12, 13, 14] and the references therein. Nevertheless, we formulate a few brief clarifying remarks.
The query, key, and value matrices have distinct roles in the attention mechanism of Vaswani et al. [1]. The query represents the information sought by particle , while the key represents the information made available by particle . Their inner product measures the compatibility of these quantities, determining the relative strength of the particle interaction. The value represents the information transmitted by particle to particle . Thus, the attention mechanism is a weighted average of the token values, with weights determined by query-key compatibility.
The softmax normalization is common in statistical mechanics and information theory. For fixed , writing , the attention weights form a Gibbs probability distribution,
For (that is, temperature less than infinity), the Gibbs distribution uniquely maximizes
over the probability simplex, where is Shannon entropy. (This functional is the negative free energy, with energies and temperature .) Thus, controls competition between selecting strongly compatible particles and distributing attention more uniformly. As , the weights approach , while as , attention concentrates on the particles with maximal compatibility. The weights are positive and sum to one, and they depend smoothly on the particle configuration, since the exponential is smooth and the denominator is positive.
Remark 2 (Model fidelity). The system given by Equation (2) is an idealization of the architecture introduced in [1], and of those used in practical applications. The constraint to the ellipsoid plays the role of layer normalization, but practical transformers differ from the model in at least three ways. First, they use multiple attention heads, each with its own query, key, and value matrices; in continuous time this corresponds to a sum of single-head terms. Second, attention layers are often combined with feedforward layers, adding a velocity field which acts on each particle separately. In an appropriate continuous-depth limit, such layers lead to neural-ODE networks [15]. Third, attention is often masked, so that each particle interacts with only a subset of the others. Causal masking in autoregressive language models, where each token attends only to the tokens preceding it, is one example [16, 14]; masks encoding graph or type structure, as in graph and heterogeneous attention architectures [17, 18], are another.
This said, the system of Equation (2) is nevertheless a building block for more realistic systems like the multi-head attention actually employed in [1]. In the present work (see Section 4) we use masked multi-head attention to assemble more realistic systems out of the building blocks considered in § 2.
An important qualitative result informing our understanding of the emergence of consensus, clustering, and metastability in self-attention systems is that, under appropriate symmetry restrictions on the query, key, and value matrices, these systems have gradient structure. Such structure severely constrains the dynamics: in an analytic gradient system on a compact manifold, every orbit converges, in both forward and backward time, to an equilibrium (not necessarily the same one). The theorem below follows, by a linear change of variables, from the spherical gradient-flow construction of Geshkovski, Letrouit, Polyanskii, and Rigolet [10 Section 1.2.4].
Theorem 3 (Gradient structure of symmetric self-attention). Suppose that and that , , and are constant, with
Define
and equip with the Riemannian metric
Then (2) is the gradient-ascent flow of with respect to . Along every solution,
with equality if and only if is an equilibrium. In particular, there are no nonconstant periodic solutions, and every trajectory converges to an equilibrium in forward and backward time.
The last assertion follows from analyticity, compactness, and the Łojasiewicz gradient inequality. The theorem and its generalizations illuminate important aspects of clustering and the long-time organization of token configurations. For related results and complementary viewpoints, we refer to [9, 19, 10, 12, 14, 20].
While Theorem 3 provides a powerful description of the qualitative dynamics, the algebraic hypotheses are in fact quite restrictive. Typical applications to machine learning impose no such constraints on the query, key, and value matrices during training [1], and since and the symmetry of are nongeneric in the set of real matrices, these conditions should be expected to fail in general. We refer to Tomihari and Karakida [21] for another perspective on self-attention in the absence of an energy function.
The goal of the present work is to explore how far transformer dynamics can depart from this gradient picture. To this end, we consider the elementary case of three particles on an ellipse in , with constant but otherwise unrestricted attention matrices. The right-hand side of Equation (2) defines a vector field on that is tangent to the embedded torus . In angular coordinates, that is, on the universal cover , it becomes a system of three unprojected ordinary differential equations, -periodic in each angle variable, and the dynamics of three-dimensional vector fields are much easier to visualize.
We begin our study by giving conditions under which this three-dimensional example system possesses nonconstant periodic orbits. For such parameters the system admits no strict Lyapunov function on the torus and, in particular, is not the gradient flow of any single-valued energy with respect to any Riemannian metric. Consequently, such parameters necessarily violate the hypotheses of Theorem 3.
Next, we present numerical explorations of the three-particle system using classical tools from computational dynamics such as Poincaré sections, Lyapunov exponents, periodic-orbit continuation, and bifurcation diagrams. The computations reveal periodic windows, changes of stability of periodic orbits, and provide compelling numerical evidence for the existence of chaotic attractors.
Finally, we show how elementary low-dimensional attention systems can be assembled into higher-dimensional models using masked multi-head attention. That is, we construct examples where, at zero coupling, we have a product of independently evolving systems whose dynamics we choose. Increasing the coupling parameter introduces interactions between the constituent subsystems, allowing us to build large networks with complex, non-gradient dynamics. We study these networks using standard ideas from perturbation theory, as well as numerical experiments. These constructions are motivated by established attention architectures involving restricted and type-dependent interactions [17, 18, 14]. See § 4.5 for more detailed discussion.
A model related to the one derived in § 2 was recently studied by Li et al. [22], who consider particles constrained to the circle with a linear attention kernel in place of the exponential softmax. They show that the resulting dynamics admit a generalized Kuramoto formulation with second-harmonic coupling, and use classical methods for coupled oscillators to investigate clustering, periodic oscillations, and bifurcations, primarily in the mean-field limit. Here we retain the softmax attention mechanism, work with finitely many particles, and construct specific examples with complicated, non-gradient dynamics.
Code and data availability: The MATLAB implementations used in this paper, together with archived numerical data and scripts for reproducing the figures and tables, are publicly available through the accompanying project webpage [23].
A three particle model on the torus
Throughout this section, we consider three particles and constant query, key, and value matrices. The particles are constrained to the surface of an ellipse defined as follows. Let be symmetric and positive definite, and write
The map takes the unit circle diffeomorphically onto . We introduce
and parametrize the particle positions by
In particular, , where the dot denotes differentiation with respect to time. We identify the configuration space with the three-dimensional torus .
The matrices , , and enter the angular equations through the effective matrices
For convenience, put and . The attention coefficients become
To obtain the angular equations, observe that has unit length in the -metric, since . Moreover, for , the tangent projection satisfies
Taking the -inner product of (2) with , and using (3), gives the autonomous system
For later numerical work, it is useful to write the right-hand side completely in terms of trigonometric functions and the entries of and . Let
Then
whereas
Substitution in (5) yields the explicit three-dimensional vector field
Thus defines a real-analytic vector field on . Its lift to is -periodic in each coordinate, and the denominators in (6) are everywhere strictly positive. In particular, the flow exists for all time on the compact phase space .
The effective matrices and can be prescribed independently. Indeed, for arbitrary real matrices and , one can choose the query/key dimension and take
Consequently, when the attention matrices are unrestricted, the ellipse can be removed by a linear change of coordinates without restricting the class of angular vector fields (5). Note also that the gradient hypotheses and from Theorem 3 reduce in these coordinates to .
Because all three particles use the same attention matrices, the vector field is equivariant under permutations of the particles. In particular, the pair-coincidence subtori and the fully synchronized circle
are invariant. On , all attention weights are equal to , and the equations reduce to
which is independent of and . The synchronized dynamics provides an explicit family of nongradient examples, as the following proposition shows.
Proposition 4 (Existence and stability of a synchronized periodic orbit). Consider the three-particle system on the unit circle, written in angular coordinates as
where
and
Suppose that are constant, , and that has complex conjugate eigenvalues , where
Then the synchronized diagonal
is a periodic orbit with period
Its monodromy matrix is
where . Equivalently,
In particular, the Floquet multipliers are
Moreover, for any , the Poincaré return map on the section has a fixed point corresponding to the synchronized orbit. In local coordinates centered at this fixed point, its derivative is
Consequently, the synchronized periodic orbit is hyperbolic and orbitally attracting if , and hyperbolic and orbitally repelling if . If , the orbit is nonhyperbolic. These conclusions are independent of and .
Proof. At synchrony, , all attention weights are equal to . Hence the synchronized diagonal is invariant, and the dynamics restricted to it are governed by
Since has no real eigenvalues, cannot vanish. Indeed, would imply that is parallel to , giving a real eigenvector of . Thus the synchronous motion is periodic.
To compute its period, observe that the equation for can be written as
Consequently,
Writing , where , we obtain
Since has no real eigenvectors, the first positive time at which is a positive multiple of is . This is the period of the synchronized orbit.
We next compute the variational equation along the synchronized solution. Define
At synchrony, the derivative of the attention weights does not contribute to the linearization. Indeed, the attention weights satisfy , and all the vectors being averaged coincide. Therefore the corresponding first-order terms cancel.
Using and , direct differentiation gives
where denotes the right-hand side of the th angular equation and is the Kronecker delta. Thus the variational equation is
Introduce the complementary projections
Since
the Jacobian is
The projections are constant and commute. Consequently, the fundamental matrix of the variational equation, normalized by , is
Consider these integrals over one period. Since and never vanishes,
The periodicity of therefore gives
On the other hand, because and form an orthonormal basis of ,
Combining this identity with gives
It follows that
Hence the monodromy matrix is
which is precisely the stated formula. The vector is an eigenvector with eigenvalue , while every vector in the two-dimensional subspace
is an eigenvector with eigenvalue . This proves the formula for the Floquet multipliers.
It remains to compute the derivative of the Poincaré return map. Fix and consider the transverse section
with local coordinates
Let denote the flow of the full three-particle system. Since , the first return time near the synchronized orbit is well-defined and smooth, with . Define
where denotes projection onto the second and third angular coordinates. Clearly .
At the synchronized crossing, the vector field is . Differentiating the return condition gives the standard correction for variations of the return time. Therefore
where . Substituting , and observing that , we obtain
The eigenvalues of the return map are therefore both equal to . The claimed stability conclusions follow.
Numerical explorations of the three-dimensional model
We now investigate the dynamics of the three-particle system (5) numerically. Throughout this section, we represent the phase space by the identification cube , with opposite faces identified. We consider two choices of the effective matrices and use the inverse-temperature parameter as a bifurcation parameter. Define the matrices
The first choice has and the second has ; both use the same matrix . For , the synchronized periodic orbit of Proposition 4 is attracting for every (see § 3.1). Parameter scans initialized near this orbit reveal no additional dynamics.
For , the synchronized periodic orbit is transversely repelling for every , and a standard bifurcation diagram reveals richer behavior. The diagram suggests torus-like dynamics, periodic windows, and numerical evidence of chaos. We consider these results in § 3.2.
For the same choice , we also follow an attracting, nonsynchronized periodic orbit, apparently born in a saddle-node bifurcation near . This periodic orbit has complex-conjugate transverse Floquet multipliers, and continuation indicates a candidate Neimark–Sacker bifurcation near . We discuss this second scan in § 3.3.
Our goal is not to provide a comprehensive bifurcation analysis of this system. Rather, we exhibit several representative dynamical phenomena, illustrating a wide variety of possible behaviors for only three interacting particles. The three-particle computations use adaptive integration of the angular equations, event detection for Poincaré crossings, and integration of the variational equations. Periodic solutions are refined by shooting, and their orbital stability is computed via Floquet multipliers. Lyapunov exponents are estimated by repeated QR orthogonalization. The coupled-system Lyapunov computations in § 5 instead use fixed-step fourth-order Runge–Kutta integration. For general discussions of these numerical techniques, see [24, 25, 26].
Unless otherwise stated, our Poincaré section is
with coordinates . This section is chosen for convenience, rather than because it has any distinguished geometric status. The bifurcation diagrams record the coordinate at section encounters, and the Poincaré maps distinguish crossings with from those with . As we shall see, these two crossing directions can correspond to different portions of the same geometric intersection curve when an invariant torus is not everywhere transverse to the flow through .
An explicit attracting synchronized periodic orbit
As a first illustration, take and as in Equation (8). The synchronized circle is invariant. By Proposition 4, it contains the explicit periodic orbit $\theta_1(t)=\theta_2(t)=\theta_3(t)=\varphi_0+2.30t`. (mod ), with period and double nontrivial Floquet multiplier . In particular, the synchronized periodic orbit is attracting. In fact, the synchronized circle itself is this periodic orbit, and both its period and multipliers are independent of and . Thus it is present and normally attracting for every , with fixed.
Figure 1 illustrates the resulting periodic motion and the approach of selected trajectories to the synchrony circle. The numerical experiments also remind us that local orbital stability does not determine the global basin of attraction.

Figure 1. (a) The attracting synchronized periodic orbit at . (b) The same orbit together with selected forward trajectories, some of which approach it. An explicitly known attracting periodic orbit in the synchronized circle (left) and the behavior of selected initial conditions (right). The simulations use and the matrix defined in Equation (8). The curves are drawn in the identification cube; trajectories are broken where they cross an identified face.
The main parameter scan: invariant tori and chaos
For the remaining experiments, we fix and the same matrix from (8), varying . The matrices and have the same rotational part, while their scalar parts are and , respectively. The synchronized periodic orbit remains present for , but it is transversely repelling, since its two nontrivial Floquet multipliers are .
Our first parameter scan begins at with the angular initial condition
and increases using the terminal state from one parameter value to initialize the next. After discarding a transient, section encounters are plotted against . This procedure is well suited to locating attracting regimes and sudden changes in the observed asymptotic dynamics, but can also switch between coexisting attractors or retain long transients.
The diagram in Figure 2 suggests a rich progression of periodic, quasiperiodic, and more complicated recurrent behavior. To examine individual regimes, we compute the finite-time Lyapunov spectrum, a Poincaré section, and a phase-space portrait at fixed values of . The three panels in the following figures show these diagnostics in that order. A smooth closed curve in the section, together with two Lyapunov exponents approaching zero, is consistent with an invariant two-torus. By contrast, a persistently positive largest Lyapunov exponent is numerical evidence of sensitive dependence on initial conditions.

Figure 2. Bifurcation diagram for the main forward-integration scan with the matrices and from (8). Points record the coordinate at intersections with the section (mod ) after a transient has been discarded. The diagram is an empirical representation of the attractors selected by this parameter sweep, rather than a continuation diagram of every periodic solution.
The two colors in the Poincaré plots merit an explanation. The blue points correspond to trajectories crossing with and the yellow/orange points to crossings with . When an

Figure 4. Numerical evidence of chaotic dynamics along the main scan of the system at . The positive largest Lyapunov exponent and the structure of the section distinguish this regime from the smooth torus illustrated in Figure 3.

(a) Finite-time Lyapunov exponents.

(b) Poincaré intersection.

(c) Orbit in the identification cube.
Figure 3. Dynamics of the main scan at . The numerical diagnostics are consistent with an attracting invariant two-torus. In the middle panel, blue marks crossings with , while yellow/orange marks crossings with . The flow need not be everywhere transverse to the chosen section.
invariant two-torus intersects along a closed curve, the vector field need not point to the same side of along the entire curve. At transitions between these two sets of intersection points, continuity forces , so the vector field is tangent to the chosen section. In particular, the complete geometric intersection curve need not be a global transverse Poincaré section for the flow. This geometric effect explains why plotting only one crossing direction can reveal just an arc of the closed intersection curve, even when the phase-space portrait clearly suggests a smooth torus.
At , the same matrices give a substantially different picture. Numerical integrations from different initial conditions yield similar Lyapunov spectra, with one positive exponent, one exponent close to zero, and one negative exponent (approximately 0.11, 0, and ). Along with the nontrivial structure of the Poincaré section, this provides evidence for chaotic dynamics, although it does not constitute a proof of the existence of a chaotic attractor.
A second parameter scan: a fold of periodic orbits and complex Floquet multipliers
A second set of experiments uses the same matrices and from (8), but is initialized near a nonsynchronized attracting periodic orbit at . A convenient section point on this periodic orbit is
Its two nontrivial Floquet multipliers are approximately
and hence have modulus smaller than one. Thus the orbit is attracting, with a contracting two-dimensional normal bundle on which the return dynamics has a rotational component. This provides a qualitatively different example from the synchronized orbit, whose nontrivial multipliers are real.
Numerical shooting and continuation suggest that this periodic orbit belongs to a family created in a saddle-node bifurcation of periodic orbits at
At the candidate fold, one nontrivial Floquet multiplier is close to , while the other is approximately 0.20636. Immediately above the fold, the calculations find both a transversely attracting periodic orbit and a saddle periodic orbit. In particular, the nonsynchronized family need not extend as a regular branch all the way to . Numerical continuation of this periodic-orbit family also indicates a crossing of a complex-conjugate pair of multipliers through the unit circle near , consistent with

(a) The nonsynchronized attracting periodic orbit at .

(b) The same orbit with selected trajectories illustrating its basin of attraction.
Figure 5. An attracting nonsynchronized periodic orbit with complex-conjugate transverse Floquet multipliers for the system. Several plotted trajectories do not approach this orbit on the displayed time scale, suggesting that its basin of attraction is not the whole phase space; the plots alone do not determine the basin boundary.
::::
a Neimark–Sacker bifurcation. Establishing the bifurcation type and the local organization of invariant tori requires additional work.
The second bifurcation scan starts at the periodic-orbit seed and varies in both directions. As in the main scan, the points shown are obtained from forward integration, so their appearance depends on which invariant set is reached from the chosen initial conditions. The superimposed information from shooting continuation, when displayed, must be interpreted separately from the attracting-set samples.
The second scan illustrates a further subtlety of the dynamics: nearby parameter values may support different recurrent sets. For example, continuation indicates that the nonsynchronized periodic orbit is still attracting at , while a separate forward-integration experiment produces a torus-like portrait at . These observations are consistent with a change in stability near the candidate Neimark–Sacker value, but do not by themselves establish the bifurcation mechanism or coexistence of attractors at a fixed parameter value.
At , the second scan exhibits a markedly more complicated recurrent regime. The finite-time Lyapunov computation for the trajectory illustrated in Figure 8 indicates a positive largest exponent. Together with the structure of the Poincaré section and the phase-space portrait, this provides numerical evidence for chaotic dynamics. This example is especially interesting when viewed alongside the attracting periodic orbit at and the torus-like dynamics at . The computations suggest that a single family of attention models can exhibit several distinct kinds of recurrent behavior, although they do not constitute a rigorous proof of a chaotic invariant set.
Taken together, these computations illustrate that even the three-particle projected-attention model can exhibit a variety of recurrent phenomena. The apparent fold of nonsynchronized periodic orbits, the emergence of complex Floquet multipliers, and the possible interactions among periodic orbits, invariant tori, and chaotic invariant sets provide concrete targets for more systematic numerical continuation and, ultimately, computer-assisted validation.
Higher-dimensional transformers as coupled systems {#sec:4}
The three-particle system studied in § 2 will now serve as a component for assembling larger systems with interesting dynamics. Consider groups of three particles, with index sets

Figure 8. (a) Finite-time Lyapunov exponents. (b) Poincaré intersection. (c) Orbit in the identification cube. Numerical evidence of chaotic dynamics in the second parameter scan at . The finite-time Lyapunov spectrum (left), Poincaré section (middle), and phase-space portrait (right) provide complementary diagnostics of the chaotic regime.

Figure 6. Bifurcation diagram from the second, complex-orbit-seeded parameter scan, using the same matrices as in Figure 2. Forward-orbit Poincaré points reveal the asymptotic dynamics selected near the nonsynchronized periodic family. Any continued periodic-orbit branch shown in the plot is distinct from the point cloud generated by time integration.

(a) Finite-time Lyapunov exponents.

(b) Poincaré intersection.

(c) Orbit in the identification cube.
Figure 7. A torus-like recurrent set observed in the second scan at . The numerical portrait does not by itself establish the existence of an invariant torus or its bifurcation mechanism.
partitioning . Suppose initially that all particles lie on the same ellipse and that, within each group, they evolve according to the autonomous three-particle system derived in § 2. Writing , the uncoupled equations are
The phase space is , and the flow of (9) is the direct product of the constituent three-particle flows. In particular, recurrent invariant sets of the individual models become invariant sets of the larger system by taking products.
We now introduce a coupling parameter and a family of projected attention vector fields of the form
with in for each fixed and finite , as . In the next subsections we discuss several ways to assemble a self-attention network of this form, using different techniques to retain subsystem information.
Note that we must build subsystem information into the network if we want to treat self-attention transformers as coupled oscillators. This is because ordinary, unmasked attention, as in Equation (2), is equivariant under permutations of the particles. A nontrivial direct product of independent three-particle systems, by contrast, distinguishes the prescribed subgroups, and permutations that mix particles from different groups actually change the dynamics. We will see that masks and fixed group labels provide the structural information we need.
There are numerous precedents for structured interactions in machine learning. Graph attention networks restrict interactions by specifying a prescribed graph [17]; heterogeneous graph transformers permit node- and edge-type-dependent interactions [18]; and head-specific masks, as discussed below, are studied in [27]. We now describe three realizations, all of which recover Equation (9) in the uncoupled limit. Two use masks, and one uses group labels. For positive coupling, the first two realizations define exactly the same coupled vector field, while the third uses a different normalization architecture.
Multiplicative attention masks. We use a common convention for attention masks throughout this section. Given a collection of scores , a nonnegative mask defines the modified attention coefficients
We assume that each row of contains at least one positive entry, so that the denominator is nonzero. A hard mask has entries in , while more general nonnegative masks allow selected interactions to be weakened or strengthened.
Consider particles in , partitioned into disjoint groups, each containing three particles. Write
We introduce the complementary hard masks
Thus permits only interactions between particles in the same group, while permits only interactions between particles belonging to distinct groups.
We consider two ways of using these masks to construct weakly coupled attention systems. In the first, the internal and external masks are combined before applying a single softmax normalization over all particles. In the second, the two masks are applied to separate attention heads, each with its own normalization, and the resulting outputs are combined afterward.
These constructions agree in the uncoupled limit but differ for positive coupling. In particular, in the single-head construction the relative contribution of external interactions depends on the number of particles outside each group. In the two-head construction, the external head produces a separately normalized weighted average, whose magnitude remains bounded independently of the number of groups. This distinction becomes important when considering systems with many particles.
Block-masked single-head attention
We first consider a single-head attention system in which the constituent subsystems are identical. To this end, fix common matrices , , and an inverse temperature , and write
Using the complementary hard masks and defined above, introduce the parameter-dependent mask
Thus interactions within each group have weight one, while interactions between distinct groups have weight . The corresponding masked attention coefficients are
and the resulting projected equations are
Observe that this construction uses a single softmax normalization over all particles, rather than separate normalizations for within-group and between-group interactions.
At , the mask is precisely , so all interactions between distinct groups vanish and each attention row is normalized over its own group. Consequently, (12) reduces exactly to the uncoupled product system (9). At , all entries of the mask are equal to one, and the model becomes ordinary unmasked single-head attention involving all particles. For , cross-group interactions are suppressed but remain nonzero.
The dependence on is smooth, including at . Indeed, for , define
and
The th component of the vector field can then be written as
Since is strictly positive, and the configuration space is compact, the remainder is uniform, together with any fixed number of derivatives in . Thus, for each fixed number of groups and each finite ,
In particular, the block-masked system is a smooth perturbation of the uncoupled product system, so that standard persistence results for hyperbolic invariant sets and normally hyperbolic invariant manifolds are applicable whenever their respective hypotheses are satisfied.
For systems with many groups, the effective strength of cross-group attention depends not only on but also on the number of particles outside each group. In particular, if the attention scores are uniformly bounded independently of , then is of order , since the external sum has terms and the internal sum has three. Thus the effective relative contribution of cross-group attention is controlled by . Consequently, a fixed small value of need not represent equally weak coupling as the number of groups increases. A natural choice is to take , with a sufficiently small proportionality constant, or to restrict cross-group attention to a sparse network. This scaling consideration also applies to the equivalent group-label construction below, but not to the separately normalized two-head construction of Section 4.3.
The next subsection gives an equivalent implementation using fixed group labels. Section 4.3 then introduces the alternative two-head construction.
Group labels and attention biases
The preceding mask can also be implemented using ordinary softmax attention applied to augmented particle representations. That is, one assigns to each group , a fixed label , the th coordinate vector. When we append a label to each particle, we obtain for . Define augmented query and key maps with bilinear compatibility score defined by
where denotes the group containing particle . Such a score is obtained by a block-diagonal choice of on the augmented space. The values remain , and the labels are fixed rather than evolving coordinates. Factoring from each softmax denominator shows that the resulting attention coefficients coincide exactly with (11), with
Hence, arbitrarily weak positive coupling is implemented using finite query and key matrices, without an attention mask. Exact decoupling corresponds to the limit ; it cannot be attained by a finite value of this particular bias parameter.
This formulation makes the group identity part of the token representation and is closely related to type-dependent attention and additive structural biases: score modifications supported by practical attention software [28]. It is not a construction using only unaugmented positions on the ellipse: the additional fixed labels distinguish the subsystems.
Two-head masked attention as a coupled system
The second normalization architecture, perhaps the most useful for the purposes of the present work, uses two masked attention heads. The notion of multi-head attention originates in [1], and we recall the definition for two heads before specializing to a masked partition of particles into interacting groups.
Two-head self-attention. Let denote a configuration of particles in a manifold . In a two-head self-attention mechanism, each head has its own query, key, and value matrices , , and , together with an inverse temperature parameter .
The attention weights associated with head are
Each head produces an attention-weighted average
The two head outputs are combined through output matrices and , giving
This is equivalent to concatenating the two head outputs and applying a single linear output map. The corresponding continuous-time projected attention system is
where denotes the tangent projection associated with the chosen particle manifold.
Masked two-head attention. We now introduce a mask restricting which particles contribute to each attention head. Using the multiplicative-mask convention introduced at the beginning of this section, we say that for each , is a nonnegative mask matrix, with at least one positive entry in every row. The masked attention weights are defined by
In particular, a hard mask has entries in , with an entry excluding particle completely from the attention of particle in head .
Equivalently, if denotes the set of particles visible to particle in head , then for a hard mask
Note that the attention weights are normalized separately within each head, so that
Thus each head computes a weighted average over its permitted particles, and the two averages are combined only afterward.
Complementary group masks. Suppose that the particle indices are partitioned into nonempty, disjoint groups,
In our numerical experiments, each group contains three particles, so that .
We introduce two attention heads, referred to as the internal and external heads. The internal head permits interactions only between particles belonging to the same group, while the external head permits interactions only between particles belonging to different groups.
More precisely, we use the complementary hard masks and defined at the beginning of this section, setting
Thus every pair of particles is visible to exactly one of the two heads. In particular, self-interactions belong to the internal head.
Let . Applying the internal mask to the first attention head gives
and for .
Similarly, the external mask gives
and for .
The outputs of the two heads are therefore
We now choose the output matrices to be
where controls the strength of the inter-group coupling. Substituting these choices into the two-head projected attention system gives
This is precisely the weakly coupled particle system considered below.
Writing , and using the linearity of the tangent projection in its vector argument, we may express the system as
where is the internal attention vector field on the th group and collects the external interactions.
In particular, when , the external head makes no contribution and the system reduces exactly to a product of uncoupled subsystems,
Since the attention weights of the two heads are normalized independently, neither nor depends on . Consequently, the full vector field depends affinely on the coupling parameter, and
for each fixed number of groups and each finite .
For the constructions considered here, all groups have identical internal attention parameters, and the external attention parameters are also independent of the interacting groups. Hence the uncoupled subsystems are identical, although their states and trajectories need not be. These uniformity assumptions are convenient for studying the effect of coupling but are not intrinsic to the masked attention construction.
Unlike the block-masked single-head construction of § 4.1, the present system uses separate softmax normalizations for the internal and external heads. In particular, the coupling parameter scales the output of the external head without altering the internal attention weights. Thus the two constructions have the same uncoupled limit, but define different coupled systems for .
Remark 5 (Heterogeneous coupled subsystems). The assumption that all groups have identical internal attention parameters, and that all inter-group interactions are governed by the same coupling parameters, is made for simplicity. More generally, one could allow the matrices , , and , as well as the inverse temperature , to depend on the group index . Similarly, the external attention parameters could depend pairwise on the interacting groups. This generalization permits the coupling of subsystems exhibiting qualitatively different dynamics, including periodic, quasiperiodic, and chaotic behavior.
Perturbative persistence
All three implementations give smooth perturbations of a direct-product flow for each fixed number of groups. Consequently, the classical theory of normally hyperbolic invariant manifolds provides a natural framework for understanding the persistence of certain dynamical structures under weak coupling. This theory applies not only to hyperbolic periodic orbits, but also to normally hyperbolic invariant tori and, more generally, to compact normally hyperbolic invariant manifolds of arbitrary dimension. Such manifolds may be attracting, repelling, or of saddle type. We record the following consequence.
Proposition 6. Suppose that the th three-particle subsystem admits a compact, smooth, normally hyperbolic invariant manifold , for . Assume moreover that the normal contraction and expansion rates of the individual manifolds dominate the tangential growth rates of all factors, so that the product
is a normally hyperbolic invariant manifold for the uncoupled system (9). Then, under any of the above coupling implementations, for all sufficiently small , there exists a nearby normally hyperbolic invariant manifold , diffeomorphic to . The dimensions of its stable and unstable normal bundles are preserved under the perturbation. In particular, if is normally attracting, then so is .
Proof. At , the derivative of the product flow is block diagonal, and the invariant splitting along is obtained by taking the direct sums of the corresponding stable, tangent, and unstable bundles of the individual factors. The assumed domination of normal rates over tangential rates ensures that this splitting is normally hyperbolic. Since the coupling constructions converge to the product vector field in as , the conclusion follows from the persistence theorem for normally hyperbolic invariant manifolds [29, 30].
An important special case occurs when each is a hyperbolic periodic orbit. In this case the tangent dynamics have zero exponential growth rates, while all transverse directions are exponentially contracting or expanding. The product is therefore a normally hyperbolic invariant -torus, and the proposition guarantees its persistence under weak coupling. Similar conclusions hold for products of normally hyperbolic invariant tori, provided the required spectral gaps are satisfied. The dynamics on the perturbed manifold need not be conjugate to the original dynamics. For example, weak coupling between periodic oscillators may produce phase locking rather than quasiperiodic motion. The proposition does not specify a numerical threshold for ; in particular, it does not by itself justify persistence at , as explored in § 5.
The theory of persistence extends beyond smooth invariant manifolds. Classical structural stability results for compact, locally maximal uniformly hyperbolic invariant sets imply that such sets persist under sufficiently small perturbations, with their dynamics preserved up to topological conjugacy (or orbit equivalence for flows) [31, 32]. Note that these results do not establish the persistence of the chaotic dynamics observed in this paper. Numerical evidence of positive Lyapunov exponents does not establish uniform hyperbolicity, and a product of hyperbolic invariant sets for independent flows generally has additional neutral directions associated with the independent time translations of the factors. Such products need not themselves be uniformly hyperbolic.
We view these observations as motivation for further work rather than as limitations of the dynamical systems approach. The persistence theory suggests that a wide variety of recurrent invariant sets may survive the introduction of weak attention coupling, but determining which structures actually arise in transformer models remains an open problem. Of particular interest is the possibility that metastable clustering may be organized by the stable manifolds of saddle-type invariant sets more complicated than equilibria, including periodic orbits, invariant tori, and chaotic invariant sets. Their slow stable and unstable directions, together with the geometry of their invariant bundles, may provide a framework for understanding long transient behavior even in the absence of gradient structure.
The examples developed here suggest that the dynamical possibilities of transformer particle systems are considerably richer than those described by convergence to consensus alone. A systematic investigation of hyperbolicity, normal hyperbolicity, bifurcations, and the persistence of invariant structures under coupling is therefore a promising direction for future research.
Structured attention in practical architectures and software
The structured interactions considered above are motivated in part by mechanisms already used in practical transformer architectures. For example, Mistral AI’s Mistral 7B language model uses sliding-window attention to restrict the preceding tokens attended to by each layer [33, 34], while Google’s Gemma 2 alternates local and global attention layers [35]. The Swin Transformer uses local and shifted windows in computer vision, including object detection and image segmentation [36]. These windowed architectures illustrate the use of restricted interactions, although their masks do not directly implement the weakly coupled blocks studied here.
Tencent’s CCFormer provides a particularly relevant industrial example: its recommendation architecture combines different classes of information through feature-field-separated cross-attention with relation-specific attention pathways and output fusion. Its authors report deployment in production video-recommendation and advertising-ranking systems [37]. The architectural principle of separately normalized interactions is close to that of our two-head construction, though the detailed models are different. For comparison, Alibaba’s deployed HetMatch system uses type-dependent interactions for sponsored-search keyword matching, but it is a heterogeneous graph neural network rather than a Transformer attention model [38].
The use of group labels and attention-score biases also has precedents in practical architectures. BERT employs segment embeddings [39], and relative-position and linear attention biases are used in other transformer models [40, 41]. These mechanisms are not identical to the group-label implementation above, but show that group-identifying embeddings and modified attention scores are familiar architectural ingredients. On the software side, PyTorch’s FlexAttention provides programmable attention-score modifications and block masks, including head-dependent masks [28]. NVIDIA’s cuDNN attention library also supports structured masking and additive score biases [42]. Together these examples illustrate that the structural ingredients used in our coupling constructions are compatible with established attention architectures and widely used software, although none should be interpreted as an implementation of the particular dynamical systems studied here.
Dynamics of some many particle systems
Coupling between two three-particle systems
Next, we ask whether the chaotic dynamics found in the three-particle model can survive when two such systems are coupled. This is the simplest nontrivial test of the constructions introduced in Section 4. Consider six particles, and partition them into two groups and with all particles constrained to the ellipse determined by . The phase space is .
In each subgroup we choose effective matrices
For these parameters, the uncoupled three-particle system exhibits numerical evidence of a chaotic attractor, with Lyapunov spectrum approximately . At the six-dimensional system is the direct product of two copies of this flow. In particular, its Lyapunov spectrum contains two positive exponents and, up to numerical error, two zero exponents. Our initial configurations for the coupled experiments are obtained by taking distinct points along the previously computed chaotic three-particle trajectory in each group. We compare the dynamics of the coupled six-dimensional system with the three implementations (corresponding to two distinct coupled vector fields) considered in Section 4.
For block-masked attention, the cross-group entries of the softmax numerator are multiplied by , while the within-group entries retain weight one; the entire row is then normalized as in (11). In the fixed-group-label construction, the scores receive the bias . The relation makes the resulting vector field exactly identical to the block-masked field for every . Hence these two constructions give the same numerical experiment, although they represent different architectural implementations.
Finally, the two-head construction of Equation (16) combines a separately normalized internal head with times a separately normalized cross-group head. For this first comparison, the two heads use the same matrices , and inverse temperature ; thus the only new parameter is the coupling strength .
We consider and . The angular equations and their analytic variational equations are integrated using a fourth-order Runge–Kutta method with time step . We discard an initial interval of length 1500 and then estimate all six Lyapunov exponents over a further interval of length 12,000, using QR orthogonalization at unit time intervals. As a numerical consistency check, the sum of the estimated exponents agrees with the time average of the divergence to approximately in the long integrations. Figure 9 shows the convergence of the finite-time exponents for the six combinations of implementation and coupling parameter.

Figure 9. Finite-time Lyapunov exponents for two coupled three-particle systems on at . Columns correspond to (left) and (right); rows correspond to block-masked attention (top), fixed group labels (middle), and separately normalized internal and cross-group attention heads (bottom). The top two rows coincide exactly because the group-label bias produces the same vector field as block-masked attention. For , the block-masked system retains two positive exponents, while the separate-head run displayed here has leading exponents near zero. At , the block-masked system has a spectrum consistent with an attracting periodic orbit, whereas the separate-head system has two positive exponents. Exponents are computed after discarding a transient of length 1500 and are accumulated over 12000 time units.
For weak coupling, , the block-masked system retains two positive Lyapunov exponents, with . In contrast, the separate-head system has leading exponents approximately , providing no convincing numerical evidence of chaotic dynamics in this experiment. Thus, the two coupling architectures produce qualitatively different behavior even at this small parameter value. At the larger coupling strength , the behavior of the two models differs substantially, but in the other direction. For the block-masked system (equivalently, the group-label system), we find and , with the remaining exponents also negative. This spectrum is consistent with convergence to an attracting periodic orbit rather than a chaotic attractor. Indeed, a subsequent numerical return calculation gives a candidate period , with return error of order . By contrast, the separate-head system has a finite-time spectrum with two positive exponents, approximately followed by an exponent near zero and three negative exponents. This provides numerical evidence for hyperchaotic dynamics in the six-dimensional flow. The contrast is visible in Figure 9.
These experiments suggest that the observed chaotic dynamics depend sensitively on the architecture used to couple the subsystems, and not only on the presence of weak cross-group interactions. Nevertheless, does not measure the same perturbation of the vector field in the two models: the block-masked head renormalizes internal and external weights together, whereas the cross-group head is normalized separately and then added with coefficient . Thus the comparison at equal is a comparison of two specific architectural parameterizations, not of perturbations with equal norm. Preliminary experiments at intermediate coupling values also suggest that the observed dynamics can depend on the initial condition, so possible coexistence of attracting sets deserves further study. In what follows, the positive exponents observed for the separate-head construction at motivate experiments with larger networks of coupled three-particle systems.
Coupling in nine-particle systems
We next consider a heterogeneous network in which a chaotic three-particle system is coupled to two three-particle systems possessing attracting periodic orbits. The resulting flow has nine angular variables, with particle groups , , and . All three subsystems use the same effective matrices
but have distinct inverse-temperature parameters,
In isolation, the first subsystem exhibits a chaotic attracting set, whereas each of the other two possesses the attracting nonsynchronized periodic orbit discussed above. The uncoupled product therefore has one positive Lyapunov exponent, associated with the chaotic component; the remaining two subsystems are regular. This setup allows us to ask whether coupling simply preserves the original chaotic direction or creates additional expanding directions in the full network.
We compare block-masked attention with separately normalized internal and cross-group attention heads, as defined in Section 4, fixing . The parameters , , and used to evaluate each attention row are those of its receiving group. For each architecture, we calculate the Lyapunov spectrum from two distinct initial configurations. The angular equations and their analytic variational equations are integrated with fourth-order Runge–Kutta at step size . After discarding a transient of length 1500, the exponents are accumulated for 9000 time units using periodic QR orthogonalization. Finite-difference checks of the analytic Jacobian give relative errors below . The results are summarized in Table 1.
| Coupling architecture | Initial condition | |||
| Block-masked | 1 | 0.00004 | 0 | |
| Block-masked | 2 | 0 | ||
| Separate heads | 1 | 0.14384 | 0.09395 | 3 |
| Separate heads | 2 | 0.14544 | 0.09638 | 3 |
Table 1. Nine-particle system consisting of one chaotic and two attracting-periodic three-particle subsystems, coupled at . The table reports the two largest finite-time Lyapunov exponents and the number of exponents greater than 0.01, for two distinct initial configurations in each architecture. The integration uses , a discarded transient of length 1500, and 9000 time units of Lyapunov accumulation.
The contrast between the two architectures is pronounced. With block-masked coupling, the largest exponent approaches zero, while the second is approximately for both initial conditions. This is consistent with convergence to regular attracting dynamics, and provides no numerical evidence of a surviving positive exponent. By contrast, with separately normalized heads, the largest two exponents stabilize near 0.14 and 0.095. Moreover, the computation resolves three exponents exceeding 0.01 in both runs; in particular, the third exponent exceeds this threshold. Thus an uncoupled system with only one chaotic constituent produces, after coupling, a nine-dimensional flow with expanding directions. The emergence of additional positive exponents is particularly noteworthy because the two receiving subsystems have attracting periodic dynamics when isolated.
We emphasize that positive Lyapunov exponents characterize expansion in the coupled system; they do not, by themselves, identify which constituent particles are responsible for the expanding directions. Nevertheless, this experiment illustrates the central point of the coupled-system study: knowledge of the dynamics of low-dimensional building blocks provides a useful starting point, while the coupling architecture can qualitatively reorganize their collective behavior. The reported exponents are numerical estimates rather than validated claims about an attractor.
A 60-particle example
We now investigate whether the chaotic dynamics observed in the three-particle system persist in higher-dimensional systems, and how interactions between chaotic subsystems influence the number of positive Lyapunov exponents.
We consider a system of particles, organized into groups of three particles each. Within each group, the dynamics are determined by the same constant coefficient matrices and inverse temperature used in the three-particle chaotic example discussed above. The groups are coupled through a multi-head attention mechanism consisting of two separately normalized contributions: an internal attention head, involving particles within the same group, and an external attention head, involving particles in the other groups. The external contribution is multiplied by a coupling parameter .
When , the system reduces to a direct product of twenty independent three-particle systems. Since each particle is constrained to an ellipse, the resulting phase space is 60-dimensional. In the coupled experiments we set .
The equations and their variational equations were integrated numerically using a fourth-order Runge–Kutta method with step size . An initial transient of length was discarded, after which the largest Lyapunov exponents were approximated over an additional integration interval of length . We repeated the experiment for two independently generated initial conditions. As a consistency check, the analytic Jacobian was compared with finite-difference approximations, giving relative errors between and in the coupled experiments.
Table 2 summarizes the results. In both experiments, the largest Lyapunov exponent is approximately 0.13, while the second largest is approximately 0.12. More significantly, both experiments produce 26 Lyapunov exponents exceeding 0.01. The estimates of the leading exponents remain relatively stable during the final portion of the integration, and the number of exponents above this threshold is unchanged throughout most of the computation.
| System | ||||||
| Coupled, seed 0 | 60 | 0.1 | 40 | 0.131501503 | 0.1231389 | 26 |
| Coupled, seed 1 | 60 | 0.1 | 40 | 0.1297627 | 0.1221250 | 26 |
| Uncoupled, single group | 3 | 0 | 3 | 0.1118411 | 1 |
Table 2. Numerically computed Lyapunov exponents for the 60-particle coupled system and the isolated three-particle baseline. Here is the number of particles, is the number of computed Lyapunov exponents, and denotes the number of computed exponents greater than 0.01. All computations use a transient of length 2000 and a Lyapunov averaging interval of length 16000.
For comparison, we also compute the Lyapunov exponents of an isolated three-particle subsystem. This calculation gives a largest exponent of approximately 0.112, a second exponent close to zero, and one exponent exceeding 0.01. Consequently, the corresponding uncoupled product of twenty such subsystems would have twenty exponents exceeding 0.01, counting multiplicity, at the level of these numerical estimates.
The comparison is particularly interesting because the coupled system has six more numerically estimated Lyapunov exponents exceeding 0.01 than the corresponding uncoupled product. Thus, the coupling not only preserves numerical evidence of chaotic behavior but appears to introduce additional expanding directions. In particular, these experiments provide numerical evidence of high-dimensional chaotic dynamics arising through interactions between low-dimensional chaotic subsystems. This comparison does not establish a general scaling law as the number of groups increases.
We emphasize that only the largest 40 of the 60 Lyapunov exponents were computed. Since these are the largest exponents and only 26 exceed 0.01, the omitted exponents cannot exceed this threshold. Thus truncation does not affect the reported count of exponents above 0.01; the number of strictly positive exponents could be larger because some may lie between zero and 0.01. The estimates are finite-time numerical quantities. Nevertheless, the agreement between the two independent experiments provides strong numerical evidence that the coupled system supports many expanding directions. These Lyapunov exponents describe the full tangent dynamics and do not, by themselves, determine whether the trajectory lies near an invariant synchronization subspace arising from the permutation symmetry among identical groups.
Conclusions
The interpretation of transformers as interacting particle systems opens the door to studying their behavior using the geometric and analytic tools of dynamical systems theory. In particular, the gradient structures identified in certain simplified attention models provide invaluable insight into the emergence of clustering and metastability. When a gradient structure is available, the associated energy landscape constrains the possible dynamics and provides a natural framework for understanding long transients near saddle equilibria and their stable manifolds. This point of view has already led to important advances in the mathematical theory of transformers.
However, gradient structure is not a prerequisite for clustering or metastability. More generally, trajectories may approach the stable manifolds of saddle-type invariant sets, remain in their neighborhoods for extended periods, and eventually depart along weakly unstable directions. Such behavior does not require an underlying energy function or a gradient-like flow. Moreover, the invariant sets organizing these dynamics need not be equilibria. Periodic orbits, invariant tori, and more complicated saddle-type invariant sets may also play a role.
The analytic results in this paper show that, when the assumptions of Theorem 3 are violated, the self-attention system can exhibit non-trivial recurrent dynamics. The numerical experiments show that even relatively simple autonomous transformer models, with particles constrained to ellipses and constant coefficient matrices, can already exhibit rich dynamics. In particular, we observe numerical evidence of chaos in low-dimensional examples, and the persistence and proliferation of expanding directions in larger coupled systems. Our 60-particle experiments provide evidence of high-dimensional chaos, with 26 numerically computed Lyapunov exponents exceeding 0.01. These observations suggest that complicated recurrent behavior is not confined to low-dimensional examples, and it may even become increasingly prevalent as the number of interacting particles grows.
We speculate that complicated dynamics may be a feature rather than a bug. After all, a central purpose of the attention mechanism is to produce context-dependent representations of information. It is conceivable that the stretching and folding associated with chaotic dynamics aid in this task. Whether such dynamics actually play a useful role in trained transformer architectures is an intriguing question which the present work does not address.
Many fundamental mathematical questions remain open. We conjecture that metastable clustering in more general attention systems may be organized by the stable manifolds of saddle-type invariant sets, including periodic orbits, invariant tori, and possibly chaotic invariant sets. Identifying such structures and developing methods for computing their stable and unstable manifolds, slow invariant submanifolds, and associated invariant bundles for self-attention systems are natural directions for future research. Understanding how these structures depend on the attention parameters, and how they interact through bifurcations, may provide a more general geometric theory of clustering and metastability beyond the gradient setting.
Our higher-dimensional experiments also suggest the possibility of a systematic relationship between the number of particles and the complexity of the dynamics. In particular, we conjecture that suitable coupling constructions can produce families of systems for which the number of positive Lyapunov exponents grows with the number of coupled subsystems. Establishing such results, and understanding the persistence of chaotic invariant sets under coupling, would provide a natural extension of the present numerical investigations.
Finally, it is important to ask how much of this dynamical structure survives in more realistic transformer architectures. How does the inclusion of time varying effects in the query, key, and value matrices change the geometric picture? Can analogous invariant sets and their stable and unstable manifolds be identified in trained models? Can their geometry help explain the organization and evolution of token representations, and ultimately contribute to the interpretability of these systems?
We regard the present work as an initial exploration of these questions. The mathematical theory of transformers is still in its early stages, but perhaps the relationship between attention and invariant dynamics itself deserves more attention.
Acknowledgments
The author is deeply indebted to Yu Xiang of Florida Atlantic University for introducing him to the particle system interpretation of LLM transformers studied in the present work, and for hours of indispensable conversation. This paper would not exist without these discussions. Conversations with Juan Miranda and Kyle Loh are also gratefully acknowledged. The author was partially supported by the National Science Foundation grant DMS - 2307987.
Declaration of generative AI and AI-assisted technologies
Generative artificial intelligence tools, primarily ChatGPT (OpenAI), were used during every phase of the development of this work, including the generation, revision, and debugging of numerical code, assistance with mathematical calculations and technical discussions, and the drafting, editing, and organization of portions of the final manuscript. Claude was also used for independent copy-edit review.
The use of AI was interactive and author-directed, involving many short chat mode exchanges in which specific mathematical, computational, or expository tasks were posed, the resulting outputs were examined, and subsequent redirections and revisions were requested. The research was not delegated to autonomous AI agents.
In particular, substantial pieces of numerical software were developed with AI assistance. The author tested and executed the resulting programs, performed the numerical experiments, examined the computed output, produced and interpreted the figures and other reported results. AI-generated text was similarly reviewed, edited, and incorporated by the author.
The author was responsible for the scientific questions, the development and selection of the mathematical models, the design and evaluation of the numerical experiments, and the interpretation of the results. All mathematical claims, numerical findings, and conclusions presented in the final manuscript are the responsibility of the human author, who takes full responsibility for the accuracy, originality, and integrity of the published work.
References
- [1]Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Advances in Neural Information Processing Systems, volume 30, 2017.arxiv.org/abs/1706.03762
- [2]OpenAI. GPT-4 technical report. arXiv preprint arXiv:2303.08774, 2023.arxiv.org/abs/2303.08774
- [3]Jack Lindsey, Wes Gurnee, Emmanuel Ameisen, Brian Chen, Adam Pearce, Nicholas L. Turner, Craig Citro, David Abrahams, Shan Carter, Basil Hosmer, Jonathan Marcus, Michael Sklar, Adly Templeton, Trenton Bricken, Callum McDougall, Hoagy Cunningham, Thomas Henighan, Adam Jermyn, Andy Jones, Andrew Persic, Zhenyi Qi, T. Ben Thompson, Sam Zimmerman, Kelley Rivoire, Thomas Conerly, Chris Olah, and Joshua Batson. On the biology of a large language model. Transformer Circuits Thread, March 2025. https://transformer-circuits.pub/2025/attribution-graphs/biology.html.
- [4]Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, and Guillaume Lample. LLaMA: Open and efficient foundation language models. arXiv preprint arXiv:2302.13971, 2023.arxiv.org/abs/2302.13971
- [5]Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel Ziegler, Jeffrey Wu, Clemens Winter, Chris Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language models are few-shot learners. In Advances in Neural Information Processing Systems, volume 33, pages 1877–1901, 2020.arxiv.org/abs/2005.14165
- [6]Yiping Lu, Zhuohan Li, Di He, Zhiqing Sun, Bin Dong, Tao Qin, Liwei Wang, and Tie-Yan Liu. Understanding and improving Transformer from a multi-particle dynamic system point of view. arXiv preprint arXiv:1906.02762, 2019.arxiv.org/abs/1906.02762
- [7]James Vuckovic, Aristide Baratin, and Remi Tachet des Combes. A mathematical theory of attention. arXiv preprint arXiv:2007.02876, 2020.arxiv.org/abs/2007.02876
- [8]Michael E. Sander, Pierre Ablin, Mathieu Blondel, and Gabriel Peyré. Sinkformers: Transformers with doubly stochastic attention. In Proceedings of the 25th International Conference on Artificial Intelligence and Statistics, volume 151 of Proceedings of Machine Learning Research, pages 3515–3530. PMLR, 2022.arxiv.org/abs/2110.11773
- [9]Borjan Geshkovski, Cyril Letrouit, Yury Polyanskiy, and Philippe Rigollet. The emergence of clusters in self-attention dynamics. In Advances in Neural Information Processing Systems, volume 36, 2023.DOI
- [10]Borjan Geshkovski, Cyril Letrouit, Yury Polyanskiy, and Philippe Rigollet. A mathematical perspective on transformers. Bulletin of the American Mathematical Society, 62(3):427–479, 2025.arxiv.org/abs/2312.10794
- [11]Yury Polyanskiy, Philippe Rigollet, and Andrew Yao. Synchronization of mean-field models on the circle. arXiv preprint arXiv:2507.22857, 2025.arxiv.org/abs/2507.22857
- [12]Álvaro Rodríguez Abella, João Pedro Silvestre, and Paulo Tabuada. The asymptotic behavior of attention in transformers, 2024. Revised 2025; arXiv:2412.02682.arxiv.org/abs/2412.02682
- [13]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. Philosophical Transactions of the Royal Society A, 383(2298):20240233, 2025.arxiv.org/abs/2501.03096
- [14]Valérie Castin, Pierre Ablin, José Antonio Carrillo, and Gabriel Peyré. A unified perspective on the dynamics of deep transformers. Foundations of Computational Mathematics, 2026. Accepted for publication (in press); arXiv:2501.18322.arxiv.org/abs/2501.18322
- [15]Ricky T. Q. Chen, Yulia Rubanova, Jesse Bettencourt, and David K. Duvenaud. Neural ordinary differential equations. In Advances in Neural Information Processing Systems, volume 31, 2018.arxiv.org/abs/1806.07366
- [16]Nikita Karagodin, Yury Polyansky, and Philippe Rigolet. Clustering in causal attention masking. In Advances in Neural Information Processing Systems, volume 37, 2024. arXiv:2411.04990.arxiv.org/abs/2411.04990
- [17]Petar Veličković, Guillem Cucurull, Arantxa Casanova, Adriana Romero, Pietro Liò, and Yoshua Bengio. Graph attention networks. In International Conference on Learning Representations, 2018.arxiv.org/abs/1710.10903
- [18]Ziniu Hu, Yuxiao Dong, Kuansan Wang, and Yizhou Sun. Heterogeneous graph transformer. In Proceedings of The Web Conference 2020, pages 2704–2710, 2020.arxiv.org/abs/2003.01332
- [19]Borjan Geshkovski, Hugo Koubbi, Yury Polyansky, and Philippe Rigollet. Dynamic metastability in the self-attention model, 2024. arXiv:2410.06833.arxiv.org/abs/2410.06833
- [20]Christian Kuehn and Jaeyoung Yoon. Spectral selection in symmetric self-attention dynamics. arXiv preprint arXiv:2604.26085, 2026.arxiv.org/abs/2604.26085
- [21]Akiyoshi Tomihari and Ryo Karakida. Recurrent self-attention dynamics: An energy-agnostic perspective from jacobians. In Advances in Neural Information Processing Systems, 2025. arXiv:2505.19458.arxiv.org/abs/2505.19458
- [22]Sixu Li, Thomas Jacob Maranzatto, Jan Peszek, Trevor Teolis, Semih Akkoc, Konstantin Riedl, Semnur Ulukus, and Nicolás Garcia Trillos. On the diverse dynamical behaviors arising in deep linear transformers. arXiv preprint arXiv:2607.18584, 2026.arxiv.org/abs/2607.18584
- [23]J. D. Mireles James. From Low-Dimensional Chaos to High-Dimensional Dynamics in Self-Attention Systems: Project website. GitHub Pages, 2026. Available at: https://j-mireles-james.github.io/self-attention-dynamics/.arxiv.org/abs/2611.29951
- [24]Eusebius J. Doedel. Lecture notes on numerical analysis of nonlinear equations. In Bernd Krauskopf, Hinke M. Osinga, and Jorge Galán-Vioque, editors, Numerical Continuation Methods for Dynamical Systems: Path Following and Boundary Value Problems, pages 1–49. Springer, 2007.DOI
- [25]Yuri A. Kuznetsov. Elements of Applied Bifurcation Theory. Springer, 3 edition, 2004.
- [26]Giancarlo Benettin, Luigi Galgani, Antonio Giorgilli, and Jean-Marie Strelcyn. Lyapunov characteristic exponents for smooth dynamical systems and for hamiltonian systems: A method for computing all of them. part 2: Numerical application. Meccanica, 15(1):21–30, 1980.
- [27]Dongsheng Wang, Casper Hansen, Lucas Chaves Lima, Christian Hansen, Maria Maistro, Jakob Grue Simonsen, and Christina Lioma. Multi-head self-attention with role-guided masks. In Advances in Information Retrieval: 43rd European Conference on IR Research (ECIR 2021), Part II, volume 12657 of Lecture Notes in Computer Science, pages 432–439. Springer, 2021.arxiv.org/abs/2012.12366
- [28]PyTorch Team. FlexAttention: The flexibility of PyTorch with the performance of FlashAttention. PyTorch Blog, August 7, 2024. https://pytorch.org/blog/flexattention/.
- [29]Neil Fenichel. Persistence and smoothness of invariant manifolds for flows. Indiana University Mathematics Journal, 21(3):193–226, 1972.DOI
- [30]Morris W. Hirsch, Charles C. Pugh, and Michael Shub. Invariant Manifolds, volume 583 of Lecture Notes in Mathematics. Springer, Berlin, 1977.
- [31]Michael Shub. Global Stability of Dynamical Systems. Springer-Verlag, New York, 1987.DOI
- [32]Anatole Katok and Boris Hasselblatt. Introduction to the Modern Theory of Dynamical Systems, volume 54 of Encyclopaedia of Mathematics and its Applications. Cambridge University Press, 1995.
- [33]Albert Q. Jiang, Alexandre Sablavrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, and William El Sayed. Mistral 7B, 2023. arXiv:2310.06825.arxiv.org/abs/2310.06825
- [34]Mistral AI. Mistral 7B. Mistral AI company announcement, September 27, 2023. https://mistral.ai/news/announcing-mistral-7b/.
- [35]Ju yeong Ji and Ravin Kumar. Gemma explained: What’s new in Gemma 2. Google Developers Blog, August 22, 2024. https://developers.googleblog.com/gemma-explained-new-in-gemma-2/.
- [36]Ze Liu, Yutong Lin, Yue Cao, Han Hu, Yixuan Wei, Zheng Zhang, Stephen Lin, and Baining Guo. Swin Transformer: Hierarchical vision transformer using shifted windows. In Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV), pages 10012–10022, 2021.arxiv.org/abs/2103.14030
- [37]Yunlong Wang, Huizhe Zhang, Haonan Hu, Yudong Li, Bing Wen, Jianchao Tu, Chengxiang Zhuo, and Zang Li. CCFormer: Efficient cross-field interaction and hierarchical sequence compression for industrial recommendation at Tencent, 2026. arXiv:2607.28070.arxiv.org/abs/2607.28070
- [38]Zongtao Liu, Bin Ma, Quan Liu, Jian Xu, and Bo Zheng. Heterogeneous graph neural networks for large-scale bid keyword matching. In Proceedings of the 30th ACM International Conference on Information and Knowledge Management (CIKM 2021), pages 3976–3985. ACM, 2021.DOI
- [39]Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of NAACL-HLT 2019, Volume 1 (Long and Short Papers), pages 4171–4186. Association for Computational Linguistics, 2019.arxiv.org/abs/1810.04805
- [40]Peter Shaw, Jakob Uszkoreit, and Ashish Vaswani. Self-attention with relative position representations. In Proceedings of NAACL-HLT 2018, Volume 2 (Short Papers), pages 464–468. Association for Computational Linguistics, 2018.arxiv.org/abs/1803.02155
- [41]Ofir Press, Noah Smith, and Mike Lewis. Train short, test long: Attention with linear biases enables input length extrapolation. In International Conference on Learning Representations, 2022.arxiv.org/abs/2108.12409
- [42]NVIDIA. Attention — NVIDIA cuDNN. NVIDIA, 2026. Accessed November 20, 2026; https://docs.nvidia.com/cudnn/latest/operations/Attention/.