Title: The Clock and the Pizza: Two Stories in Mechanistic Explanation of Neural Networks
Venue: NeurIPS 2023
Accepted: yes
Keywords: mechanistic interpretability

algorithmic phase transitions

arithmetic learning

neural network

transformer

ensemble
Abstract: Do neural networks, trained on well-understood algorithmic tasks, reliably rediscover known algorithms? Several recent studies, on tasks ranging from group operations to in-context linear regression, have suggested that the answer is yes. Using modular addition as a prototypical problem, we show that algorithm discovery in neural networks is sometimes more complex: small changes to model hyperparameters and initializations can induce discovery of qualitatively different algorithms from a fixed training set, and even learning of multiple different solutions in parallel. In modular addition, we specifically show that models learn a known *Clock* algorithm, a previously undescribed, less intuitive, but comprehensible procedure we term the *Pizza* algorithm, and a variety of even more complex procedures. Our results show that even simple learning problems can admit a surprising diversity of solutions, motivating the development of new tools for mechanistically characterizing the behavior of neural networks across the algorithmic phase space.

The Clock and the Pizza: Two Stories in Mechanistic Explanation of Neural Networks

Abstract

Do neural networks, trained on well-understood algorithmic tasks, reliably rediscover known algorithms for solving those tasks? Several recent studies, on tasks ranging from group arithmetic to in-context linear regression, have suggested that the answer is yes. Using modular addition as a prototypical problem, we show that algorithm discovery in neural networks is sometimes more complex. Small changes to model hyperparameters and initializations can induce discovery of qualitatively different algorithms from a fixed training set, and even parallel implementations of multiple such algorithms. Some networks trained to perform modular addition implement a familiar Clock algorithm (previously described by Nanda et al. [1]); others implement a previously undescribed, less intuitive, but comprehensible procedure we term the Pizza algorithm, or a variety of even more complex procedures. Our results show that even simple learning problems can admit a surprising diversity of solutions, motivating the development of new tools for characterizing the behavior of neural networks across their algorithmic phase space. 1

1 Introduction

Mechanistically understanding deep network models-reverse-engineering their learned algorithms and representation schemes-remains a major challenge across problem domains. Several recent studies [2, 3, 4, 5, 1] have exhibited specific examples of models apparently re-discovering interpretable (and in some cases familiar) solutions to tasks like curve detection, sequence copying and modular arithmetic. Are these models the exception or the rule? Under what conditions do neural network models discover familiar algorithmic solutions to algorithmic tasks?

In this paper, we focus specifically on the problem of learning modular addition, training networks to compute sums like 8 + 6 = 2 (mod 12) . Modular arithmetic can be implemented with a simple geometric solution, familiar to anyone who has learned to read a clock: every integer is represented as an angle, input angles are added together, and the resulting angle evaluated to obtain a modular sum (Figure 1, left). Nanda et al. [1] show that specific neural network architectures, when trained to perform modular addition, implement this Clock algorithm. In this work, we show that the Clock algorithm is only one part of a more complicated picture of algorithm learning in deep networks. In particular, networks structurally similar to the ones trained by Nanda et al. preferentially implement a qualitatively different approach to modular arithmetic, which we term the Pizza algorithm (Figure 1, right), and sometimes even more complex solutions. Models exhibit sharp algorithmic phase transitions [6] between the Clock and Pizza algorithms as their width and attention strength very, and often implement multiple, imperfect copies of the Pizza algorithm in parallel.

Clock

Algorithm

Pizza

Algorithm

Same-label predictions

are spread over two

slices of

pizza

=5 (mod 12)

2+3

1+4

12+5

11+6

9+8 10+7

1

2

3

4

5

6

7

8

9

10

11

12

Ea

Eb

E

ab

=

E

a

+

E

b

2

Step 1

: Embed token

and

to a circle where

for some

a

b

wk

= 2

πk

/

p

k

∈ [1,2/uni22EF,

p

-1]

Step 2

: compute the angle sum using multiplication.

Step 3

: score possible outputs

using a dot product.

c

Step 2.1

: compute the vector mean.

E

ab

= (

E

a

+

E

b

)/2 = (cos(

wk

a

) + cos(

wk

b

), sin(

wk

a

) + sin(

wk

b

))/2

Same-label predictions

collapse to a number

on a

clock

5

2+3=1+4=12+5=11+6

=10+7=9+8=5 (mod 12)

Input

Embed

MLP or

Transformer

Unembed

Logit

a

→

E

a

≡ (

E

a

,

x

,

E

a

,

y

) = (cos(

wk

a

), sin(

wk

a

)),

b

→

E

b

≡ (

E

b

,

x

,

E

b

,

y

) = (cos(

wk

b

), sin(

wk

b

))

1

2

3

4

5

6

7

8

9

10

11

12

θ

a

θ

b

θ

ab

=

θ

a

+

θ

b

E

a

E

b

E

ab

E

ab

≡

(

E

ab

,

x

E

ab

,

y

)

=

(

E

a

,

x

E

b

,

x

-

E

a

,

y

E

b

,

y

E

a

,

x

E

b

,

y

+

E

a

,

y

E

b

,

x

)

=

(

cos(

wk

(

a

+

b

))

wk

(

a

+

b

))

)

=

U

c

⋅

H

ab

,

a

,

b

E

a

,

E

b

E

ab

U

c

≡ (

E

c

,

x

,

E

c

,

y

) = (cos(

wk

c

), sin(

wk

c

))

⋅

U

c

(Clock) = cos(

wk

(

a

+

b

-

c

))

(Pizza) =

cos(

wk

(

a

+

b

-

c

))

Step 2.2

: using      and nonlinearities to compute

E

ab

H

ab

=

|

cos(

wk

(

a

-

b

)/2)

|

(cos(

wk

(

a

+

b

)), sin(

wk

(

a

+

b

)))

H

ab

H

ab

=

E

ab

H

ab

cos(

wk

(

a

-

b

)/2)

Our results highlight the complexity of mechanistic description in even models trained to perform simple tasks. They point to characterization of algorithmic phase spaces, not just single algorithmic solutions, as an important goal in algorithm-level interpretability.

Organization In Section 2, we review the Clock algorithm [1] and show empirical evidence of deviation from it in models trained to perform modular addition. In Section 3, we show that these deviations can be explained by an alternative Pizza algorithm. In Section 4, we define additional metrics to distinguish between these algorithms, and detect phase transitions between these algorithms (and others Non-circular algorithms) when architectures and hyperparameters are varied. We discuss the relationship between these findings and other work on model interpretation in Section 5, and conclude in Section 6.

2 Modular Arithmetic and the Clock Algorithm

Setup We train neural networks to perform modular addition a + b = c (mod p ) , where a, b, c = 0 , 1 , · · · , p -1 . We use p = 59 throughout the paper. In these networks, every integer t has an associated embedding vector E t ∈ R d . Networks take as input embeddings [ E a , E b ] ∈ R 2 d and predict a categorical output c . Both embeddings and network parameters are learned. In preliminary experiments, we train two different network architectures on the modular arithmetic task, which we refer to as: Model A and Model B. Model A is a one-layer ReLU transformer [7] with constant attention, while Model B is a standard one-layer ReLU transformer (see Appendix F.1 for details). As attention is not involved in Model A, it can also be understood as a ReLU MLP (Appendix G).

2.1 Review of the Clock Algorithm

As in past work, we find that after training both Model A and Model B, embeddings ( E a , E b in Figure 1) usually describe a circle [8] in the plane spanned by the first two principal components of the embedding matrix. Formally, E a ≈ [cos( w k a ) , sin( w k a )] where w k = 2 πk/p , k is an integer in [1 , p -1] . Nanda et al. [1] discovered a circuit that uses these circular embeddings to implement an interpretable algorithm for modular arithmetic, which we call the Clock algorithm.

"If a meeting starts at 10, and lasts for 3 hours, then it will end at 1." This familiar fact is a description of a modular sum, 10+3 = 1 (mod 12) , and the movement of a clock describes a simple algorithm for modular arithmetic: the numbers 1 through 12 are arranged on a circle in 360 ◦ / 12 = 30 ◦ increments, angles of 10 × 30 ◦ and 3 × 30 ◦ are added together, then this angle is evaluated to determine that it corresponds to 1 × 30 ◦ .

Remarkably, Nanda et al. [1] find that neural networks like our Model B implement this Clock algorithm, visualized in Figure 1 (left): they represent tokens a and b as 2D vectors, and adding their polar angles using trigonometric identities. Concretely, the Clock algorithm consists of three steps: In step 1, tokens a and b are embedded as E a = [cos( w k a ) , sin( w k a )] and E b = [cos( w k b ) , sin( w k b )] , respectively, where w k = 2 πk/p (an everyday clock has p = 12 and k = 1 ). Then the polar angles of E a and E b are added (in step 2) and extracted (in step 3) via trigonometric identities. For each candidate output c , we denote the logit Q abc ; the predicted output is c ∗ = argmax c Q abc .

Crucial to this algorithm is the fact that the attention mechanism can be leveraged to perform multiplication. What happens in model variants when the attention mechanism is absent, as in Model A? We find two pieces of evidence of deviation from the Clock algorithm in Model A.

2.2 First Evidence for Clock Violation: Gradient Symmetricity

Since the Clock algorithm has logits:

glyph[negationslash]

(see Figure 1) the gradients of Q abc generically lack permutation symmetry in argument order: ∇ E a Q abc = ∇ E b Q abc . Thus, if learned models exhibit permutation symmetry ( ∇ E a Q abc = ∇ E b Q abc ), they must be implementing some other algorithm.

We compute the 6 largest principal components of the input embedding vectors. We then compute the gradients of output logits (unnormalized log-probabilities from the model) with respect to the input embeddings. We then project them onto these 6 principal components (since the angles relevant to the Clock and Pizza algorithms are encoded in the first few principal components). These projections are shown in Figure 2. While Model B demonstrates asymmetry in general, Model A exhibits gradient symmetry.

(a,b,c)=(37,28,16)

山

40

40

ddings

S

30

S

6

ul

30

b

em

?

20

b

20

10

?

10

token

oken

0

0

pu

-10

pu

-10

2

2

-20

-20

Gradients

adients

-30

ModelAPCAGradients

-30

ModelAPCAGradients

-40

ModelBPCAGradients

Grac

-40

ModelBPCAGradients

-40

-20

0

20

40

-40

-20

0

20

40

Gradients on1st token embeddings Ea

Gradients on 1st token embeddings Ea

2.3 Second Evidence for Clock Violation: Logit Patterns

Inspecting models' outputs, in addition to inputs, reveals further differences. For each input pair ( a, b ) , we compute the output logit assigned to the correct label a + b . We visualize these correct logits from Models A and B in Figure 3. Notice that the rows are indexed by a -b and the columns by a + b . From Figure 3, we can see that the correct logits of Model A have a clear dependency on a -b in that within each row, the correct logits are roughly the same, while this pattern is not observed in Model B. This suggests that Models A and B are implementing different algorithms.

CorrectLogitsofModelA

CorrectLogitsofModelB

28

- 30

26

(a-b) mod 59

29

(a-b) mod 59

24

28

22

20

27

18

26

16

0

3

6

(a+b)mod59

(a+b)mod59

3 An Alternative Solution: the Pizza Algorithm

How does Model A perform modular arithmetic? Whatever solution it implements must exhibit gradient symmetricity in Figure 2 and the output patterns in Figure 3. In this section, we describe a new algorithm for modular arithmetic, which we call the Pizza algorithm, and then provide evidence that this is the procedure implemented by Model A.

3.1 The Pizza Algorithm

Unlike the Clock algorithm, the Pizza algorithm operates inside the circle formed by embeddings (just as pepperoni are spread all over a pizza), instead of operating on the circumference of the circle. The basic idea is illustrated in Figure 1: given a fixed label c , for all ( a, b ) with a + b = c (mod p ) , the points E ab = ( E a + E b ) / 2 lie on a line though the origin of a 2D plane, and the points closer to this line than to the lines corresponding to any other c form two out of 2 p mirrored 'pizza slices', as shown at the right of the figure. Thus, to perform modular arithmetic, a network can determine which slice pair the average of the two embedding vectors lies in. Concretely, the Pizza algorithm also consists of three steps. Step 1 is the same as in the Clock algorithm: the tokens a and b are embedded at E a = (cos( w k a ) , sin( w k a )) and E b = (cos( w k b ) , sin( w k b )) , respectively. Step 2 and Step 3 are different from the Clock algorithm. In Step 2.1, E a and E b are averaged to produce an embedding E ab . In Step 2.2 and Step 3, the polar angle of E ab is (implicitly) computed by computing the logit Q abc for any possible outputs c . While one possibility of doing so is to take the absolute value of the dot product of E ab with (cos( w k c/ 2) , sin( w k c/ 2)) , it is not commonly observed in neural networks (and will result in a different logit pattern). Instead, Step 2.2 transforms E ab into a vector encoding | cos( w k ( a -b ) / 2) | (cos( w k ( a + b )) , sin( w k ( a + b ))) , which is then dotted with the output embedding U c = (cos( w k c ) , sin( w k c )) . Finally, the prediction is c ∗ = argmax c Q abc . See Appendix A and Appendix L for a more detailed analysis of a neural circuit that computes H ab in a real network.

The key difference between the two algorithms lies in what non-linear operations are required: Clock requires multiplication of inputs in Step 2, while Pizza requires only absolute value computation, which is easily implemented by the ReLU layers. If neural networks lack inductive biases toward implementing multiplication, they may be more likely to implement Pizza rather than Clock , as we will verify in Section 4.

3.2 First Evidence for Pizza : Logit Patterns

Both the Clock and Pizza algorithms compute logits Q abc in Step 3, but they have different forms, shown in Figure 1. Specifically, Q abc ( Pizza ) has an extra multiplicative factor | cos( w k ( a -b ) / 2) | compared to Q abc ( Clock ) . As a result, given c = a + b , Q abc ( Pizza ) is dependent on a -b , but Q abc ( Clock ) is not. The intuition for the dependence is that a sample is more likely to be classified correctly if E ab is longer. The norm of this vector depends on a -b . As we observe in Figure 3, the logits in Model A indeed exhibit a strong dependence on a -b .

3.3 Second Evidence for Pizza : Clearer Logit Patterns via Circle Isolation

To better understand the behavior of this algorithm, we replace the embedding matrix E with a series of rank-2 approximations: using only the first and second principal components, or only the third and fourth, etc. For each such matrix, embeddings lie in a a two-dimensional subspace. For both Model A and Model B, we find that embeddings form a circle in this subspace (Figure 4 and Figure 5, bottom). We call this procedure circle isolation . Even after this drastic modification to the trained models' parameters, both Model A and Model B continue to behave in interpretable ways: a subset of predictions remain highly accurate, with this subset determined by the periodicity of the k of the isolated circle. As predicted by the Pizza and Clock algorithms described in Figure 1, Model A's accuracy drops to zero at specific values of a -b , while Model B's accuracy is invariant in a -b . Applying circle isolation to Model A on the two principal components (one circle) yields a model with 32 . 8% overall accuracy, while retaining the first six principal components (three circles) yields an overall accuracy of 91 . 4% . See Appendix D for more discussion. By contrast, Model B achieves 100% when embeddings are truncated to the first six principal components. Circle isolation thus reveals an error correction mechanism achieved via ensembling: when an algorithm (clock or pizza) exhibits systematic errors on subset of inputs, models can implement multiple algorithm variants in parallel to obtain more robust predictions.

Correct Logits of Model A after CircleIsolation

10

15

20

25

30

10

15

20

25

0.0

2.55.07.510.012.515.017.5

-10

-5

0

10

6S pow L/(q-e)

(a-b)/20 mod 59

(a-b)/4 mod 59

(a-b)/4 mod 59

0 3 6 9 12151821242730333639424548515457

0 3 6 9 12151821242730333639424548515457

0 3 6 9 12151821242730333639424548515457

0 3 6 9 12151821242730333639424548515457

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

Circle from Principal Component 1, 2

Circle from Principal Component 3,4

Circle from Principal Component 5,6

Circle from Principal Component 11,12

0.6

122 29

0.6

0.6

0.3

22086,49

6205

0.4

0.4

0.4

0.2

0.2

0.2

0.2

0.1

0.0

Circle #1, 6 = 7

0.0

Circle #2,6=20

0.0

Circle #3,6= 4

00

Circle #6,6=2

0.2

0.2

0.2

0.1

0.4

0.6

53181 3720

58

0.4

0.6

29

9283

0.4

0.3

0.2

0.6

0.4

0.2

0.0

0.2

0.4

0.6

0.6

0.4

0.2

0.0

0.2

0.4

0.6

0.4

0.2

0.0

0.2

0.4

0.6

0.3

0.2

0.1

0.0

0.1

0.2

0.3

Using these isolated embeddings, we may additionally calculate the isolated logits directly with formulas in Figure 1 and compare with the actual logits from Model A. Results are displayed in Table 2. We find that Q abc ( Pizza ) explains substantially more variance than Q abc ( Clock ) .

Why do we only analyze correct logits? The logits from the Pizza algorithm are given by Q abc ( Pizza ) = | cos( w k ( a -b ) / 2) | cos( w k ( a + b -c )) . By contrast, the Clock algorithm has logits Q abc ( Clock ) = cos( w k ( a + b -c )) . In a word, Q abc ( Pizza ) has an extra multiplicative factor | cos( w k ( a -b ) / 2) | compared to Q abc ( Clock ) . By constraining c = a + b (thus cos( w k ( a + b -c )) = 1 ), the factor | cos( w k ( a -b ) / 2) | can be identified.

(Unexpected) dependence of logits Q abc ( Clock ) on a + b : Although our analysis above expects logits Q abc ( Clock ) not to depend on a -b , they do not predict its dependence on a + b . In Figure 5, we surprisingly find that Q abc ( Clock ) is sensitive to this sum. Our conjecture is that Step 1 and Step 2 of the Clock are implemented (almost) noiselessly, such that same-label samples collapse to the same point after Step 2. However, Step 3 (classification) is imperfect after circle isolation, resulting in fluctuations of logits. Inputs with common sums a + b produce the same logits.

Correct Logits of Model B after Circle Isolation

20

30

40

50

-10

0

10203040

50

20

0

20

40

40

20

0

20

40

6S pow 6/(q-e)

6S pow TT/(q-e)

(a-b)/14 mod 59

(a-b)/14 mod 59

0 3 6 9 12151821242730333639424548515457

0 3 6 9 12151821242730333639424548515457

0 3 6 9 12151821242730333639424548515457

0 3 6 9 12151821242730333639424548515457

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

Circle from Principal Component 1, 2

Circle from Principal Component 3,4

Circle from Principal Component 5,6

Circle from Principal Component 7,8

0.8

0.6

54632e190

0.8

0.6

0.4

0.6

0.3

0.4

24

0.4

0.2

0.2

0.2

0.2

0.1

0.0

Circle #1,6= 9

0.0

Circle #2, 6 =11

0.0

Circle #3,6 =14

0.0

Circle #4,6=7

0.2

0.2

0.2

0.1

0.4

0.6

0.4

0.4 -

0.2

0.8

0.6

0.6 L

0.3

0.75 0.50 0.25 0.00

0.25

0.50

0.75

0.75 0.50 0.25

0.00

0.25

0.50

0.75

0.6

-0.4

0.2

0.0

0.2

0.4

0.6

0.3

0.2

0.1

0.0

0.1

0.2

0.3

3.4 Third Evidence for Pizza : Accompanied & Accompanying Pizza

The Achilles' heel of the Pizza algorithm is antipodal pairs. If two inputs ( a, b ) happen to lie antipodally, then their middle point will lie at the origin, where the correct 'pizza slice' is difficult to identify. For example in Figure 1 right, antipodal pairs are (1,7), (2,8), (3,9) etc., whose middle points all collapse to the origin, but their class labels are different. Models cannot distinguish between, and thus correctly classify, these pairs. Even for odd p 's where there are no strict antipodal pairs, approximately antipodal pairs are also more likely to be classified incorrectly than non-antipodal pairs.

Intriguingly, neural networks find a clever way to compensate for this failure mode. we find that pizzas usually come with 'accompanying pizzas'. An accompanied pizza and its accompanying pizza complement each other in the sense that near-antipodal pairs in the accompanied pizza become adjacent or close (i.e, very non-antipodal) in the accompanying pizza. If we denote the difference between adjacent numbers on the circle as δ and δ 1 , δ 2 for accompanied and accompanying pizzas, respectively, then δ 1 = 2 δ 2 (mod p ) . In the experiment, we found that pizzas #1/#2/#3 in Figure 4 all have accompanying pizzas, which we call pizzas #4/#5/#6 (see Appendix D for details). However, these accompanying pizzas do not play a significant role in final model predictions 2 . We conjecture that training dynamics are as follows: (1) At initialization, pizzas #1/#2/#3 correspond to three different 'lottery tickets' [9]. (2) In early stages of training, to compensate the weaknesses (antipodal pairs) of pizzas #1/#2/#3, pizzas #4/#5/#6 are formed. (3) As training goes on (in the presence of weight decay), the neural network gets pruned. As a result, pizzas #4/#5/#6 are not significantly involved in prediction, although they continue to be visible in the embedding space.

4 The Algorithmic Phase Space

In Section 3, we have demonstrated a typical Clock (Model A) and a typical Pizza (Model B). In this section, we study how architectures and hyperparametes govern the selection of these two algorithmic 'phases'. In Section 4.1, we propose quantitative metrics that can distinguish between Pizza and Clock . In Section 4.2, we observe how these metrics behave with different architectures and hyperparameters, demonstrating sharp phase transitions. The results in this section focus Clock and Pizza models, but other algorithmic solutions to modular addition are also discovered, and explored in more detail in Appendix B.

4.1 Metrics

We wish to study the distribution of Pizza and Clock algorithms statistically, which will require us to distinguish between two algorithms automatically. In order to do so, we formalize our observations in Section 2.2 and 2.3, arriving at two metrics: gradient symmetricity and distance irrelevance .

4.1.1 Gradient Symmetricity

To measure the symmetricity of the gradients, we select some input-output group ( a, b, c ) , compute the gradient vectors for the output logit at position c with respect to the input embeddings, and then compute the cosine similarity. Taking the average over many pairs yields the gradient symmetricity.

Definition 4.1 (Gradient Symmetricity) . For a fixed set S ⊆ Z 3 p of input-output pairs 3 , define gradient-symmetricity of a network M with embedding layer E as

where sim ( a, b ) = a · b | a || b | is the cosine-similarity, Q abc is the logit for class c given input a and b . It is clear that s g ∈ [ -1 , 1] .

As we discussed in Section 2.2, the Pizza algorithm has symmetric gradients while the Clock algorithm has asymmetric ones. Model A and Model B in Section 3 have gradient symmetricity 99 . 37% and 33 . 36% , respectively (Figure 2).

4.1.2 Distance Irrelevance

To measure the dependence of correct logits on differences between two inputs, which reflect the distances of the inputs on the circles, we measure how much of the variance in the correct logit matrix depends on it. We do so by comparing the average standard deviation of correct logits from inputs with the same differences and the standard deviation from all inputs.

Definition 4.2 (Distance Irrelevance) . For some network M with correct logit matrix L ( L i,j = Q ij,i + j ), define its distance irrelevance as

where std computes the standard deviation of a set. It is clear that q ∈ [0 , 1] .

Model A and Model B in Section 3 give distance irrelevance 0.17 and 0.85, respectively (Figure 3). A typical distance irrelevance from the Pizza algorithm ranges from 0 to 0.4 while a typical distance irrelevance from Clock algorithm ranges from 0.4 to 1.

4.1.3 Which Metric is More Decisive?

When the two metrics have conflicting results, which one is more decisive? We consider distance irrelevance as the decisive factor of the Pizza algorithm, as the output logits being dependent on the distance is highly suggestive of Pizza . On the other hand, gradient symmetricity can be used to rule out the Clock algorithm, as it requires multiplying (transformed) inputs which will result in asymmetric gradients. Figure 6 confirmed that at low distance irrelevance (suggesting pizza) the gradient symmetricity is almost always close to 1 (suggesting non-clock).

Symmetricity

1.0

0.5

0.0

Gradient

-0.5

0.2

0.4

0.6

0.8

1.0

DistanceIrrelevance

4.2 Identifying algorithmic phase transitions

How do models 'choose' whether to implement the Clock or Pizza algorithm? We investigate this question by interpolating between Model A (transformer without attention) and Model B (transformer with attention). To do so, we introduce a new hyperparameter α we call the attention rate .

For a model with attention rate α , we modify the attention matrix M for each attention head to be M ′ = Mα + J (1 -α ) . In other words, we modify this matrix to consist of a linear interpolation between the all-one matrix and the original attention (post-softmax), with the rate α controlling how much of the attention is kept. The transformer with and without attention corresponds to the case where α = 1 (attention kept) and α = 0 (constant attention matrix). With this parameter, we can control the balance of attention versus linear layers in transformers.

We performed the following set of experiments on transformers (see Appendix F.1 for architecture and training details). (1) One-layer transformers with width 128 and attention rate uniformly sampled in [0 , 1] (Figure 7). (2) One-layer transformers with width log-uniformly sampled in [32 , 512] and attention rate uniformly sampled in [0 , 1] (Figure 7). (3) Transformers with 2 to 4 layers, width 128 and attention rate uniformly sampled in [0 , 1] (Figure 11).

The Pizza and the Clock algorithms are the dominating algorithms with circular embeddings. For circular models, most observed models either have low gradient symmetricity (corresponding to the Clock algorithm) or low distance irrelevance (corresponding to the Pizza algorithm).

Two-dimensional phase change observed for attention rate and layer width. For the fixedwidth experiment, we observed a clear phase transition from the Pizza algorithm to the Clock algorithm (characterized by gradient symmetricity and distance irrelevance). We also observe an almost linear phase boundary with regards to both attention rate and layer width. In other words, the attention rate transition point increases as the model gets wider.

Dominance of linear layers determines whether the Pizza or the Clock algorithm is preferred. For one-layer transformers, we study the transition point against the attention rate and the width:

The Clock algorithm dominates when the attention rate is higher than the phase change point, and the Pizza algorithm dominates when the attention rate is lower than the point. Our explanation is: At a high attention rate, the attention mechanism is more prominent in the network, giving rise to the clock algorithm. At a low attention rate, the linear layers are more prominent, giving rise to the pizza algorithm.

The phase change point gets higher when the model width increases. Our explanation is: When the model gets wider, the linear layers become more capable while the attention mechanism receive less benefit (attentions remain scalars while outputs from linear layers become wider vectors). The linear layer therefore gets more prominence with a wider model.

Possibly hybrid algorithms between the Clock and the Pizza algorithms. The continuous phase change suggests the existence of networks that lie between the Clock and the Pizza algorithms. This is achievable by having some principal components acting as the Clock and some principal components acting as the Pizza .

GradientSymmetricity

DistanceIrrelevance

0.2

0.4

0.6

0.8

0.2

0.4

0.6

0.8

1.0

1.0

Gradient Symmetricity

Distance Irrelevance

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.0+

0.0+

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

T

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

GradientSymmetricity

DistanceIrrelevance

0.2

0.4

0.6

0.8

0.2

0.4

0.6

0.8

512

512

256

256

IWidth

Model

128

128

64

64

品

32+

32+

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

Existence of non-circular algorithms. Although our presentation focuses on circular algorithms (i.e., whose embeddings are circular), we find non-circular algorithms (i.e., whose embeddings do not form a circle when projected onto any plane) to be present in neural networks. See Appendix B for preliminary findings. We find that deeper networks are more likely to form non-circular algorithms. We also observe the appearance of non-circular networks at low attention rates. Nevertheless, the Pizza algorithm continues to be observed (low distance irrelevance, high gradient symmetricity).

5 Related Work

Mechanistic interpretability aims to mechanically understand neural networks by reverse engineering them [2, 3, 5, 4, 10, 11, 1, 12, 13, 14]. One can either look for patterns in weights and activations by studying single-neuron behavior (superposition [11], monosemantic neurons [15]), or study meaningful modules or circuits grouped by neurons [4, 14]. Mechanistic interpretability is closely related to training dynamics [8, 13, 1].

Learning mathematical tasks : Mathematical tasks provide useful benchmarks for neural network interpretability, since the tasks themselves are well understood. The setup could be learning from images [16, 17], with trainable embeddings [18], or with number as inputs [19, 5]. Beyond arithmetic relations, machine learning has been applied to learn other mathematical structures, including geometry [20], knot theory [21] and group theory [22].

Algorithmic phase transitions : Phase transitions are present in classical algorithms [23] and in deep learning [6, 24, 25]. Usually the phase transition means that the algorithmic performance sharply

changes when a parameter is varied (e.g., amount of data, network capacity etc). However, the phase transition studied in this paper is representational : both clock and pizza give perfect accuracy, but arrive at answers via different interal computations. These model-internal phase transitions are harder to study, but closer to corresponding phenomena in physical systems [24].

Algorithm learning in neural networks : Emergent abilities in deep neural networks, especially large language models, have recently attracted significant attention [26]. An ability is 'emergent' if the performance on a subtask suddenly increases with growing model sizes, though such claims depend on the choice of metric [27]. It has been hypothesized that the emergence of specific capability in a model corresponds to the emergence of a modular circuit responsible for that capability, and that emergence of some model behaviors thus results from a sequence of quantized circuit discovery steps [5].

6 Conclusions

We have offered a closer look at recent findings that familiar algorithms arise in neural networks trained on specific algorithmic tasks. In modular arithmetic, we have shown that such algorithmic discoveries are not inevitable: in addition to the Clock algorithm reverse-engineered by [1], we find other algorithms (including a Pizza algorithm, and more complicated procedures) to be prevalent in trained models. These different algorithmic phases can be distinguished using a variety of new and existing interpretability techniques, including logit visualization, isolation of principle components in embedding space, and gradient-based measures of model symmetry. These techniques make it possible to automatically classify trained networks according to the algorithms they implement, and reveal algorithmic phase transitions in the space of model hyperparameters. Here we found specifically that the emergence of a Pizza or Clock algorithm depends on the relative strength of linear layers and attention outputs. We additionally showed that these algorithms are not implemented in isolation; instead, networks sometimes ensemble multiple copies of an algorithm in parallel. These results offer exciting new challenges for mechanistic interpretability: (1) How to find, classify, and interpret unfamiliar algorithms in a systematic way? (2) How to disentangle multiple, parallel algorithm implementations in the presence of ensembling?

Limitations We have focused on a single learning problem: modular addition. Even in this restricted domain, qualitatively different model behaviors emerge across architectures and seeds. Significant additional work is needed to scale these techniques to the even more complex models used in real-world tasks.

Broader Impact We believe interpretability techniques can play a crucial role in creating and improving safe AI systems. However, they may also be used to build more accurate systems, with the attendant risks inherent in all dual-use technologies. It is therefore necessary to exercise caution and responsible decision-making when deploying such techniques.

References

Neel Nanda, Lawrence Chan, Tom Lieberum, Jess Smith, and Jacob Steinhardt. Progress measures for grokking via mechanistic interpretability. In The Eleventh International Conference on Learning Representations , 2023.

Chris Olah, Nick Cammarata, Ludwig Schubert, Gabriel Goh, Michael Petrov, and Shan Carter. Zoom in: An introduction to circuits. Distill , 2020. https://distill.pub/2020/circuits/zoom-in.

Catherine Olsson, Nelson Elhage, Neel Nanda, Nicholas Joseph, Nova DasSarma, Tom Henighan, Ben Mann, Amanda Askell, Yuntao Bai, Anna Chen, Tom Conerly, Dawn Drain,

Deep Ganguli, Zac Hatfield-Dodds, Danny Hernandez, Scott Johnston, Andy Jones, Jackson Kernion, Liane Lovitt, Kamal Ndousse, Dario Amodei, Tom Brown, Jack Clark, Jared Kaplan, Sam McCandlish, and Chris Olah. In-context learning and induction heads. Transformer Circuits Thread , 2022. https://transformer-circuits.pub/2022/in-context-learning-and-inductionheads/index.html.

Kevin Ro Wang, Alexandre Variengien, Arthur Conmy, Buck Shlegeris, and Jacob Steinhardt. Interpretability in the wild: a circuit for indirect object identification in GPT-2 small. In The Eleventh International Conference on Learning Representations , 2023.

Eric J Michaud, Ziming Liu, Uzay Girit, and Max Tegmark. The quantization model of neural scaling. arXiv preprint arXiv:2303.13506 , 2023.

Ekin Akyürek, Dale Schuurmans, Jacob Andreas, Tengyu Ma, and Denny Zhou. What learning algorithm is in-context learning? investigations with linear models. In The Eleventh International Conference on Learning Representations , 2023.

Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. Advances in Neural Information Processing Systems , 30, 2017.

Ziming Liu, Ouail Kitouni, Niklas S Nolte, Eric Michaud, Max Tegmark, and Mike Williams. Towards understanding grokking: An effective theory of representation learning. Advances in Neural Information Processing Systems , 35:34651-34663, 2022.

Jonathan Frankle and Michael Carbin. The lottery ticket hypothesis: Finding sparse, trainable neural networks. In International Conference on Learning Representations , 2019.

Nelson Elhage, Neel Nanda, Catherine Olsson, Tom Henighan, Nicholas Joseph, Ben Mann, Amanda Askell, Yuntao Bai, Anna Chen, Tom Conerly, Nova DasSarma, Dawn Drain, Deep Ganguli, Zac Hatfield-Dodds, Danny Hernandez, Andy Jones, Jackson Kernion, Liane Lovitt, Kamal Ndousse, Dario Amodei, Tom Brown, Jack Clark, Jared Kaplan, Sam McCandlish, and Chris Olah. A mathematical framework for transformer circuits. Transformer Circuits Thread , 2021. https://transformer-circuits.pub/2021/framework/index.html.

Nelson Elhage, Tristan Hume, Catherine Olsson, Nicholas Schiefer, Tom Henighan, Shauna Kravec, Zac Hatfield-Dodds, Robert Lasenby, Dawn Drain, Carol Chen, Roger Grosse, Sam McCandlish, Jared Kaplan, Dario Amodei, Martin Wattenberg, and Christopher Olah. Toy models of superposition. Transformer Circuits Thread , 2022.

Bilal Chughtai, Lawrence Chan, and Neel Nanda. A toy model of universality: Reverse engineering how networks learn group operations. In The Fortieth International Conference on Machine Learning , 2023.

Ziming Liu, Eric J Michaud, and Max Tegmark. Omnigrok: Grokking beyond algorithmic data. In The Eleventh International Conference on Learning Representations , 2023.

Arthur Conmy, Augustine N Mavor-Parker, Aengus Lynch, Stefan Heimersheim, and Adrià Garriga-Alonso. Towards automated circuit discovery for mechanistic interpretability. arXiv preprint arXiv:2304.14997 , 2023.

Wes Gurnee, Neel Nanda, Matthew Pauly, Katherine Harvey, Dmitrii Troitskii, and Dimitris Bertsimas. Finding neurons in a haystack: Case studies with sparse probing. arXiv preprint arXiv:2305.01610 , 2023.

Yedid Hoshen and Shmuel Peleg. Visual learning of arithmetic operation. In Proceedings of the AAAI Conference on Artificial Intelligence , 2016.

Samuel Kim, Peter Y Lu, Srijon Mukherjee, Michael Gilbert, Li Jing, Vladimir ˇ Ceperi´ c, and Marin Soljaˇ ci´ c. Integration of neural network-based symbolic regression in deep learning for scientific discovery. IEEE Transactions on Neural Networks and Learning Systems , 32(9):41664177, 2020.

Alethea Power, Yuri Burda, Harri Edwards, Igor Babuschkin, and Vedant Misra. Grokking: Generalization beyond overfitting on small algorithmic datasets. arXiv preprint arXiv:2201.02177 , 2022.

Boaz Barak, Benjamin Edelman, Surbhi Goel, Sham Kakade, Eran Malach, and Cyril Zhang. Hidden progress in deep learning: SGD learns parities near the computational limit. Advances in Neural Information Processing Systems , 35:21750-21764, 2022.

Yang-Hui He. Machine-learning mathematical structures. International Journal of Data Science in the Mathematical Sciences , 1(01):23-47, 2023.

Sergei Gukov, James Halverson, Fabian Ruehle, and Piotr Sułkowski. Learning to unknot. Machine Learning: Science and Technology , 2(2):025035, 2021.

Alex Davies, Petar Veliˇ ckovi´ c, Lars Buesing, Sam Blackwell, Daniel Zheng, Nenad Tomašev, Richard Tanburn, Peter Battaglia, Charles Blundell, András Juhász, et al. Advancing mathematics by guiding human intuition with ai. Nature , 600(7887):70-74, 2021.

Alexander K Hartmann and Martin Weigt. Phase transitions in combinatorial optimization problems: basics, algorithms and statistical mechanics . John Wiley & Sons, 2006.

Lorenza Saitta, Attilio Giordana, and Antoine Cornuejols. Phase transitions in machine learning . Cambridge University Press, 2011.

Ekdeep Singh Lubana, Eric J Bigelow, Robert P Dick, David Krueger, and Hidenori Tanaka. Mechanistic mode connectivity. In International Conference on Machine Learning , pages 22965-23004. PMLR, 2023.

Jason Wei, Yi Tay, Rishi Bommasani, Colin Raffel, Barret Zoph, Sebastian Borgeaud, Dani Yogatama, Maarten Bosma, Denny Zhou, Donald Metzler, Ed H. Chi, Tatsunori Hashimoto, Oriol Vinyals, Percy Liang, Jeff Dean, and William Fedus. Emergent abilities of large language models. Transactions on Machine Learning Research , 2022. Survey Certification.

Rylan Schaeffer, Brando Miranda, and Sanmi Koyejo. Are emergent abilities of large language models a mirage? arXiv preprint arXiv:2304.15004 , 2023.

Michael Hassid, Hao Peng, Daniel Rotem, Jungo Kasai, Ivan Montero, Noah A. Smith, and Roy Schwartz. How much does attention actually attend? questioning the importance of attention in pretrained transformers. In Findings of the Association for Computational Linguistics: EMNLP 2022 , pages 1403-1416, Abu Dhabi, United Arab Emirates, December 2022. Association for Computational Linguistics.

Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization. In International Conference on Learning Representations , 2019.

Supplementary material

A Mathematical Analysis and An Example of Pizza Algorithm

In the pizza algorithm, we have E ab = cos( w k ( a -b ) / 2) · (cos( w k ( a + b ) / 2) , sin( w k ( a + b ) / 2)) , as cos x +cos y = cos(( x -y ) / 2)(2 cos(( x + y ) / 2)) and sin x +sin y = cos(( x -y ) / 2)(2 sin(( x + y ) / 2)) .

To get | cos( w k ( a -b ) / 2) | (cos( w k ( a + b )) , sin( w k ( a + b ))) , we generalize this to | cos( w k ( a -b ) / 2) | cos( w k ( a + b -u )) (the two given cases correspond to u = 0 and u = π/ 2 /w k ).

thus their difference will be equal to

Now notice | cos( t ) | - | sin( t ) | ≈ cos(2 t ) for any t ∈ R (Figure 8), so the difference is approximately | cos( w k ( a -b ) / 2) | cos( w k ( a + b -u )) .

1.00

0.75

0.50

0.25

0.00

0.25

-0.50

0.75

cos(2t)

|cos(t)l-|sin(t)

1.00

0

1

2

3

4

5

6

Plugging in u = 0 and u = π/ 2 /w k as mentioned, we get the following particular implementation of the pizza algorithm.

Algorithm: Pizza, Example

Step 1 On given input a and b , circularly embed them to two vectors on the circumference (cos( w k a ) , sin( w k a )) and (cos( w k b ) , sin( w k b )) .

Step 2 Compute:

Step 3 Output of this pizza is computed as a dot product.

Similar circuits are observed in the wild, but instead of the above two-term approximation, a more complicated one is observed. See Appendix L for details.

The extra | cos( w k ( a -b ) / 2) | term is not a coincidence. We can generalize our derivation as the following.

Lemma A.1. A symmetric function f ( x, y ) that is a linear combination of cos x, sin x, cos y, sin y 4 can always be written as cos(( x -y ) / 2) g ( x + y ) for some function g .

This is why we consider the output pattern with the | cos( w k ( a -b ) / 2) | terms rather than the actual computation circuits as the determinant feature of the pizza algorithm.

B Non-Circular algorithms

One thing that further complicates our experiment is the existence of non-circular embeddings. While only circular algorithms are reported in the previous works [8, 1], many non-circular embeddings are found in our experiments, e.g., 1D lines or 3D Lissajous-like curves, as shown in Figure 9. We leave the detailed analysis of these non-circular algorithms for future study. Since circular algorithms are our primary focus of study, we propose the following metric circularity to filter out non-circular algorithms. The metric reaches maximum 1 when the principal components aligns with cosine waves.

0.5

0.0

Principal Component1

-0.5

16

50

25

01734

9

43

18

52

27

2

36

11

45

20

54

29

4

38

13

47

22

56

31

6

40

15

49

24

58

Component

2

Component

3

1.0

onent

3

1.0

0.5

0.5

Compe

0.5

0.0

0.0

0.0

Princi

ledi

0.5

Princip

p

-0.5

inci

p

0.5

P

-1.0

-1.0

-0.5

0.0

0.5

-0.5

0.0

0.5

-0.5

0.0

0.5

Principal Component1

Principal Component1

PrincipalComponent2

Definition B.1 (Circularity) . For some network, suppose the l -th principal component of its input embeddings is v l, 0 , v l, 1 , · · · , v l,p -1 , define its circularity based on first four components as

where i is the imaginary unit. c ∈ [0 , 1] by Fourier analysis. c = 1 means first four components are Fourier waves.

Both Model A and Model B in Section 3 have a circularity around 99 . 8% and we consider models with circularity ≥ 99 . 5% circular .

C More Results from the Main Experiments

Here we provide Figure 7 with non-circular networks unfiltered (Figure 10). We can see more noise emerging in the plot. We also provide the training results from multi-layer transformers (Figure 11).

GradientSymmetricity

Distancelrrelevance

0.2

0.4

0.6

0.8

0.2

0.4

0.6

0.8

1.0

1.0

Gradient Symmetricity

Distance Irrelevance

0.8

0.8

0.6

0.4

0.2

circular

0.2

circular

non-circular

non-circular

0.0+

0.0+

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

GradientSymmetricity

DistanceIrrelevance

0.2

0.4

0.6

0.8

0.2

0.4

0.6

0.8

512

512

256

256

128

128

64

64

non-circular

non-circular

circular

circular

32

32

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

D Pizzas Come in Pairs

Cautious readers might notice that the pizza algorithm is imperfect - for near antipodal points, the sum vector will have a very small norm and the result will be noise-sensitive. While the problem is partially elevated by the use of multiple circles instead of one, we also noticed another pattern emerged: accompanying pizzas .

The idea is the following: suppose the difference between adjacent points is 2 k mod p , then the antipodal points have difference ± k . Therefore, if we arrange a new circle with a difference k for adjacent points, we will get a pizza that works best for formerly antipodal points.

Algorithm: Accompanying Pizza

Step 1 Take w k as of the accompanied pizza. On given input a and b , circularly embed them to two vectors on the circumference (cos(2 w k a ) , sin(2 w k a )) and (cos(2 w k b ) , sin(2 w k b )) .

Step 2 Compute the midpoint:

Step 3 Output of this pizza is computed as a dot product.

This is exactly what we observed in Model A (Table 3, Figure 13). With the six circles (pizzas and accompanying pizzas) included in the embedding, Model A also gets 100% accuracy.

GradientSymmetricity

DistanceIrrelevance

GradientSymmetricity

0.2

0.4

0.6

0.8

0.2

0.4

0.6

0.8

0.4

0.6

0.8

亡

1.0

1.0

1.0

DistanceIrrelevance

tSymmetricity

DistanceIrrelevance

0.8

0.8

0.8

0.6

0.6

0.6

0.4

Gradient S

0.4

0.4

0.2

non-circular

0.2

■

non-circular

0.2

...

circular

circular

circular

0.0+

0.0+

0.0+

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

AttentionRate

GradientSymmetricity

DistanceIrrelevance

GradientSymmetricity

0.2

0.4

0.6

0.8

0.2

0.4

0.6

0.8

0.4

0.6

0.8

广

1.0

1.0

1.0

Distance Irrelevance

Gradient Symmetricity

Distance Irrelevance

0.8

0.8

0.8

0.6

0.6

0.6

0.4

0.4

0.4

0.2

non-circular

0.2

口

non-circular

0.2

circular

circular

circular

0.0+

0.0+

0.0+

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

AttentionRate

Gradient Symmetricity

DistanceIrrelevance

Gradient Symmetricity

0.0

0.2

0.4

0.6

0.8

0.2

0.4

0.6

0.8

0.2

0.4

0.6

0.8

1.0

1.0

1.0

Distance Irrelevance

0.8

Gradient Symmetricity

0.8

Distance Irrelevance

0.8-

0.6

0.6

0.6

0.4

1

0.4

0.4

0.2

■

non-circular

0.2

non-circular

0.2

circular

.

circular

品

circular

0.0+

0.0+

0.0+

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

AttentionRate

Accompanied and Accompanying Pizza (p = 11)

0

0

10

1

5

6

9

0+1

2

10

0+5

0+1

1

-direction

0+5:

8

3

4

-direction

7

4

9

6

5

3

8

0+1 → larger norm →more likely to be correct

0+1 → sum points at a point → negative result

0+5 → sum points between points →positive result

Correct Logits of Model A after Accompanying Circle Isolation

-20

-10

0

10

20

15

-10

-5

5

10

15

-10

-5

0

5

10

6s pow L/(q-e)

(a-b)/20 mod 59

(a-b)/4 mod 59

0 3 6 912151821242730333639424548515457

0 3 6 912151821242730333639424548515457

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

CirclefromPrincipal Component6,7

CirclefromPrincipal Component8,9

Circlefrom Principal Component 10,11

E'0

0.4

2

30 3744

11

.825

E'0

086.46

5727

0.3

220181614

8

6A

20 51

0.2

54

0.2

18

0.2

02284

6

0.1

5320

0.1

24 1484

24

58

0.1

0:0

2,40

Circle #4,=26

0.0

Circle#5,6=10

0.0

Circle #6,6=2

34

39

0.1

265

151

0.1 -

0.1

0.2

55.22.48

0.2

0.2

FE'0-

8

324

43

29

E'0-

52

12

431

221

50

FE'0-

35

0.4

-0.4

-0.2

0.0

0.2

0.4

0.4

-0.2

0.0

0.2

0.4

0.3

-0.2

0.1

0.0

0.1

0.2

0.3

E Results in Other Linear Architectures

While this is not the primary focus of our paper, we also ran experiments on the following four different linear model setups (see Section F.2 for setup details).

For all the models, we first encode input tokens ( a, b ) with a trainable embedding layer W E : x 1 = W E,a , x 2 = W E,b (positional embedding removed for simplicity). L 1 , L 2 , L 3 are trainable linear layers. The outmost layers (commonly referred as unembed layers) have no biases and the other layers have biases included for generality.

Model α : calculate output logits as L 2 ( ReLU ( L 1 ( x 1 + x 2 ))) .

Model β : calculate output logits as L 3 ( ReLU ( L 2 ( ReLU ( L 1 ( x 1 + x 2 ))))) .

Model γ : calculate output logits as L 3 ( ReLU ( L 2 ( ReLU ( L 1 ( x 1 ) + L 1 ( x 2 ))))) .

Model δ : calculate output logits as L 2 ( ReLU ( L 1 ([ x 1 ; x 2 ]))) ( [ x 1 ; x 2 ] stands for the concatenation of x 1 and x 2 )

The results are shown in Figure 14. Rather surprisingly, Model α , Model β and Model δ gave radically different results. Model β and Model γ are very similar, and in general they are more pizza-like

1.0

1.0

00)(0.0)0

0.9

Gradient Symmetricity

0.8

Circularity

0.8

0.6

0.4

FL0

ModelType

Model Type

α

0.2

α

0.6

β

β

0.0

0.5

8

6

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1.0

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1.0

Distancelrrelevancy

DistanceIrrelevancy

35

40-

Modely

40

Model 6

35

30

30

# of Runs

25

25

20

20

20

20

15

15

10

10-

10

10

5

5

0

0

0

0

0.4

0.5

0.6

0.7

0.4

0.6

0.8

0.92

0.94

0.96

0.98

0.4

0.5

0.6

0.7

Distance Irrelevancy

Distance Irrelevancy

Distance Irrelevancy

Distance Irrelevancy

than Model α , with lower distance irrelevancy and higher circularity. This could be explained by the addition of an extra linear layer.

However, Model δ gave very different results from Model α although they are both one-layer linear models. It is more likely to be non-circular and have very high distance irrelevancy in general. In other words, concatenating instead of adding embeddings yields radically different behaviors in one-layer linear model. This result, again, alarmed us the significance of induction biases in neural networks.

We also want to note that using different embeddings on two tokens of Model α doesn't resolve the discrepancy. The following model

Model α ′ : calculate output logits as L 2 ( ReLU ( L 1 ( x 1 + x 2 ))) where x 1 = W A E,a , x 2 = W B E,b on input ( a, b ) and W A E , W B E are different embedding layers.

gives roughly the same result as of Model α (Figure 14, lower right corner).

Figure 15 shows the correct logits after circle isolation (Section 3.3) of a circular model from Model β implementing the pizza algorithm. Figure 16 shows the correct logits after circle isolation (Section 3.3) of a circular model from Model δ . We can see the pattern is similar but different from the one of clock algorithm (Figure 5). We leave the study of such models to future work.

F Architecture and Training Details

F.1 Transformers

Here we describe our setup for the main experiments. See Appendix E and Appendix I for experiments on different setups.

Architecture We train bidirectional transformers (attention unmasked) to perform modular addition mod p where p = 59 . To calculate ( a + b ) mod p , the input is provided to the model as a sequence

2

4

6

8

10

12

14

(a-b)/2 mod 59

(a+b) mod 59

6

8

10

(a+b) mod 59

0

4

6

8

10

12

0 3 6 912151821242730333639424548515457

(a+b) mod 59

Circle from Principal Component 1, 2

0.75

1.00

5048

30

3836

1.00

0.75

29

524

51

406

14.9

41

0.75

1.00

44

23

19.

576

0.50

0.50

494

36

0.50

5635

14.52

522048265

0.25

0.25

26 53

0.25

398

245

0.00

21

Circle #1,6=2

22

0.00

337

Circle#2,6=27

18

0.00

3.56

22

Circle #3,6=21

30

0.25

16

0.25 -

0.25

0.50

0.75

3

6

3

457 49 55357

0.75

1.00

0.50

20

52

25

13.4550 232

18

558

0.50

0.75

3

5517

380

242

25

246 8

29

50

12

33

1.00

1.0

0.5

0.0

0.5

1.0

-0.5

0.0

0.5

1.0

-0.5

0.0

0.5

1.0

4.0

4.5

5.0

5.5

6.0

6.5

7.0

7.5

(a-b)/23 mod 59

(a+b) mod 59

m

5

6

0 3 6 9 12151821242730333639424548515457

(a+b) mod 59

4

5

6

(a-b)/24 mod 59

(a+b)mod 59

(a-b)/29 mod 59

687578

29 0 39 31

54

41

1.0

0.5

8

2418

2#1

1.0 -

0.5 -

0.5 -

1.0

47358

1045

34

328

56

21

43

6

52

15 5026

3748

2

0.0

Circle #1,6=23

0.0

50

Circle #2,6=29

0.0

12

Circle #3,6=24

365

49

0.5

0.5

0.5

3

1.0

26

1.0

1.0

26

40

9

53

18

31

55

0.5

0.5

1.0

0.0

0.5

1.0

-1.0

0.0

0.5

1.0

-1.0

0.5

0.0

0.5

1.0

of two tokens [ a, b ] . The output logit at the last token is considered as the output of the model. For a transformer with 'width' d , the input embedding and the residue stream will be d -dimensional, 4 attention heads of glyph[floorleft] d/ 4 glyph[floorright] dimensions will be employed, and the MLP will be of 4 d hidden units. By default d = 128 is chosen. ReLU is used as the activation function and layer normalization isn't applied. The post-softmax attention matrix is interpolated between an all-one matrix and original as

0

12

14

(a-b)/27 mod 59

6s pow tz/(q-e)

specified by the attention rate (Section 4.2). We want to point out that the setup of constant-attention transformers is also considered in the previous work [28].

Data Among all possible data points ( p 2 = 3481 of them), we randomly select 80% as training samples and 20% as validation samples. This choice (small p and high training data fraction) helps accelerating the training.

Training We used AdamW optimizer [29] with learning rate γ = 0 . 001 and weight decay factor β = 2 . We do not use minibatches and the shuffled training data is provided as a whole batch in every epoch. For each run, we start the training from scratch and train for 20 , 000 epoches. We removed the runs that did not reach 100% validation accuracy at the end of the training (majority of the runs reached 100% ).

F.2 Linear Models

Here we describe our setup for the linear model experiments (Appendix E).

Architecture We train several types of linear models to perform modular addition mod p where p = 59 . The input embedding, residue stream and hidden layer are all d = 256 dimensional. ReLU is used as the activation function. The actual structures of network types are specified in Appendix E.

Data & Training Same as in the previous section (Section F.1).

F.3 Computing Resources

A total of 226 GPU days of NVidia V100 is spent on this project, although we expect a replication would take significantly fewer resources.

G Mathematical Description of Constant-Attention transformer

In this section, we examine the structure of constant-attention transformers loosely following the notation of [10].

Denote the weight of embedding layer as W E , the weight of positional embedding as W pos, the weight of the value and output matrix of the j -th head of the t -th layer as W t,j V and W t,j O , the weights and biases of the input linear map of MLP in the t -th layer as W t in and b t in , the corresponding weights and biases of the output linear map as W t out and b t out , and the weight of the unembedding layer as W U . Notice that the query and the key matrices are irrelevant as the attention matrix is replaced with an all-one matrix. Denote x j as the value of residue stream vector after the first j layers and denote c i as the character in the i -th position. We use subscripts like x t to denote taking a specific element of vector.

We can formalize the logit calculation as the following:

Embedding: x 0 i = W E,c i + W pos ,i .

For each layer t from 1 to n layer :

-Constant Attention: w t i = x t -1 i + ∑ j W t,j O W t,j V ∑ k x t -1 k .

-MLP: x t = w t + b t out + W t outReLU ( b t in + W t in w t ) .

Output: O = W U x n layer .

In the particular case where the input length is 2 , the number of layer is 1 , and we focus on the logit of the last position, we may restate as the following (denote z as x 1 and y as w 1 ):

Embedding: x 1 = W E,c 1 + W pos , 1 , x 2 = W E,c 2 + W pos , 2 .

Constant Attention: y = x 2 + ∑ j W j O W j V ( x 1 + x 2 ) .

MLP: z = y + b t out + W t outReLU ( b t in + W t in y ) .

Output: o = W U z .

If we remove the skip connections, the network after embedding could be seen as

where L j V , L j O , L in , L out , L U are a series of linear layers corresponding to the matrices.

H Pizza with Attention

Extrapolating from Figure 7, we trained transformers with width 1024 and attention rate 1 (normal attention). After several tries, we are able to observe a trained circular model with distance irrelevance 0 . 156 and gradient symmetricity 0 . 995 , which fits our definition of Pizza (Figure 17).

10

15

20

0

2

4

6

8

10

12

14

6

8

10

12

6

8

10

(a-b)/12 mod 59

(a-b)/8 mod 59

6S pow T/(q-e)

(a-b)/27 mod 59

0 3 6 9 12151821242730333639424548515457

0

3 6 9 12151821242730333639424548515457

0

3 6 9 12151821242730333639424548515457

0 3 6 9 12151821242730333639424548515457

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

Circle from Principal Component 1, 2

Circle from Principal Component 3, 4

Circle from Principal Component 5,6

Circle from Principal Component 7,8

0.6

0.6

0.6

20

191817

0.6

t0

0.4

0.4

10

0.4

0.2

0.2

0.2

9

0.2

0.0

Circle #1, 6 =12

0.0

Circle #2,6=8

0.0

Circle #3, 6 =1

65

0.0

Circle #4, 6=13

0.2

0.2

0.2

389

2

0.2

11

0.4

0.6

0.6

0.4

5#

0.4

0.6

34

456 47

0.6

0.4

0.6

-0.4

0.2

0.0

0.2

0.4

0.6

0.6

0.4

0.2

0.0

0.2

0.4

0.6

0.6

0.4

0.2

00

0.2

0.4

0.6

0.6

0.4

0.2

0.0

0.2

0.4

0.6

I Results on Slightly Different Setups

We considered the following variations of our setups (Appendix F.1, Section 4), for which the existence of pizzas and clocks as well as the phase changes are still observed.

GeLU instead of ReLU We conducted the same 1-layer transformer experiment with activation function GeLU instead of ReLU. Very similar results are observed (Figure 18).

Encode Two Tokens Differently We conducted the 1-layer transformer experiments but with different embedding for the two tokens. Again very similar results are observed (Figure 19). We also discovered that the two tokens' embeddings are often aligned to implement the Pizza and Clock algorithm (Figure 20).

Adding Equal Sign We conducted the 1-layer transformer experiment with an equal sign added. Very similar results are observed (Figure 21).

J Pizza Occurs Early in the Clock Training

We plotted intermediate states during the training of a model with attention (attention rate 1). Pizzalike pattern was observed early in the training, but the pattern gradually disappeared during the run (Figure 22).

GradientSymmetricity

Gradient Symmetricity

-0.2

0.0

0.2

0.4

0.6

0.8

0.4

0.6

0.8

1.0

1.0

Irrelevance

Irrelevance

0.8

0.8

0.6

0.6

Distance

0.4

Distance

0.4

0.2

non-circular

0.2

circular

circular

0.0+

0.0+

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

DistanceIrrelevance

Circularity

0.2

0.4

0.6

0.8

0.4

0.6

0.8

1.0

1.0

:Symmetricity

Irrelevance

0.8

0.8

0.6

0.6

Distance！

Gradient

0.4

0.4

0.2

non-circular

0.2

non-circular

circular

circular

0.0+

0.0-

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

GradientSymmetricity

DistanceIrrelevance

-0.25

0.00

0.25

0.50

0.75

0.2

0.4

0.6

0.8

1.0

1.0

icity

levance

0.8

0.8

netri

Irrel

0.6

Symr

E

0.6

istance

0.4

0.4

adier

0.2

0.2

G

0.0+

0.0-

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

0

5

10

15

20

25

30

35

0

5

10

15

20

0.0

2.5

5.0

7.5

10.0

12.5

15.0

(a-b)/19 mod 59

(a-b)/17 mod 59

(a-b)/18 mod 59

0 3 6 912151821242730333639424548515457

0 3 6 912151821242730333639424548515457

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

Circle from Principal Component 1, 2

Circle from Principal Component 3, 4

Circle from Principal Component 5,6

0.4

0.4

0.4

0.2

0.2

0.2

0.0

Circle #1,6=19

0.0

Circle#2,6=17

0.0

Circle#3,6=18

0.2

0.2

0.2

0.4

0.4

5 43369

0.4

0.4

0.2

0.4

-0.2

0.0

0.2

-0.4

-0.2

0.0

0.4

-0.4

-0.2

0.0

0.2

0.4

GradientSymmetricity

GradientSymmetricity

0.90

0.92

0.94

0.96

0.98

0.90

0.92

0.94

0.96

0.98

1.0

1.0

levance

ance

0.8

0.8

>

Irrel

0.6

Irrel

e

0.6

e

0.4

0.4

C

istal

n

is

0.2

non-circular

0.2

D

circular

D

circular

0.0+

0.0+

0.0

0.2

0.4

0.6

0.8

1.0

0.0

0.2

0.4

0.6

0.8

1.0

AttentionRate

AttentionRate

K Accompanying Pizza Occurs Early in the Pizza Training

We plotted intermediate states during the training of a model without attention (attention rate 0). We observed the early emergence of a pattern similar to accompanying pizza in training runs (Figure

0.5 L,

0:0

0.5

·

0.0

：

".

.

0.5

0.5

0.0

0.5

0.0

：

..

0.5

0.5

0.0

`.

0.5

0.5

0.0

0.5

3

0.0

...

0.5

-0.5

0.0

0.5

0.0

0.5

-0.5

00

0.5

:

..

0.0

·

0.5

Iso.Correct Logits

Iso. Correct Logits

Iso.Correct Logits

Iso.Correct Logits

Iso. Correct Logits

Iso.Correct Logits

(a-b)/4 mod 59

(a-b)/4 mod 59

20

6s pow t/(q-e)

20

(a-b)/16 mod 59

2  。

6s pow ez/(q-e)

20

6S pow 9t/(q-e)

20

20

10

10

10

10

0

-10

3

-0

-10

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

300Steps

PC 1, 2

PC 1, 3

PC 1, 4

PC 2, 3

PC 2, 4

PC 3, 4

0.5

0.5

0.0

.

0.5

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

：

...

：

：

.

:

：

..

0.5

0.5

0.0

...

：

0.5

s'0

0.0

：

'

:..

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

Iso.Correct Logits

Iso.Correct Logits

Iso.Correct Logits

Iso.Correct Logits

Iso.Correct Logits

Iso.Correct Logits

(a-b)/16 mod 59

(a-b)/4 mod 59

(a-b)/4 mod 59

(a-b)/20 mod 59

6s pow z/(q-e)

(a-b)/16 mod 59

20

20

20

20

-20

RIR

0

0

o

0

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

510 Steps

PC 1, 2

PC 1, 3

PC 1, 4

PC 2, 3

PC 2, 4

PC 3, 4

0.5

0.5

0.0

。

、

。

0.5

0.0

0.5

、

0.5

0.5

0.0

：

·

：

.·

·

0.5

0.5

0.0

.·.

0.5

0.5

0.0

.*

、

1

0.5

0.5

0.0

。。

..

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

Iso. Correct Logits

Iso.Correct Logits

Iso.Correct Logits

Iso.Correct Logits

Iso. Correct Logits

Iso.Correct Logits

(a-b)/4 mod 59

40

(a-b)/4 mod 59

- 40

(a-b)/4 mod 59

- 40

(a-b)/23 mod 59

40

(a-b)/23 mod 59

(a-b)/23 mod 59

- 40

20

20

20

20

20

0

0

。

0

0

0

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

840 Steps

PC 1, 2

PC 1, 3

PC 1, 4

PC 2, 3

PC 2, 4

PC 3, 4

0.5

0.0

0.5

：

.·

.

.

...

0.5

0.0

0.5

0.5

0.5

0.0

：：

.·

..

0.5

0.5

0.0

:.

:.

·

0.5

0.5

0.0

·

·

。

·.

0.5

0.5

0.0

：

0.5

0.0

0.5

-0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

0.5

0.0

0.5

Iso. Correct Logits

Iso.Correct Logits

Iso.Correct Logits

Iso. Correct Logits

Iso. Correct Logits

Iso. Correct Logits

(a-b)/4 mod 59

40

(a-b)/4 mod 59

40

(a-b)/4 mod 59

40

(a-b)/4 mod 59

(a-b)/23 mod 59

40

(a-b)/23 mod 59

-40

20

20

20

20

20

0

0

。

0

-0

-20

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

(a+b) mod 59

23) and removing that circle brings accuracy down from 99.7% to 97.9%. They are less helpful later in the network (removing accompanying pizzas in trained Model A only brings accuracy down to 99.7%).

0

10

20

30

40

-30

-20

-10

0

10

20

(a-b)/20 mod 59

(a-b)/20 mod 59

(a+b)mod59

(a+b)mod59

Circle from Principal Component 1, 2

Circle fromPrincipal Component 13,14

27

26

5

24

25

。

34

35

$4

6

0.2

0.2

287

3

36

16

29

42

0.1 -

33

25

0.1

10

58

22

23

53

55

41

0:0

51

Circle #1,6 =20

21

40

0:0

12

26Circle5#7

10

31.12

46 $718

47

0.1

52

38

29g0

11

42

380

21291

50

33

19

-0.1

48

0.2

53

14

55

16

56

36

17

57

58

0.2

1

49

10

58

20

E'0-

-0.3

-0.2

-0.1

0.0

0.1

0.2

0.3

-0.2

-0.1

0.0

0.1

0.2

L A Closer Look at a Linear Pizza Model

In this section, we provide a full picture of the linear model shown in Figure 15 by investigating the actual weights in the model.

L.1 Model Structure

As described in Appendix E, on input ( a, b ) , the output logits of the model is computed as

Denote the weight of embedding layer as W E , the weight of the unembedding layer ( L 3 ) as W U , and the weights and biases of L 1 and L 2 as W 1 , b 1 and W 2 , b 2 , respectively, then the output logits on input ( a, b ) can be written as

L.2 General Picture

We first perform principal component visualizations on the embedding and unembedding matrices. From Figure 24, we can see that the embedding and unembedding matrices formed matching circles (circles with the same gap δ between adjacent entries).

We now give the general overview of the circuit. Each pair of matching circles forms an instance of Pizza and they operate independently (with rather limited interference). Specifically for each pair,

The embedding matrix first places the inputs a, b on the circumference: W ′ E [ a ] ≈ (cos( w k a ) , sin( w k a )) and W ′ E [ b ] ≈ (cos( w k b ) , sin( w k b )) ( w k = 2 πk/p for some integer k ∈ [1 , p -1] as in Section 2.1; W ′ E stands for the two currently considered principal components of W E ; rotation and scaling omitted for brevity).

The embeddings are added to get

It is then passed through the first linear layer L 1 . Each result entry pre-ReLU will thus be a linear combination of the two dimensions of the aforementioned vectors, i.e. cos( w k ( a -b ) / 2) · ( α cos( w k ( a + b ) / 2) + β sin( w k ( a + b ) / 2)) for some α, β , which will become | cos( w k ( a -b ) / 2) || α cos( w k ( a + b ) / 2) + β sin( w k ( a + b ) / 2)) | after ReLU.

These values are then passed through the second linear layer L 2 . Empirically the ReLU is not observed to be effective as the majority of values is positive. The output entries are then simply linear combinations of aforementioned outputs of L 1 .

The unembedding matrix is finally applied. In the principal components we are considering, W ′ U [ c ] ≈ (cos( w k c ) , sin( w k c )) . ( W ′ U stands for the two currently considered principal components of W U ; rotation and scaling omitted for brevity) and these two principal components correspond to a linear combination of the output entries of L 2 , which then correspond to a linear combination of the outputs of L 1 (thanks to the non-functional ReLU).

Similar to the formula | sin( t ) | - | cos( t ) | ≈ cos(2 t ) discussed in Appendix A, these linear combinations provide good approximations for | cos( w k ( a -b ) / 2) | cos( w k ( a + b )) and | cos( w k ( a -b ) / 2) | sin( w k ( a + b )) . Finally we arrive at

.

Embedding:Circle fromPC1,2

Embedding:Circle from PC3,4

Unembedding:Circle from PC 1,2

Unembedding:Circle fromPC 3,4

1.0

1.0

524

6

1.0

43

1.0

123942

3

0.5

0.0

We Circle #1,6=2

36

2

8

6

0.0

0.5

B27WeCircle #2,6=27

94

0.5

0.0

WuCircle#1,6=2

9

0.5

0.0

Circle#2,6=27

8

3

8

6

10

1

0.5

3

39

0.5

20

25

563

1345502

0.5

56

4

8

-0.5

1.0

1.0

18

1.0

1.0

1.0

0.5

0.0

0.5

1.0

0.5

0.0

0.5

1.0

1.0

0.5

0.0

0.5

1.0

1.0

0.5

0.0

0.5

1.0

L.3 Aligning Weight Matrices

We first verify that the ReLU from the second layer is not functional. After removing it, the accuracy of the model remains 100% and the cross-entropy loss actually decreased from 6 . 20 × 10 -7 to 5 . 89 × 10 -7 .

Therefore, the model output can be approximately written as

We now 'align' the weight matrices W 1 and W 2 by mapping through the directions of the principal components of the embeddings and unembeddings. That is, we calculate how these matrices act on and onto the principal directions (consider W 1 v for every principal direction v in W E and v T W 2 for every principal direction v in W U ). We call the other dimension of aligned W 1 and W 2 output and source dimensions, respectively (Figure 25).

In the aligned weight matrices, we can see a clear domino-like pattern: in most output or source dimensions, only two principal components have significant non-zero values, and they correspond to a pair of matching circle, or a pizza. In this way, every immediate dimension serves for exactly one pizza, so the pizzas do not interfere with each other.

Aligned W:W acting on first 6 principal components of We

We principal dimensions

。

1.0

0.5

0.0

0.5

-1.0

5

1.5

6849999599278九0

120

144

148

152

156

160

164

168

172

176

180

184

188

192

196

204

208

120

2

2

1

11

11

1

1

2

2

2

2

2

2

2

2

2

2

output dimensions

Aligned W2:W2acting onto the first 6 principal components of Wu

Wu principal dimensions

1.0

0.5

0.0

-0.5

-1.0

1.5

6889499500927980

0

1

1

1

22

1

28 3640

33

1

1

4

1

144

148

152

156

160

164

168

172

176

180

184

188

192

196

200

204

208

216

220

2

2

2

2

2

2

2

2

2

source dimensions

L.4 Approximation

Everything becomes much clearer after realigning the matrices. For a pizza and its two corresponding principal embedding / unembedding dimensions, W ′ E [ a ] + W ′ E [ b ] ≈ cos( w k ( a -b ) / 2) · (cos( w k ( a + b ) / 2) , sin( w k ( a + b ) / 2)) will be mapped by realigned W 1 into its corresponding columns (which are different for every pizza), added with b 1 and apply ReLU. The result will then be mapped by the realigned W 2 , added with realigned b 2 , and finally multipled by (cos( w k c ) , sin( w k c )) .

For the first two principal dimensions, realigned W 1 has 44 corresponding columns (with coefficients of absolute value > 0 . 1 ). Let the embedded input be ( x, y ) = W ′ E [ a ] + W ′ E [ b ] ≈ cos( w k ( a -b ) / 2) · (cos( w k ( a + b ) / 2) , sin( w k ( a + b ) / 2)) , the intermediate columns are

ReLU ([0 . 530 x -1 . 135 y +0 . 253 , -0 . 164 x -1 . 100 y +0 . 205 , 1 . 210 x -0 . 370 y +0 . 198 , -0 . 478 x -1 . 072 y + 0 . 215 , -1 . 017 x + 0 . 799 y + 0 . 249 , 0 . 342 x -0 . 048 y + 0 . 085 , 1 . 149 x -0 . 598 y + 0 . 212 , -0 . 443 x +1 . 336 y +0 . 159 , -1 . 580 x -0 . 000 y +0 . 131 , -1 . 463 x +0 . 410 y +0 . 178 , 1 . 038 x + 0 . 905 y + 0 . 190 , 0 . 568 x + 1 . 188 y + 0 . 128 , 0 . 235 x -1 . 337 y + 0 . 164 , -1 . 180 x + 1 . 052 y + 0 . 139 , -0 . 173 x +0 . 918 y +0 . 148 , -0 . 200 x +1 . 060 y +0 . 173 , -1 . 342 x +0 . 390 y +0 . 256 , 0 . 105 x -1 . 246 y + 0 . 209 , 0 . 115 x + 1 . 293 y + 0 . 197 , 0 . 252 x + 1 . 247 y + 0 . 140 , -0 . 493 x + 1 . 252 y + 0 . 213 , 1 . 120 x +0 . 262 y +0 . 239 , 0 . 668 x +1 . 096 y +0 . 205 , -0 . 487 x -1 . 302 y +0 . 145 , 1 . 134 x -0 . 862 y + 0 . 273 , 1 . 143 x + 0 . 435 y + 0 . 171 , -1 . 285 x -0 . 644 y + 0 . 142 , -1 . 454 x -0 . 285 y + 0 . 218 , -0 . 924 x +1 . 068 y +0 . 145 , -0 . 401 x +0 . 167 y +0 . 106 , -0 . 411 x -1 . 389 y +0 . 249 , 1 . 422 x -0 . 117 y + 0 . 227 , -0 . 859 x -0 . 778 y + 0 . 121 , -0 . 528 x -0 . 216 y + 0 . 097 , -0 . 884 x -0 . 724 y + 0 . 171 , 1 . 193 x +0 . 724 y +0 . 131 , 1 . 086 x +0 . 667 y +0 . 218 , 0 . 402 x +1 . 240 y +0 . 213 , 1 . 069 x -0 . 903 y + 0 . 120 , 0 . 506 x -1 . 042 y +0 . 153 , 1 . 404 x -0 . 064 y +0 . 152 , 0 . 696 x -1 . 249 y +0 . 199 , -0 . 752 x -0 . 880 y +0 . 106 , -0 . 956 x -0 . 581 y +0 . 223]) .

For the first principal unembedding dimension, it will be taken dot product with

[1 . 326 , 0 . 179 , 0 . 142 , -0 . 458 , 1 . 101 , -0 . 083 , 0 . 621 , 1 . 255 , -0 . 709 , 0 . 123 , -1 . 346 , -0 . 571 , 1 . 016 , 1 . 337 , 0 . 732 , 0 . 839 , 0 . 129 , 0 . 804 , 0 . 377 , 0 . 078 , 1 . 322 , -1 . 021 , -0 . 799 , -0 . 339 , 1 . 117 , -1 . 162 , -1 . 423 , -1 . 157 , 1 . 363 , 0 . 156 , -0 . 165 , -0 . 451 , -1 . 101 , -0 . 572 , -1 . 180 , -1 . 386 , -1 . 346 , -0 . 226 , 1 . 091 , 1 . 159 , -0 . 524 , 1 . 441 , -0 . 949 , -1 . 248] .

Call this function f ( x, y ) . When we plug in x = cos( t ) , y = sin( t ) , we get a function that wellapproximated 8 cos(2 t +2) (Figure 26). Therefore, let t = w k ( a + b ) / 2 , the dot product will be approximately 8 | cos( w k ( a -b ) / 2) | cos( w k ( a + b ) + 2) , or | cos( w k ( a -b ) / 2) | cos( w k ( a + b )) if we ignore the phase and scaling. This completes the picture we described above.

Peer reviews:
{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThis paper takes a closer look at the mechanistic explanation of neural networks learning to perform modular addition expanding on recent work that argued that such networks discover a simple \"clock\" algorithm. The authors demonstrate that changes in initialization and hyperparameters can lead to the discovery of qualitatively different algorithms - most notably what is referred to here as the \"pizza\" algorithm. This provides evidence that even the simple learning problem of modular addition leads to the discovery of diverse solutions in neural networks and mechanistic explanation requires a more complex analysis.\n\nSTRENGTHS:\nThe paper is well written and succeeds in clearly communicating the findings on an active topic in the field of mechanistic interpretability. The analysis is carefully conducted, empirical results are mostly convincing and the conclusion is of importance for the broader field.\n\nWEAKNESSES:\nOne of the main claims of the paper is that \"some networks very similar to the ones trained by [1] preferentially implement a qualitatively different approach\" but most of the evidence presented for such different solutions only apply to models that (transiently) remove the attention mechanism.\n\nQUESTIONS:\n1. Focusing on one of the main claims that \"some networks very similar to the ones trained by [1] preferentially implement a qualitatively different approach\": What is the fraction of neural networks with attention rate 1 that according to your metrics implement the \"pizza\" algorithm? Judging from Figure 6 it seems to me that this claim might be too strong if the originally investigated model with full attention almost always discovers \"clock\" solutions.\n2. You state that you also find \"non-circular algorithms\" in your trained networks. What fraction of trained models is non-circular and removed from the main analysis? Again this would be especially insightful to understand in dependence of the attention rate.\n3. How are Distance Irrelevance and Gradient Symmetricity related to each other? From my understanding they both intend to measure the same property (pizza vs clock). A scatter plot showing one vs. the other might give some insight on their relationship. \n4. In cases where the metrics contradict each other (judging from Figure 6 this sometimes happens), can you still make a confident statement on what algorithm such solutions implement?\n6. Could you elaborate how you come to the conclusion that some solutions \"implement multiple, imperfect copies of either the Clock or Pizza algorithm in parallel.\"? How do such solutions work?\n7. Could you elaborate why accompanied pizzas achieve almost perfect accuracy (footnote of page 6) despite the failure mode of antipodal pairs?\n8. In section 3.4 you conjecture that \"accompanying pizzas\" are primarily used early in training. Would it be possible to test this hypothesis by comparing the accuracy of \"accompanied pizzas\" early in training with and without the hypothesised \"accompanying pizzas\"?\n9. Minor point: The word \"symmetricity\" is unfamiliar to me. Is there a reason to deviate from the more common term symmetry, i.e. calling your metric \"Gradient Symmetry\"?\n\nLIMITATIONS:\nLimitations have been addressed appropriately.", "TITLE": "Official Review", "RECOMMENDATION": 7, "REVIEWER_CONFIDENCE": 3, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-06-28"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nIn this paper the authors study neural networks doing modular addition of integers, i.e. output $= mod_P( a + b)$ for fixed integer P and input integers a and b. Previous work on these networks has found that small transformers implement a simple _clock_ algorithm. This work verifies this, but shows that if you simplify the transformer’s attention and make your network more like a simple feedforward ReLU network, then you find the networks implement a completely different algorithm they call the _pizza_ algorithm. Their evidence for this includes (i) strange patterns in the correct logit outputs, (ii) gradients that do not fit the clock model but can be understood in their pizza model, (iii) patterns in the logits when the inputs are restricted to particular 2D planes, and (iv) the need for error correcting that leads to particular patterns in a pizza embedding. They then study an algorithmic phase change from pizza to clock as you vary how much attention is included.\n\nSTRENGTHS:\nI thought the large-scale motivation for this work was justified, previous people have claimed that this specific task leads many networks to solve it in the same way. Turns out that isn’t true. That seems important.\nI thought the main discovery of this work was very interesting.\nI thought the evidence to back up the claim was convincing.\nI thought the experiments performed were pretty thorough.\nFor the most part the claims were not overblown (for example I really appreciated the discussion of non-circular algorithms for solving this task)\nFinally the appendix was a bit of a treasure trove.\n\nWEAKNESSES:\nI think the paper’s clarity could definitely improve. At times, mainly in the appendix where a lot of the explanation gets relegated, the paper felt rushed and the explanations were terse, expecting a lot from the reader. \n\nI found this especially true of the equations in the appendix, for example:\n\n1.\tIn appendix A you introduce $s$ on the first line, which is the same as $E_{ab}$ I think. Why do you introduce a new symbol? Why do you not make it clear it is the same as $E_{ab}$ in the main paper? \n2.\tYou then do the same, again in Appendix A, when introducing the symbol $P_c$, which is I believe $Q_{abc}$ from the main paper? You also say thus, which in maths makes me expect to understand that you have derived a result, instead at the moment it reads like a definition of $P_c$ so the use of thus is confusing. \n3.\tLine 392, in step 1 you talk about an accompanied pizza in a section that readers are expected to reach long before they read about accompanied pizzas where that adds no value as far as I can tell, but just makes the whole thing confusing.\n4.\tAppendix G was a minefield of strange notational choices in my mind. The layer index was initially denoted with i, but then changes to t, and i is reused as the token index.  I found this needlessly confusing.\n5.\tYou define $x^j$ as the value of the residual stream after j layers, but then talk about $x_{i}^j$ for a couple of lines of the algorithm, before dropping the lower index. I think this is because there’s only one output logit so after the attention you can drop which token the input is coming from, but I still found it confusing at first (because you never say what I just wrote). It felt important to specify that the lower index of x is tokens for understanding the sum over k in the constant attention equation.\n6.\tFor the next description you switch notation but still use x, but now without the top index rather than the bottom one, and use y and z. Could you highlight what is changing?\n\nAnd beyond the equations I thought that occasionally the appendix was a tough read. For example in appendix H you talked about adding an equal sign. I eventually looked at the caption for figure 19 and understood what that meant, but I thought I’d missed some previously discussed equals sign (I now realise this is a hangover from the original clocks paper). Making sure the writing doesn’t have these kind of moments when the reader hasn’t been told about something and isn’t completely sure where to find out about it seems good. Perhaps you could edit the writing and captions when you try and re-read the paper with fresh eyes to see what is confusing - or get some fresh eyes on it.\n\nA few of small things I am confused by: \n\n1.\tI think the sine and cosine addition formulae you are using in step 2 of the algorithm in appendix A, during the development of alpha and beta, are missing factors of 2. [since you use them so often maybe it would be good to state the sine and cosine addition formulae somewhere]\n2.\tIn section 3.4 it says the condition for there to be no antipodal pairs is for p to be prime, isn’t it for p to be odd? What am I missing?\n3.\tThe plots in figure 6 (and all figures like it in the appendix) are titled wrong.\n4.\tIn the formula for distance irrelevance i on the top row should i be a member of $\\mathbb{Z}_P$ not $\\mathbb{Z}_P^2$?\n\nIt seems there are a class of pizza like algorithms (e.g. the two in appendix A), and the evidence listed does not distinguish them. Is this true? Do you know which is happening? If not, perhaps figure 1 is misleading. Instead your claim is that step 3 is one example of a class of pizza type algorithms that are being implemented, and perhaps figure 1 could say that?\n\nQUESTIONS:\n1.\tWhy do you compute the gradients after having projected to first 6 principal components of the embedding space? What happens if you don’t do this?\n2.\tFurther, why on earth did you think to make this gradient symmetry plot?! Did you already have the pizza algorithm in mind and knew this would distinguish them???\n3.\tIn table 1 it says non-circular algorithms show gradient symmetry, but in general (figure 9) it appears like they don’t. Why does it say this?\n4.\tThe phase transition appears to happen at slightly different points when measured by distance irrelevance or by gradient symmetry, is this true? This definitely seems true in the 2D phase plots. How do you interpret this?\n5.\tThis study restricts itself to circular algorithms, what proportion of models were circular? \n6.\tThe phase change is not discrete, i.e. it does not just jump from the most pizza-ey to the most clock-ey. This could be outside the scope, but what do you think happens in between? An algorithm that is a mixture of the two somehow? Or an output that is a mixture of both algorithms running concurrently? Any evidence in any direction?\n\nLIMITATIONS:\nThe authors did a good job discussing limitations.", "TITLE": "Official Review", "RECOMMENDATION": 7, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 4, "DATE": "2023-07-01"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\n*Background*: Previous work in mechanistic interpretability has identified a particular algorithm that NNs implement (the clock algorithm) to solve modular addition. However, under certain architecture changes, the authors notice that NNs implement a different algorithm.\n\nThe main goal of this paper is to present inconsistencies in the clock algorithm for neural networks without attention (ie: an inductive bias that allows the model to implement multiplication) and motivate a different algorithm (the pizza) that explains a different algorithm through which such networks learn modular attention. The observations are backed by experiments on linearly interpolating between a NN with attention and an NN without it. The experiments also demonstrate that a single algorithm doesn’t always win: different models can and do ensemble multiple copies of both algorithms in parallel.\n\nSTRENGTHS:\nThe paper is very well written and the proofs and arguments presented seem airtight.  Most of the questions I’ve had while reading the paper are either addressed in subsequent sections or in the appendix. The experiments are simple yet, I believe, comprehensive in evaluating the arguments presented. This is also an exciting emerging area of research and should lead to interesting discussions in the mechanistic interpretability community.\n\nWEAKNESSES:\nThis work raises a lot of interesting questions, but I really can’t find any egregious logical inconsistencies with this work.  \nmeta-(non)concern: This work largely relies on a problem from a paper that hasn’t been peer-reviewed. However, I do not think this is a reason to reject this work.\n\nOverall, I recommend _acceptance_.\n\nQUESTIONS:\n* L78: Why the choice of 6 vectors specifically? For exposition? Will choosing less significant components introduce unnecessary noise?\n* L113: What would happen with an odd number of ReLU units?\n\nLIMITATIONS:\nThe authors have addressed limitations in the manuscript.", "TITLE": "Official Review", "RECOMMENDATION": 7, "REVIEWER_CONFIDENCE": 3, "SOUNDNESS_CORRECTNESS": 4, "DATE": "2023-07-06"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThe authors present a novel algorithm as a mechanistic explanation of neural networks for modular addition. It is noted that the model without attention fails to implement the ‘Clock’ algorithm. This assertion is substantiated with evidence related to gradient symmetricity and logit patterns. The authors then propose an alternative solution, named the ‘Pizza’ algorithm, supported by evidence concerning logit patterns via circle isolation and accompanying ‘pizza’. Ultimately, they demonstrate the presence of an algorithmic phase transition along the attention rate and model width, employing metrics that indicate gradient symmetricity and distance irrelevance.\n\nSTRENGTHS:\nThe paper is well-structured and supports its arguments with solid experiments. The authors demonstrate that a neural network is capable of learning diverse algorithms for the same task. They introduce an impressive procedure for interpreting the neural network via embedding vectors. This methodology has the potential for extension to more complex models and tasks.\n\nWEAKNESSES:\nThe authors employ the term logit $Q_{abc}$ as well as the term output logit, which refers to the un-normalized log probability. The choice of terminology, however, proves to be confusing. Given that $Q_{abc}$ is not used in the model and is a concept introduced by the authors themselves, it would be beneficial to rename $Q_{abc}$ to a more intuitive term like \"value\" or \"rank\".\n\nQUESTIONS:\nWhat prevents us from directly ascertaining the algorithm employed by the model? Couldn't it be possible to determine the intermediate vector $E_{ab}$ to gain insights into the algorithmic process?\n\nLIMITATIONS:\nAs the authors have noted, their focus lies on a simple learning problem. Significant further work is required to adapt their techniques for use with the more complex models typically employed in real-world tasks.", "TITLE": "Official Review", "RECOMMENDATION": 8, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 4, "DATE": "2023-07-15"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nIn this work, the authors focus on the problem of learning modular addition in NNs. Using clock and pizza algorithms, they show that model exhibits sharp algorithm transitions, which are affected by layer width and attention strengths, often resulting in the parallel occurrence of these phases.  A series of experiments are performed on the single-layer network to support the hypothesis proposed in this work.\n\nSTRENGTHS:\n1. Well-written paper.\n2, an useful contribution in terms of interpretability of NNs.\n3. Novel contribution in terms of analyzing the algorithmic transitions.\n\nWEAKNESSES:\n1. Ablation study is missing\n2. Did authors perform a grid search to select best hyper-parameters? Then that should be mentioned with ranges in the appendix.\n\nQUESTIONS:\nIn terms of interpretability there are models inspired by formal language theory that insert rules [1,3] and extract rules [2-7], termed as interpretable by extractions and such models are even tested on mathematical reasoning[4] task and are known to be turing complete even with finite precision and time [8]. Authors should discuss this line of work, as they are relevant.\n\nHow to determine the threshold for the circularity, does value >= 99.5% works for all model/architectures in terms of thresholding for circularity. It would be ideal if authors can provide empirical bound for this and how to determine such threshold. \n\nCan this framework be extended to convolutions with tensor weights or stateful models such as RNNs?\n\nAuthors do point out that deeper models leads to non-circular algorithms, but what is the bound for that? After how many layers non-circular behavior is shown by various models? At minimum providing empirical results will further strengthen this work. I would also like to see some empirical bounds on attention rate, what quantifies as high attention rate and what is low attention rate. Can author provide ablation study on various value of attention rate and also the width of layers?\n\nFew additional comments that are not clear from the manuscript.\n\nHow does the model effectively interpolate between the memorizing and generalizing solutions? \n\nDoes this also work with sinusoidal embeddings, masked embedding? Does the choice of embedding have an issue in generalization?\n\nThe authors do mention pruning the weights, so what effect does sparsity have in the model performance? Can authors comment on this? Like how the two-phase switch? \n\n\n\n\n\nFinally I would like to see total computational time required by the model including FLOPS and also standard error for various trials on proposed experiments.\n\nMinor comments\nThe figure 4 should be improved, its difficult to read values on y-axis and also values overlap in the circular diagram.  Same goes for other figures too.\n\t\n1.\tOmlin, C.W. and Giles, C.L., 1996. Rule revision with recurrent neural networks. IEEE Transactions on Knowledge and Data Engineering, 8(1), pp.183-188.\n2.\tTiňo, P. and Šajda, J., 1995. Learning and extracting initial mealy automata with a modular neural network model. Neural Computation, 7(4), pp.822-844.\n3.\tMali, A.A., Ororbia II, A.G. and Giles, C.L., 2020. A neural state pushdown automata. IEEE Transactions on Artificial Intelligence, 1(3), pp.193-205.\n4.\tMali, A., Ororbia, A.G., Kifer, D. and Giles, C.L., 2021, May. Recognizing and verifying mathematical equations using multiplicative differential neural units. In Proceedings of the AAAI Conference on Artificial Intelligence (Vol. 35, No. 6, pp. 5006-5015).\n5.\tWeiss, G., Goldberg, Y. and Yahav, E., 2018, July. Extracting automata from recurrent neural networks using queries and counterexamples. In International Conference on Machine Learning (pp. 5247-5256). PMLR.\n6.\tWang, C., Lawrence, C. and Niepert, M., 2022. State-Regularized Recurrent Neural Networks to Extract Automata and Explain Predictions. IEEE Transactions on Pattern Analysis and Machine Intelligence, 45(6), pp.7739-7750.\n7.\tOkudono, T., Waga, M., Sekiyama, T. and Hasuo, I., 2020, April. Weighted automata extraction from recurrent neural networks via regression on state spaces. In Proceedings of the AAAI Conference on Artificial Intelligence (Vol. 34, No. 04, pp. 5306-5314).\n8.\tStogin, J., Mali, A. and Giles, C.L., 2020. A provably stable neural network Turing Machine. arXiv preprint arXiv:2006.03651.\n\nLIMITATIONS:\nAs highlighted above, the main point is an ablation study to support the hypothesis and computational overhead.\n\n**********\nScore increased after Author rebuttal Responses", "TITLE": "Official Review", "RECOMMENDATION": 7, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-19"}