In the paper that introduced the Transformer, attention gets most of the architecture section, a figure of its own and a whole further section justifying its cost. The perceptron that follows it in every block gets a single paragraph: five sentences and an equation. Almost everything written since, courses included, has inherited that proportion, and it is the opposite of what the parameters say. In GPT-3, two out of every three parameters in each block belong to that perceptron; in Mixtral, a 2024 model that has eight copies of it per layer, the figure is 9797%.

This article asks what the perceptron is for, and the question is not rhetorical. Attention already combines the positions of the text using weights that depend on the content; a box that processes each position separately, with the same weights for all of them, looks like the least Transformer-like part of the Transformer. The answer has four parts: what attention cannot compute, what the perceptron stores that attention has nowhere to keep, why it has this shape and not another, and what has been tried in its place. First, though, a red herring needs clearing up. The paper with the most famous title on the subject, Attention is not all you need, proves something true and important, but the perceptron is not the hero of its proof.

The block, in the usual notation

A text of TT tokens enters each block as a matrix X∈RT×dmodel\mathbf{X} \in \mathbb{R}^{T \times d_{\text{model}}}, with one row per position. The block has two sublayers, each wrapped in a sum and a normalisation, LayerNorm(X+Sublayer(X))\text{LayerNorm}\left(\mathbf{X} + \text{Sublayer}(\mathbf{X})\right). Whether the normalisation comes before or after the sublayer (current models normalise the input) makes no difference to what follows. The first sublayer is multi-head attention,

MultiHead(X)=Concat(head1,…,headh)WO,headi=softmax(XWiQ(XWiK)⊤dk)XWiV,\text{MultiHead}(\mathbf{X}) = \text{Concat}\left(\text{head}_1, \dots, \text{head}_h\right)\mathbf{W}^O, \qquad \text{head}_i = \text{softmax}\left(\frac{\mathbf{X}\mathbf{W}^Q_i\left(\mathbf{X}\mathbf{W}^K_i\right)^{\top}}{\sqrt{d_k}}\right)\mathbf{X}\mathbf{W}^V_i,

and the second is what the original paper calls the FFN (feed-forward network, a network with no recurrence), which I will call the position-wise perceptron: a two-layer perceptron with a ReLU (rectified linear unit, max⁡(0,⋅)\max(0, \cdot) applied coordinate by coordinate) in between,

FFN(X)=ReLU(XW1+1Tb1⊤)W2+1Tb2⊤,\text{FFN}(\mathbf{X}) = \text{ReLU}\left(\mathbf{X}\mathbf{W}_1 + \mathbf{1}_T\mathbf{b}_1^{\top}\right)\mathbf{W}_2 + \mathbf{1}_T\mathbf{b}_2^{\top},

with W1∈Rdmodel×dff\mathbf{W}_1 \in \mathbb{R}^{d_{\text{model}} \times d_{\text{ff}}}, W2∈Rdff×dmodel\mathbf{W}_2 \in \mathbb{R}^{d_{\text{ff}} \times d_{\text{model}}} and 1T\mathbf{1}_T a column of TT ones that repeats each bias once per row. In the original paper, dmodel=512d_{\text{model}} = 512 and dff=2,048d_{\text{ff}} = 2{,}048: the hidden layer is four times as wide as the model.

Two properties follow from the formula, and they define the piece. First, W1\mathbf{W}_1 and W2\mathbf{W}_2 are the same for every row, so row tt of the output depends only on row tt of the input. The paper puts it in two sentences: the perceptron is applied to each position "separately and identically", and it is equivalent to two convolutions with a kernel of size 11. Second, each block has its own matrices: six blocks, six different perceptrons.

So the block splits the work into two halves that don't overlap. Attention is the only piece that moves information from one row to another; the perceptron transforms each row without being able to look at the others.

Two panels, each with the same five rows of the input matrix, one per position of the text, stacked from top to bottom. On the left, attention: arrows leaving all five rows converge on row 3, which receives a weighted average of all of them; it is the only part of the block that moves information from one position to another. On the right, the position-wise perceptron: each row, on its own, widens from d_model to d_ff coordinates, goes through the ReLU and comes back to d_model, with no arrows between rows and the same two matrices, W1 and W2, for all of them.

The two sublayers of a block. Attention mixes rows; the perceptron mixes the coordinates of each row. Neither does the other's job.

The red herring in the famous title

Attention is not all you need, by Dong, Cordonnier and Loukas (2021), studies what happens when you stack attention layers and nothing else: no sum around them, no perceptron and no normalisation. The result is easiest to grasp by looking at what a head does to a row. The weights αts\alpha_{ts} that come out of the softmax are positive and sum to 11 in each row, so row tt of the output is a weighted average of the rows of XWV\mathbf{X}\mathbf{W}^V. Stacking layers means taking averages of averages, and averages of averages tend to look alike.

To measure how much, define the residual of X\mathbf{X} as how far it is from having all its rows equal: res⁡(X)=X−1Tx⊤\operatorname{res}(\mathbf{X}) = \mathbf{X} - \mathbf{1}_T\mathbf{x}^{\top}, where x\mathbf{x} is the vector that makes that difference as small as possible. A matrix whose rows are all equal has rank 11, and a small residual means that every position is saying almost the same thing. The central theorem bounds the residual after LL layers of pure attention. Gathering its constants (they depend on the norms of the weight matrices, the number of heads and dkd_k) into a single cc, it reads

∥res⁡(X(L))∥≤c3L−12 ∥res⁡(X)∥3L.\left\lVert \operatorname{res}\left(\mathbf{X}^{(L)}\right) \right\rVert \le c^{\frac{3^{L}-1}{2}}\, \left\lVert \operatorname{res}(\mathbf{X}) \right\rVert^{3^{L}}.

The exponent is 3L3^{L}: in each layer the residual is, at worst, cubed. With c=1c = 1 and an initial residual of 0.50.5, the bound is 0.1250.125 after one layer, 0.0020.002 after two and 7⋅10−97 \cdot 10^{-9} after three. That is why the authors call the convergence doubly exponential. The cube has an intuitive reading: similar rows produce similar scores, similar scores give nearly uniform weights, and nearly uniform weights average things out even more. The similarity feeds on itself.

What matters for this article is the next section, where the paper puts back the pieces it had removed. Its three subheadings sum it up: the residual connection is crucial, the perceptron helps, and normalisation does nothing.

  • The residual connection (skip connection, the sum X+Sublayer(X)\mathbf{X} + \text{Sublayer}(\mathbf{X})) breaks the bound completely. With it, among the paths from input to output there is always one that goes through no attention at all, and the authors show that there are infinitely many choices of weights for which the residual never shrinks, however many layers are stacked.
  • The perceptron enters the bound as one more factor in the base: its Lipschitz constant, which is the most the function can stretch a distance. The more it stretches, the more slowly everything converges, but the convergence is still doubly exponential. The authors describe it as a tug of war and put a price on it: stretching a lot makes the model more sensitive to small perturbations of the input. In their experiments on BERT, ALBERT and XLNet with the residual connections removed, the perceptron does not seem to slow the collapse, although they warn that these models were not retrained without them.
  • Normalisation plays no part: centring and scaling the rows can be written as multiplying the matrix and adding the same vector to every row. Multiplying cannot raise the rank, and adding that vector does not change the residual.

The title is about attention, and the conclusion is about the sum. The perceptron is a supporting actor in the proof, and rank collapse is not why it is there: the residual connection prevents it on its own. There is further evidence that, with the sum and without a perceptron, a Transformer can already do real work. A Mathematical Framework for Transformer Circuits, from Anthropic (2021), deliberately studies attention-only models, and with two layers induction heads appear: pairs of heads that find an earlier occurrence of the current token in the context and copy the token that came after it, a general way of learning from the text itself. The authors leave the perceptron out because, as they write, they have had much less success understanding it. That is an honest way of saying it is the hard part.

So the question still stands. If the sum prevents the collapse and attention alone can already copy from the context, what is missing?

What attention cannot compute

One specific operation is missing, and you can see which one by opening up the Concat\text{Concat}. Call αts(i)\alpha^{(i)}_{ts} the weight head ii gives to position ss when computing row tt, and WiO\mathbf{W}^O_i the dvd_v rows of WO\mathbf{W}^O that multiply what that head returns. Row tt of MultiHead(X)\text{MultiHead}(\mathbf{X}) is

∑i=1h∑s=1Tαts(i) xsWiVWiO,\sum_{i=1}^{h}\sum_{s=1}^{T}\alpha^{(i)}_{ts}\,\mathbf{x}_s\mathbf{W}^V_i\mathbf{W}^O_i,

where xs\mathbf{x}_s is row ss of X\mathbf{X}. All of the softmax lives inside the α\alpha, and what the α\alpha decide is where to read from. What happens to what has been read is another matter: a weighted average of rows, each multiplied by two matrices. Once the weights are fixed, row tt is a linear function of the rows of X\mathbf{X}. The residual sum is linear too. Normalisation isn't, but its parameters, γ\boldsymbol{\gamma} and β\boldsymbol{\beta}, work coordinate by coordinate: none of them looks at two coordinates at once.

A small example shows why that is a problem. Take four phrases, "it's good", "it's bad", "it's not good" and "it's not bad", and assume attention has done its job well: it has carried to the row of "good" or "bad" the news of whether there is a "not" in front of it. That row now holds two coordinates that matter: n=−1n = -1 if there is a negation and n=+1n = +1 if not, and p=+1p = +1 for "good" and p=−1p = -1 for "bad". The sentiment of the phrase is their product, n⋅pn \cdot p: "not" has no sign of its own, it flips the sign of the word that follows.

No affine function of (n,p)(n, p) gives that product at all four corners. If an+bp+ca n + b p + c were equal to npn p, subtracting the two phrases without a negation would give 2b=22b = 2, and subtracting the two with one would give 2b=−22b = -2. This is XOR (exclusive or), the classic example for showing that a single neuron is not enough, and it sits entirely inside one row. Composing linear functions gives another linear function, so stacking more attention does not fix it: the two pieces of data are sitting together, and attention has no component built to combine them.

The perceptron does. With two hidden units it solves the problem exactly, because for n,p∈{−1,+1}n, p \in \{-1, +1\}

n p=1−∣n−p∣=1−ReLU(n−p)−ReLU(p−n).n\,p = 1 - \lvert n - p \rvert = 1 - \text{ReLU}(n - p) - \text{ReLU}(p - n).

In terms of the block's formula, that is two columns of W1\mathbf{W}_1 reading n−pn - p and p−np - n, two rows of W2\mathbf{W}_2 subtracting what comes out of the ReLU, and a bias b2\mathbf{b}_2 that supplies the 11. The ReLU lets the output depend on whether a combination of coordinates is positive, which is exactly what no linear function can do. This site's deep learning course devotes a section of the lesson on the Transformer block to this, using the XOR square from the lesson on hidden layers.

There is a concession to make. I have reasoned with the weights already fixed, and they don't come fixed: the α\alpha are computed from X\mathbf{X}, so attention as a whole is non-linear in its input, and a trained network can exploit that. But that non-linearity exists to choose where to read from, and using it to combine the coordinates of a single row means asking one component to do another's job. Theory divides the roles the same way. The proof that Transformers are universal approximators of sequence-to-sequence functions (Yun et al., 2020) uses attention for one thing only, letting each position know what context it is in, and leaves everything else to the perceptron: discretising the input at the start and, at the end, turning each combination of row and context into the right output value. The proof's sections are titled accordingly: quantisation by feed-forward layers, contextual mapping by self-attention, function value mapping by feed-forward layers.

Attention gathers; the perceptron computes.

Where the parameters and the operations are

That the perceptron is the piece doing the computing shows up in the budget. Per block, attention has four dmodel×dmodeld_{\text{model}} \times d_{\text{model}} matrices (the query, key and value matrices of all the heads together, plus WO\mathbf{W}^O) and the perceptron has two of size dmodel×dffd_{\text{model}} \times d_{\text{ff}}:

2 dmodel dff⏟perceptron=8 dmodel2versus4 dmodel2⏟attention,with dff=4 dmodel.\underbrace{2\, d_{\text{model}}\, d_{\text{ff}}}_{\text{perceptron}} = 8\, d_{\text{model}}^{2} \quad\text{versus}\quad \underbrace{4\, d_{\text{model}}^{2}}_{\text{attention}}, \qquad\text{with } d_{\text{ff}} = 4\, d_{\text{model}}.

That is two thirds of the block, not counting biases or normalisations, which are just vectors. GPT-3 keeps dff=4 dmodeld_{\text{ff}} = 4\, d_{\text{model}} at every size, and in the largest (9696 blocks with dmodel=12,288d_{\text{model}} = 12{,}288) that comes to 1,2081{,}208 million perceptron parameters per block against 604604 million for attention. Current models change the matrices but not the proportion: LLaMA uses three matrices instead of two and shrinks dffd_{\text{ff}} so that they add up to the same total (the section on alternatives comes back to this), and its later versions share keys and values across groups of heads (GQA, grouped-query attention), which slims down the attention and fattens the perceptron's share.

Then there is Mixtral, which has eight perceptrons per block. With dmodel=4,096d_{\text{model}} = 4{,}096, dff=14,336d_{\text{ff}} = 14{,}336, three matrices per perceptron and eight key and value heads of 128128 coordinates each, the sums for one block are

8⋅3⋅4,096⋅14,336⏟perceptrons=1,409 Mversus2⋅4,0962+2⋅4,096⋅1,024⏟attention=42 M.\underbrace{8 \cdot 3 \cdot 4{,}096 \cdot 14{,}336}_{\text{perceptrons}} = 1{,}409 \text{ M} \quad\text{versus}\quad \underbrace{2 \cdot 4{,}096^{2} + 2 \cdot 4{,}096 \cdot 1{,}024}_{\text{attention}} = 42 \text{ M}.

That is 9797% of the block. Multiply by the 3232 blocks, add the two embedding matrices (32,00032{,}000 words by 4,0964{,}096 coordinates, one at the input and one at the output), and you get about 46,70046{,}700 million parameters, the 4747 billion that Mistral AI publishes. Each token uses only two of the eight perceptrons, and even so the perceptron accounts for 8989% of the parameters each token uses in each block.

The operations tell a similar story, with a twist that depends on the length of the text. For the token at position TT, counting each multiply followed by an add as two operations, a layer with dff=4 dmodeld_{\text{ff}} = 4\, d_{\text{model}} does

8 dmodel2⏟projections Q,K,V,O+4 T dmodel⏟scores and weighted sum+16 dmodel2⏟perceptron.\underbrace{8\, d_{\text{model}}^{2}}_{\text{projections } Q, K, V, O} + \underbrace{4\, T\, d_{\text{model}}}_{\text{scores and weighted sum}} + \underbrace{16\, d_{\text{model}}^{2}}_{\text{perceptron}}.

The middle term is the only one that grows with TT: it comes from comparing the query with TT keys and adding up TT values. Dividing, the perceptron's share is 4 dmodel/(6 dmodel+T)4\, d_{\text{model}} / (6\, d_{\text{model}} + T): two thirds for a short text, and exactly half when T=2 dmodelT = 2\, d_{\text{model}}.

Line chart. On the horizontal axis, the position of the token in the text, T, on a logarithmic scale from 256 to 131,072. On the vertical axis, the fraction of one layer's operations done by the position-wise perceptron, from 0 to 100%. Three curves, one per model width: d_model equal to 768, to 4,096 and to 12,288. All three start near two thirds, 67%, and fall as T grows; each crosses 50% exactly at T equal to twice d_model: at 1,536, at 8,192 and at 24,576. With d_model equal to 768 and T equal to 131,072 the perceptron is down to 2%; with 12,288, to 24%.

The share of a layer's operations done by the perceptron, for the token at position TT, according to the sum above. The quadratic cost of attention, the thing people mention most about it, only overtakes the perceptron beyond twice the width of the model.

For GPT-3 that crossover is at 24,57624{,}576 tokens, twelve times the 2,0482{,}048-token context it was trained with. Throughout its training, the perceptron's share of each layer never fell below 6464%. The figure needs careful reading: these are operations, not time. A model generating text is usually limited by how long it takes to read the weights and the key-value cache from memory, not by how long it takes to multiply, and that is a different budget.

What matters about this budget is what it leads to. Whenever people have wanted to give a model more capacity without paying for it on every token, what they have multiplied is the perceptron, and that story is in the second-to-last section.

A memory with its keys written into the weights

To see what those parameters store, it helps to rewrite the perceptron column by column. Call kj\mathbf{k}_j column jj of W1\mathbf{W}_1 and vj\mathbf{v}_j row jj of W2\mathbf{W}_2. For a row x\mathbf{x},

FFN(x)=∑j=1dffReLU(x kj+b1,j)vj+b2⊤.\text{FFN}(\mathbf{x}) = \sum_{j=1}^{d_{\text{ff}}} \text{ReLU}\left(\mathbf{x}\,\mathbf{k}_j + b_{1,j}\right)\mathbf{v}_j + \mathbf{b}_2^{\top}.

Written like this, it has the same shape as an attention head: compare the input with some keys, turn the comparisons into weights, and add up some values using those weights. There are three differences, and all three matter. In attention the keys and values come from the text; in the perceptron they are stored in the parameters, the same for any text. Attention has TT keys, one per position, while the perceptron has dffd_{\text{ff}}. And the softmax shares one unit of weight among all the keys, whereas the ReLU normalises nothing and leaves many of them at exactly zero.

Two rows with the same structure from left to right: an input, some keys it is compared with, some weights and a sum of values. At the top, one attention head: the query of row t is compared with T keys taken from the text itself, one per position; the softmax turns the T scores into positive weights that add up to one, and the output is the sum of the T values, also taken from the text, with those weights. At the bottom, the position-wise perceptron: row t is compared with d_ff keys stored in the parameters, the columns of W1, the same for any text; the ReLU leaves each coefficient at zero or at a positive number, unnormalised, and the output is the sum of d_ff values stored in the rows of W2, with those coefficients. Many coefficients are zero, and their values do not enter the sum.

The same sum of keys, weights and values. Attention looks up what is in the text; the perceptron looks up what it learnt during training.

The equivalence has been taken literally. In Augmenting Self-attention with Persistent Memory (Sukhbaatar et al., 2019), swapping the ReLU for a softmax and removing the biases turns the perceptron into attention over dffd_{\text{ff}} fixed vectors. The authors then take the next step: they remove the perceptron and add those vectors, which they call persistent memory, to the keys and values of every head, alongside the ones from the text. With as many vectors as the ReLU had units, the parameter count is the same. On enwik8, a benchmark that measures, in bits per character, how well a model compresses the first hundred million bytes of English Wikipedia, their 114114-million-parameter model matches, at 0.980.98, the best model of the time, which had 209209 million. And the most telling ablation is in the same table: with zero persistent vectors, that is, with attention and nothing acting as a perceptron, the model performs poorly. The piece can be disguised as attention; what cannot be done is to remove what it stores.

Researchers have probed what it stores in several ways. Transformer Feed-Forward Layers Are Key-Value Memories (Geva et al., 2021) takes a 1616-layer language model trained on WikiText-103, a corpus of English Wikipedia articles, with dmodel=1,024d_{\text{model}} = 1{,}024 and dff=4,096d_{\text{ff}} = 4{,}096. For a sample of keys, it finds the pieces of text that switch each one on most strongly and asks people to describe what they have in common. Every key has at least one recognisable pattern, 3.63.6 on average. In layers 11 to 99 shallow patterns dominate, such as ending in a particular word; in layers 1010 to 1616, semantic ones, such as being about a particular topic. For the values, they project each vj\mathbf{v}_j onto the vocabulary and look at which word it pushes: in the lower layers it almost never matches the word that follows the text that switches on its key, and from layer 1111 on it matches in up to 3.53.5% of cases, against 0.00040.0004% by chance. No memory works alone: a typical example switches on between 1010 and 5050% of the 4,0964{,}096, and what the whole layer predicts differs from what any single one of them predicts in at least two out of three examples.

The follow-up (Geva et al., 2022) reads each term ReLU(⋅) vj\text{ReLU}(\cdot)\,\mathbf{v}_j as a small update that raises the probability of a group of words, often a recognisable concept. And it puts that to use: switching on ten value vectors of GPT-2 by hand, 0.010.01% of the total, lowers the share of toxic continuations from 58.558.5% to 30.830.8%, at the cost of raising the perplexity (the exponential of the mean loss per token; lower is better) from 21.721.7 to 25.325.3.

Two other papers go looking for specific facts. Knowledge Neurons (Dai et al., 2022) uses a gradient-based attribution method to locate, in BERT, the hidden units of the perceptron that most influence whether the model completes a fact correctly, and most of them are in the top layers. Switching them off lowers the probability of the correct answer by 2929% on average, and doubling their activation raises it by 3131%. ROME (Rank-One Model Editing, Meng et al., 2022) goes further, in GPT-2 XL and GPT-J. First it corrupts the input of sentences such as "the Eiffel Tower is in" and restores the internal states one at a time to see which ones bring back the right answer: the decisive ones are the perceptrons of the middle layers, at the last token of the subject, with an effect about four times as strong as that of attention at the same token. Then it edits one of those perceptrons, treating its second matrix as a linear associative memory, with a rank-one update: a single outer product, and the model comes to believe something else about that subject, consistently, even when the question is phrased differently.

All of this comes with a caveat that rules out reading it as a table of facts with one row per neuron. Networks represent more features than they have units by overlapping them, a phenomenon known as superposition, which is why a single unit fires for things that have nothing to do with each other. That each of Geva's keys responds to several patterns is the same observation seen from the inside. The memory is real, but it is spread out.

Why it has this shape

With both readings in hand, the perceptron as the piece that computes and as a memory, we can review the design decisions one by one. Some have a reason behind them; others are just habit.

One hidden layer. It is the minimum that breaks linearity, and in theory one is enough: a perceptron with a sufficiently wide hidden layer can approximate any continuous function on a bounded domain. The XOR above needed one, not two. None of the models cited in this article puts more than one hidden layer in the perceptron; the improvements that stuck came from changing its width, its activation or how many there are, not its depth.

Wider than the model. In the memory reading, dffd_{\text{ff}} is the number of slots; in the computing reading, it is the number of new features that can be built from each row, and in more dimensions it is easier for whatever needs separating to end up separable by a plane. Both readings call for widening. Neither calls for a factor of four: 2,048/5122{,}048 / 512 is simply the number in the original paper, which doesn't justify it, and GPT-3 kept it at every size. The scaling laws study by Kaplan et al. (2020) measured how much it matters, and the answer is not much: with the number of parameters fixed, the loss depends only very weakly on dffd_{\text{ff}}, on the number of layers and on the number of heads, and varies by only a few per cent across a wide range of shapes. A model with 66 layers and dmodel=4,288d_{\text{model}} = 4{,}288 comes within 33% of one with 4848 layers and 1,6001{,}600. The four is a convention that works, not an optimum.

Back to dmodeld_{\text{model}}. This one is not a choice. The sum X+FFN(X)\mathbf{X} + \text{FFN}(\mathbf{X}) is element by element, so what comes out must have the same width as what went in. The perceptron widens to dffd_{\text{ff}} to do its work and narrows again to hand the result back.

Position-wise. Using the same matrices for every row does two things. It makes the number of parameters independent of TT, so the same model can read a sentence or a book. And it keeps the perceptron from competing with attention: if it could look at the other rows it would also have to learn to mix them, and the division of labour from the first section would disappear. The next section shows that this independence also has a very large practical consequence, because it is what allows each token to be routed on its own.

What has been tried in its place

Another non-linearity, and a gate

The first change was the activation. GPT and BERT replaced the ReLU with the GELU (Gaussian error linear unit, 2016), which multiplies the input by the probability that a standard normal variable falls below it, x Φ(x)x\,\Phi(x): a smoothed ReLU, differentiable at zero and with a small negative dip.

The change that stuck came in 2020. In GLU Variants Improve Transformer, Noam Shazeer (one of the Transformer's authors) tries perceptrons with a gate: two projections of the input instead of one, with one of them passed through an activation, and the two multiplied element by element before the second layer,

FFNSwiGLU(X)=(Swish(XW1)⊙XV)W2,\text{FFN}_{\text{SwiGLU}}(\mathbf{X}) = \left(\text{Swish}\left(\mathbf{X}\mathbf{W}_1\right) \odot \mathbf{X}\mathbf{V}\right)\mathbf{W}_2,

with Swish(z)=z σ(z)\text{Swish}(z) = z\,\sigma(z), σ\sigma the sigmoid and ⊙\odot the element-wise product. The variants change the gate's activation: none (bilinear), a sigmoid (GLU, for gated linear unit), a ReLU (ReGLU), a GELU (GEGLU) or a Swish (SwiGLU). There are three matrices instead of two, so to avoid adding parameters Shazeer shrinks dffd_{\text{ff}} by a factor of 2/32/3, from 3,0723{,}072 to 2,0482{,}048 in his model. These are the mean losses (the logarithm of the perplexity) that he measures on T5-base at the end of pre-training:

perceptronReLUGELUSwishGLUbilinearReGLUSwiGLUGEGLU
loss1.6771.6771.6791.6791.6831.6831.6631.6631.6481.6481.6451.6451.6361.6361.6331.633

Changing the activation without a gate moves nothing, and every gate improves things. The paper's conclusion is famous because it explains nothing: it puts the variants' success down, "as all else, to divine benevolence".

I will venture a reading the paper does not make, and it comes from the example of the four phrases. The sentiment was a product, n⋅pn \cdot p. The ReLU computed it with two units and a trick; a bilinear gate computes it with a single one, because it multiplies two projections of the row, and one can read nn while the other reads pp. What the gate adds is a direct way for one coordinate to modulate another, which is exactly the operation attention lacks. That the bilinear variant, with no activation of any kind, beats the ReLU fits that reading. It does not prove it.

Practice did not wait for the explanation. PaLM uses SwiGLU with dff=4 dmodeld_{\text{ff}} = 4\, d_{\text{model}}, paying for the extra parameters, and LLaMA uses it with 23⋅4 dmodel\tfrac{2}{3} \cdot 4\, d_{\text{model}}, Shazeer's adjustment. A good share of the open models that followed take the LLaMA route.

Many perceptrons, and one per token

A mixture of experts (MoE) puts several perceptrons in each layer, the experts, together with a small network, the router, that decides which ones each token uses. The parameters grow with the number of experts, but the computation per token grows only with the number actually used. Its history in language modelling is largely a list of where in the block it has been placed.

  • Shazeer et al. (2017) place it between two layers of an LSTM (long short-term memory) recurrent network, with up to 137137 billion parameters.
  • GShard (2020) replaces every other perceptron of a Transformer with experts, two experts per token, and reaches 600600 billion.
  • Switch Transformer (2021) replaces the perceptron and keeps a single expert per token; in pre-training it is up to seven times faster than the dense model with the same computation.
  • Mixtral (2024) swaps every perceptron for eight experts, two per token. DeepSeekMoE (2024) splits them into many small experts and reserves a few shared ones that every token goes through; its 16-billion-parameter model matches LLaMA 2 7B with 4040% of its computation.

In all of them, what gets multiplied is the perceptron. There is a structural reason for this, beyond the parameter count: since the perceptron works on each row separately, each token can go to a different expert without anything else changing. Attention does not lend itself to that split as easily, because its job is to mix rows.

A real memory

If the perceptron is a memory, you can try building one on purpose. Large Memory Layers with Product Keys (Lample et al., 2019) replaces the perceptron of some layers with a table of 5122512^2, about 262,000262{,}000 key-value slots, from which each token reads only the ones most similar to it, and it organises the keys as the product of two small sets so that finding them is cheap. A 1212-layer model with memory beats a 2424-layer one without, and is twice as fast at inference. Memory Layers at Scale (Berges et al., 2024) takes the idea up to 128128 billion memory parameters and a trillion training tokens. It beats dense models that use more than twice the computation, as well as mixtures of experts matched on both computation and parameters, and the gains are largest where the memory reading says they should be: on factual questions. In their 1.31.3-billion-parameter model, accuracy on Natural Questions, a benchmark of real questions put to Google's search engine, goes from 7.87.8% to 20.820.8%.

Removing it, sharing it or moving it

Removing it with nothing in its place has already come up twice: the ablation without persistent memory performs poorly, and attention-only models are studied because they are easier to understand, not because they are better. The other two tests say more.

Sharing it: One Wide Feedforward is All You Need (Pires et al., 2023) tests what happens with fewer perceptrons in English-to-German translation. Sharing a single one across the six encoder layers and dropping it from the decoder leaves the model with 6060% of the parameters and makes it 2222% faster at translating, at a cost of 0.30.3 BLEU points (bilingual evaluation understudy, the metric that counts the fragments in common with a reference translation), from 35.635.6 to 35.335.3. If that shared perceptron is widened until the original parameter count is restored, the score rises to 36.536.5: better than the starting model. Perceptrons in different layers repeat each other a good deal, at least in translation; what doesn't work is going without any.

Moving it: the sandwich Transformer (Press et al., 2020) tries reordering the sublayers without changing how many there are, and the best orderings put more attention at the bottom and more perceptron at the top. On WikiText-103 the perplexity drops from 18.6318.63 to 17.9617.96 at no cost in parameters or time, although it makes no difference in translation. PaLM takes another route and computes the two sublayers in parallel on the same normalised input, X+FFN(LayerNorm(X))+MultiHead(LayerNorm(X))\mathbf{X} + \text{FFN}(\text{LayerNorm}(\mathbf{X})) + \text{MultiHead}(\text{LayerNorm}(\mathbf{X})), which trains 1515% faster at large scale because the first multiplications of the two can be fused. It loses a little quality at 88 billion parameters and none at 6262.

The experiment in reverse

The most striking test does not touch the perceptron at all, but the other half. MetaFormer (Yu et al., 2022) takes a vision Transformer and replaces the attention with the simplest thing the authors could think of: averaging each patch of the image with its neighbours (pooling), with not a single parameter. It keeps the sum, the normalisation and the perceptron. The result, PoolFormer, reaches 82.182.1% on ImageNet, the classic image classification benchmark, 0.30.3 points more than DeiT-B, a reference vision Transformer, with 3535% fewer parameters. A few months earlier, MLP-Mixer had replaced the attention with another perceptron that mixes positions, and its authors concluded that neither convolutions nor attention are necessary.

This needs careful reading: it is vision, not language. In an image the neighbours say almost everything about a patch, whereas in a text the word that matters may be two pages away, which an average over neighbours cannot fetch and attention can. But the experiment shows what has been kept in every variant in this article, in vision and in language: the way positions are mixed has changed a great deal, and the perceptron that transforms each position has never been missing.

What remains

The Transformer has two halves because there are two jobs. One is deciding where to read from, which depends on the text and is what attention does. The other is doing something with what has been read: combining the coordinates of a single row in ways no weighted average can reach, as in the XOR of the four phrases, and bringing in what the model learnt that is not in the text. That is the perceptron, an attention whose keys and values are written into the weights. The residual connection, usually relegated to third place in explanations, is what keeps the stack from collapsing.

Almost everything about its shape is convention: the factor of four, the ReLU, having one per block. The variants that have survived have changed everything except one thing. They have given it gates, multiplied it into experts, turned it into a table of millions of slots, shared it and moved it around, and in all of them there is still, in every layer, a non-linear computation that works on each position separately.

So the next time a Transformer diagram draws the attention big and a little box labelled FFN on top, it is worth remembering the real budget. Attention gave the architecture its name. The perceptron holds two thirds of the parameters and most of the operations, and it is where the model keeps what it knows.