Fundamental Limitations on Subquadratic Alternatives to Transformers

4 Representational strength of transformers

Lemma 203 Continuous threshold OR, Lemma D.1

For \(a{\lt}b\) there is a continuous function \(f:\mathbb {R}^\ell \to \mathbb {R}\) such that \(f(x)=1\) if some coordinate \(x[i]\geq b\), and \(f(x)=0\) if all coordinates satisfy \(x[i]{\lt}a\).

Proof

Define

\[ g(y)= \begin{cases} 1, & y\geq b,\\ (y-a)/(b-a), & a\leq y{\lt}b,\\ 0, & y{\lt}a. \end{cases} \]

This piecewise-linear function is continuous. Set \(f(x)=1-\prod _{i=1}^{\ell }(1-g(x[i]))\). If some \(x[i]\geq b\), then one factor is zero and \(f(x)=1\). If every \(x[i]{\lt}a\), every \(g(x[i])\) is zero and \(f(x)=0\).

Lemma 204 Finite row prescriptions can be implemented by an MLP

Let \(S\subset \mathbb {R}^a\) be a finite set of valid row inputs, and assign a target vector \(y_s\in \mathbb {R}^b\) to every \(s\in S\). There exists a continuous function \(f:\mathbb {R}^a\to \mathbb {R}^b\) such that \(f(s)=y_s\) for every \(s\in S\).

Proof

Because \(S\) is finite, choose pairwise disjoint open balls centered at the points of \(S\). On the ball around \(s\), use a continuous bump function that is \(1\) at \(s\) and \(0\) on the boundary, multiply it by \(y_s\), and set the function to \(0\) outside the union of the balls. The balls are disjoint, so these local definitions agree on overlaps, and the resulting piecewise function is continuous and has the prescribed values on \(S\).

Lemma 205 MLP appending an end token, Lemma D.2

Fix an integer threshold \(1\leq t\leq \ell \). Let the raw sentinel row be

\[ s_t=(0,\ldots ,0,t+1)\in \mathbb {R}^\ell , \]

and let the target attention-space sentinel row be

\[ \tau _t=(0,\ldots ,0,t+1)\in \mathbb {R}^{\ell +1}, \]

with \(\ell \) leading zero coordinates and last coordinate \(t+1\). On the finite valid row set consisting of all binary rows in \(\{ 0,1\} ^{\ell }\) and the sentinel row \(s_t\), there exists a continuous \(f:\mathbb {R}^\ell \to \mathbb {R}^{\ell +1}\) such that

\[ f(x)=(x,1)\quad \text{for every }x\in \{ 0,1\} ^{\ell }, \qquad f(s_t)=\tau _t. \]
Proof

Since \(t\geq 1\), the sentinel row has last coordinate at least \(2\) and is not a binary row. The valid row set is therefore finite with no conflicting prescriptions. Assign \((x,1)\) to each binary row \(x\) and assign \(\tau _t\) to \(s_t\), then apply Lemma 204.

Lemma 206 MLP normalizing and appending an end token, Lemma D.3

Fix a threshold \(t\in [0,1]\). Let the raw sentinel row be

\[ s_t=(0,\ldots ,0,t+2)\in \mathbb {R}^\ell , \]

and let the target attention-space sentinel row be

\[ \tau _t=(0,\ldots ,0,t+1)\in \mathbb {R}^{\ell +1}, \]

with \(\ell \) leading zero coordinates and last coordinate \(t+1\). On the finite set consisting of all nonzero binary document rows and \(s_t\), there exists a continuous \(f:\mathbb {R}^\ell \to \mathbb {R}^{\ell +1}\) such that

\[ f(x)=(x/\| x\| ,1)\quad \text{for every nonzero }x\in \{ 0,1\} ^{\ell }, \]

and

\[ f(s_t)=\tau _t. \]
Proof

The set of valid rows is finite: it contains the \(2^\ell -1\) nonzero binary vectors and the one special vector \(s_t\). Since \(t+2{\gt}1\), the sentinel row is not binary, so there is no conflict with the document-row prescriptions. Prescribe the displayed value for each valid row and apply Lemma 204. The document-row prescription uses Euclidean normalization, so the inner product of two prescribed document rows is exactly their cosine similarity.

Lemma 207 Low-rank attention score matrices can realize scalar identities

If \(m\geq d_{\rm in}\), then for any scalar \(\lambda \) there exist \(Q,K\in \mathbb {R}^{d_{\rm in}\times m}\) with \(QK^\top =\lambda I_{d_{\rm in}}\).

Proof

Put \(\lambda \) on the first \(d_{\rm in}\) diagonal entries of \(Q\) and put \(1\) on the corresponding diagonal entries of \(K\), with all other entries zero. Then the matrix product has diagonal entries \(\lambda \) and off-diagonal entries zero.

In the OV construction of Theorem 211, with raw sentinel row \(s=0^\ell \), augmented attention input \(\operatorname {Aug}_s(E)\in \mathbb {R}^{(n+1)\times \ell }\), \(QK^\top =-\lambda I_\ell \) for a concrete scale \(\lambda {\gt}0\), and \(V\) the all-one column, the \(i\)th attention output for every document row \(1\leq i\leq n\) equals

\[ \frac{\sum _{j=1}^{n}\exp (-\lambda \left\langle v_i,v_j\right\rangle )\| v_j\| _1}{\sum _{k=1}^{n}\exp (-\lambda \left\langle v_i,v_k\right\rangle )+1}. \]
Proof

The attention score from row \(i\) to row \(j\) is \(-\lambda \left\langle v_i,v_j\right\rangle \), so exponentiating it inside softmax gives \(\exp (-\lambda \left\langle v_i,v_j\right\rangle )\). Definition 40 makes the last row exactly \(0^\ell \), so it contributes score \(0\) and hence denominator contribution \(1\). Multiplication by the all-one value column returns \(\| v_j\| _1\) for document rows and \(0\) for the sentinel row, giving the displayed formula for the first \(n\) rows.

Lemma 209 OV yes-instance attention gap

If the OV instance has an orthogonal pair, then some attention output entry in the OV construction is at least \(1/(n+1)\).

Proof

Let \(\left\langle v_{i^*},v_{j^*}\right\rangle =0\). The numerator of row \(i^*\) contains the term \(\exp (0)\| v_{j^*}\| _1\). After the preprocessing used in the proof, zero vectors have already been handled, so \(\| v_{j^*}\| _1\geq 1\). The denominator is at most \(n+1\) because every factor \(\exp (-\lambda \left\langle v_{i^*},v_k\right\rangle )\) is at most \(1\). Therefore the row output is at least \(1/(n+1)\).

Lemma 210 OV no-instance attention gap

If the OV instance has no orthogonal pair, then every attention output entry in the OV construction is at most \(n\ell \exp (-\lambda )\). In particular, if \(\lambda \) is chosen so that \(n\ell \exp (-\lambda ){\lt}1/(2(n+1))\), then every no-instance output entry is below \(1/(2(n+1))\).

Proof

In a no instance, every document pair has inner product at least \(1\). Hence every numerator weight is at most \(\exp (-\lambda )\), and every \(\| v_j\| _1\) is at most \(\ell \). The numerator is at most \(n\ell \exp (-\lambda )\), while the denominator is at least \(1\) because of the zero sentinel row. The final displayed implication is exactly the assumed upper bound on \(n\ell \exp (-\lambda )\).

Theorem 211 A single attention unit solves OV, Theorem 4.1

An attention unit with input and output MLPs and parameters \(d=\ell \), \(d_{\rm in}=\ell \), \(d_{\rm out}=1\), \(m\geq \ell +1\), and one fixed raw sentinel row \(0^\ell \) solves \(\mathrm{OV}_{n,\ell }\) in the sentinel-augmented sense of Definition 41.

Proof

Evaluate the transformer on \(\operatorname {Aug}_{0^\ell }(E)\), whose last row is the fixed zero sentinel and whose first \(n\) rows are exactly the OV instance vectors. Choose \(Q,K\) so that \(QK^\top =-\lambda I_\ell \) for a scale \(\lambda {\gt}0\) satisfying \(n\ell \exp (-\lambda ){\lt}1/(2(n+1))\), and choose \(V\) to be the all-one column. Lemma 208 gives the row outputs. By Lemma 209, yes instances produce an entry at least \(1/(n+1)\); by Lemma 210, no instances produce only entries below \(1/(2(n+1))\). The output MLP from Lemma 203, with \(a=1/(2(n+1))\) and \(b=1/(n+1)\), separates these two ranges and outputs \(1\) or \(0\) accordingly.

For \(1\leq t\leq \ell \), evaluate the transformer on \(\operatorname {Aug}_{s_t}(E)\), where \(s_t=(0,\ldots ,0,t+1)\in \mathbb {R}^\ell \) is the raw sentinel row from Lemma 205. After the input MLP, the first \(n\) rows are \(x_i=(v_i,1)\) and the last row is \(\tau _t=(0,\ldots ,0,t+1)\in \mathbb {R}^{\ell +1}\). With the attention parameters of Appendix C, choose a scale \(\lambda {\gt}0\) with \(n\ell \exp (-\lambda ){\lt}1/(2(n+1))\). The attention output has a gap of at least \(1/(n+1)\) versus below \(1/(2(n+1))\) between yes and no instances of \(\mathrm{Max\mbox{-}IP}_{n,\ell ,t}\) and \(\mathrm{Min\mbox{-}IP}_{n,\ell ,t}\).

Proof

Lemma 205 maps each binary document row to \(x_i=(v_i,1)\) and maps the fixed raw sentinel row to \(\tau _t=(0,\ldots ,0,t+1)\). Definition 40 ensures that the sentinel is present as the unique \((n+1)\)st row and is not a candidate pair member.

For Max-IP, choose \(QK^\top =\lambda I\) and value vector \((1,\ldots ,1,0)\). If some document pair has inner product at least \(t\), then the shifted score \(\left\langle x_i,x_j\right\rangle \) is at least \(t+1\), matching or exceeding the sentinel score \(\left\langle x_i,\tau _t\right\rangle =t+1\). The best document contribution in that row therefore carries at least a \(1/(n+1)\) softmax fraction and has value at least \(1\). If all document pairs have inner product at most \(t-1\), every document score is lower than the sentinel by at least one, hence by a factor \(\exp (\lambda )\) after exponentiation. The total document value is at most \(n\ell \exp (-\lambda )\), which is below \(1/(2(n+1))\) by the chosen scale.

For Min-IP, choose \(QK^\top =-\lambda I\) and use the same positive target sentinel row \(\tau _t\). A yes witness with \(\left\langle v_i,v_j\right\rangle \leq t\) has shifted score at most \(t+1\), so after negation its exponent is at least the sentinel exponent; a no instance has all shifted document scores at least \(t+2\), so every document exponent is smaller than the sentinel exponent by a factor \(\exp (\lambda )\). The same numerator bound gives the stated gap.

Theorem 213 A single attention unit solves Max-IP and Min-IP decisions, Theorem C.1

An attention unit with input and output MLPs and parameters \(d=\ell \), \(d_{\rm in}=\ell +1\), \(d_{\rm out}=1\), \(m\geq \ell +1\), and the raw sentinel row \(s_t=(0,\ldots ,0,t+1)\in \mathbb {R}^\ell \) solves \(\mathrm{Max\mbox{-}IP}_{n,\ell ,t}\) and \(\mathrm{Min\mbox{-}IP}_{n,\ell ,t}\) for \(1\leq t\leq \ell \) in the sentinel-augmented sense of Definition 41.

Proof

Lemma 212 constructs attention parameters and input MLPs that separate yes and no instances by the numerical gap \(1/(2(n+1)){\lt}1/(n+1)\). Applying the continuous threshold OR of Lemma 203 to the attention outputs gives the required decision value.

Lemma 214 Finite cosine thresholds have a positive no-instance gap

Fix \(n,\ell \) and \(t\in [0,1]\). Among nonzero binary vectors in \(\{ 0,1\} ^{\ell }\), the set of possible cosine similarities is finite. Therefore, for \(\mathrm{MSD}_{n,\ell ,t}\), either a pair has similarity at least \(t\), or there is a number \(\Delta {\gt}0\) such that every pair has similarity at most \(t-\Delta \). Similarly, for \(\mathrm{LSD}_{n,\ell ,t}\), either a pair has similarity at most \(t\), or there is a number \(\Delta {\gt}0\) such that every pair has similarity at least \(t+\Delta \).

Proof

There are only finitely many nonzero binary vectors of length \(\ell \), hence only finitely many pairwise cosine-similarity values. If no value lies on the accepting side of the threshold, the finite set of distances from the remaining values to \(t\) has a positive minimum. This minimum is the desired \(\Delta \) for the corresponding maximization or minimization decision.

Lemma 215 Normalized document rows realize cosine scores

For nonzero binary document embeddings \(v,w\), if the input MLP maps document rows to \(x_v=(v/\| v\| ,1)\) and \(x_w=(w/\| w\| ,1)\), then

\[ \left\langle x_v,x_w\right\rangle =1+\frac{\left\langle v,w\right\rangle }{\| v\| \| w\| }. \]

If the raw sentinel row is mapped to the target attention-space row \(\tau _t=(0,\ldots ,0,t+1)\) with \(\ell \) leading zeros, then \(\left\langle x_v,\tau _t\right\rangle =t+1\).

Proof

Expanding the concatenated inner product gives \(\left\langle v/\| v\| ,w/\| w\| \right\rangle +1\), which is \(\left\langle v,w\right\rangle /(\| v\| \| w\| )+1\). The target sentinel has zeros in the document coordinates and last coordinate \(t+1\), while \(x_v\) has last coordinate \(1\), so their inner product is \(t+1\).

For fixed \(n,\ell ,t\), evaluate the transformer on \(\operatorname {Aug}_{s_t}(E)\), where \(s_t=(0,\ldots ,0,t+2)\in \mathbb {R}^\ell \) is the raw sentinel row from Lemma 206. The input MLP maps the first \(n\) nonzero binary rows to \((v_i/\| v_i\| ,1)\) and maps the sentinel to \(\tau _t=(0,\ldots ,0,t+1)\in \mathbb {R}^{\ell +1}\). Choose \(Q,K\) so that \(QK^\top =\lambda I_{\ell +1}\) for a sufficiently large \(\lambda {\gt}0\), and choose the value vector \((1,\ldots ,1,0)\). Then yes instances of \(\mathrm{MSD}_{n,\ell ,t}\) produce some attention output at least \(1/(n+1)\), while no instances produce all attention outputs below \(1/(2(n+1))\).

Proof

Lemma 206 gives exactly the displayed row images, and Definition 40 places the raw sentinel as the unique last row. In a yes instance choose a row \(i\) with some witness row \(j\) whose cosine similarity is at least \(t\), and then choose a document row \(j'\) maximizing the attention score against row \(i\). Its score is at least the sentinel score \(t+1\) by Lemma 215. The value of a nonzero normalized binary row under \((1,\ldots ,1,0)\) is positive and at least \(1\). Since the chosen document row has maximal score among the \(n+1\) rows up to ties with the sentinel, its softmax mass is at least \(1/(n+1)\), so the output is at least \(1/(n+1)\).

In a no instance Lemma 214 gives \(\Delta {\gt}0\) such that every document score is at most \(t+1-\Delta \), whereas the target sentinel score is \(t+1\). The numerator is at most \(n\sqrt{\ell }\exp (\lambda (t+1-\Delta ))\), and the denominator is at least \(\exp (\lambda (t+1))\). Choosing \(\lambda \) so that \(n\sqrt{\ell }\exp (-\lambda \Delta ){\lt}1/(2(n+1))\) gives the claimed no-case bound.

For fixed \(n,\ell ,t\), use the same augmented raw sentinel row \(s_t=(0,\ldots ,0,t+2)\), normalized document rows, and positive target sentinel row \(\tau _t=(0,\ldots ,0,t+1)\) as in Lemma 216. Choose \(Q,K\) so that \(QK^\top =-\lambda I_{\ell +1}\) for a sufficiently large \(\lambda {\gt}0\), and choose the value vector \((1,\ldots ,1,0)\). Then yes instances of \(\mathrm{LSD}_{n,\ell ,t}\) produce some attention output at least \(1/(n+1)\), while no instances produce all attention outputs below \(1/(2(n+1))\).

Proof

Multiplication by \(-\lambda I_{\ell +1}\) reverses the score order. In a yes instance a witness pair has cosine similarity at most \(t\), so its negated document score is at least the negated target-sentinel score. Choosing the best such document score in the row gives softmax mass at least \(1/(n+1)\) and value at least \(1\), as in Lemma 216.

In a no instance every cosine similarity is at least \(t+\Delta \) for the positive gap from Lemma 214. Thus every negated document score is at most the negated target-sentinel score minus \(\lambda \Delta \). Taking \(\lambda \) large enough makes the total document contribution smaller than \(1/(2(n+1))\), exactly as in the MSD no-case.

Theorem 218 A single attention unit solves MSD and LSD decisions, Theorem C.2

An attention unit with input and output MLPs and parameters \(d=\ell \), \(d_{\rm in}=\ell +1\), \(d_{\rm out}=1\), \(m\geq \ell +1\), and the raw sentinel row \(s_t=(0,\ldots ,0,t+2)\in \mathbb {R}^\ell \) solves \(\mathrm{MSD}_{n,\ell ,t}\) and \(\mathrm{LSD}_{n,\ell ,t}\) for every \(t\in [0,1]\) in the sentinel-augmented sense of Definition 41.

Proof

For \(t=0\), MSD is trivial on instances with at least two nonzero document rows, so the output MLP may constantly output \(1\). For all other MSD cases, Lemma 216 constructs attention parameters whose outputs have a gap between yes and no instances. For LSD, including the endpoint \(t=0\), Lemma 217 gives the analogous gap with the sign of \(QK^\top \) reversed. Applying the continuous threshold OR of Lemma 203 to the resulting attention-output vector gives the scalar decision value.

Theorem 219 Introductory transformer representation theorem, Theorem 1.4

A single unit of standard attention with input and output MLPs and embedding dimension \(\ell +1\) solves \(\mathrm{OV}_{n,\ell }\), \(\mathrm{MSD}_{n,\ell ,t}\), and \(\mathrm{LSD}_{n,\ell ,t}\) for every \(0\leq t\leq 1\) under the explicit sentinel-augmented input encoding of Definition 41.

Proof

The OV part is Theorem 211. The MSD and LSD decision parts are Theorem 218. These constructions use one attention unit plus simple continuous MLPs, with the fixed sentinel row supplied by the input encoding rather than counted as a problem-instance document row.