Saturated Transformers are Constant-Depth Threshold Circuits

William Merrill, Ashish Sabharwal, Noah A. Smith

Introduction

Opening the “black box” (Alishahi et al., 2020) of the representations within neural networks is an important step towards building systems with robust and interpretable behavior. In NLP, one part of this question is analyzing the languages networks can model, and the mechanisms they use to represent linguistic structure and dependencies.

One path toward this goal is via formal analysis of specific network architectures (Merrill, 2021); for example, recurrent neural networks (RNNs). Due to their autoregressive formulation, formal linguistic analysis of RNNs has often characterized their power by relating them to automata-theoretic classes of formal languages (Weiss et al., 2018; Peng et al., 2018; Merrill, 2019, inter alia). Recently, however, RNNs have largely been overtaken in NLP by a new class of models: transformers (Vaswani et al., 2017). Transformers are not autoregressive, and therefore less naturally resemble automata, posing challenges to characterizing their linguistic capacity or inductive biases in the same terms as RNNs. Instead, some recent work has related them to circuit complexity classes, a direction that we continue to pursue in this paper. Drawing on classical circuit lower bound results, Hao et al. (2022) and Hahn (2020) derive theoretical limitations of transformers with hard attention, meaning the attention distributions focus all probability mass on one index. Together, their results show that AC0\mathsf{AC}^{0}—the class of languages recognizable by constant-depth circuit families—upper bounds the formal languages hard-attention transformers can recognize.

However, hard attention is a strong assumption, making it unclear how these results transfer to practical transformers. For example, Bhattamishra et al. (2020) showed how transformers can solve synthetic counting tasks by using uniform attention patterns, which hard attention does not allow. Motivated by this potential disconnect between theory and practice, we aim to extend circuit-based analysis to transformers with saturated attention: a generalization of hard attention that has been argued to approximate attention patterns acquired through gradient descent (Merrill et al., 2021). Broadly speaking, saturated attention goes beyond hard attention in that it can “tie” across a subset of positions, rather than selecting just one position. The tied positions are then aggregated by averaging. Qualitatively, saturated attention heads can “count”: a capability observed in transformers in practice (Bhattamishra et al., 2020). Further, Merrill et al. (2021) show that transformer training dynamics lead attention heads in several pretrained transformers to approximate saturated attention. In summary, saturated attention strictly generalizes hard attention and should more closely reflect the attention patterns acquired in practical transformers.

Our main contributions are twofold. First, we show that saturated transformers can recognize languages outside AC0\mathsf{AC}^{0}. Then, as depicted in Table 1, we prove that transformers with floating point activations and saturated attention can only recognize formal languages in the circuit complexity class TC0\mathsf{TC}^{0}, constituting an upper bound for a more realistic model of transformers than past results with hard attention.

Roadmap

In § 3, we formally define our model of the transformer, including defining saturated attention in contrast to hard attention. § 4 introduces circuits in theoretical computer science and relevant complexity measures and classes for them.

In § 5, we first briefly analyze saturated transformers with rational values where the embedding, scoring, and activation functions are allowed to be any size-preserving function. We find such transformers to be universally powerful. We also observe that when the positional embeddings are computed in time linear in the sequence length, saturated rational-valued transformers are exactly as powerful as the complexity class of their activation functions, because the full input sequence can be pooled to a single position, and an activation function can be used as an oracle over the full input sequence. However, this setup relies on the use of unrealistic embedding functions. To move to a more realistic model of computation, we then focus on saturated transformers whose values are restricted to be floats, which have a coarser granularity and, thus, cannot encode the full input sequence into a single position.

Building on results of Pérez et al. (2019), we demonstrate in § 6 that saturated transformers with float activations transcend the theoretical limitations of hard-attention transformers. In particular, we will show that they can recognize the majority language, which lies outside AC0\mathsf{AC}^{0}. We experimentally validate that transformers can learn to recognize the majority language. Taken together, these results suggest that the very weak characterization of hard-attention transformers does not hold in practice for saturated or soft attention.

Finally, in § 8, we use the bounded size of transformer representations to upper bound that formal languages that can be recognized by a saturated transformers with floating-point values. In particular we show that they can be simulated by constant-depth threshold circuits, i.e., fall in TC0\mathsf{TC}^{0}. Informally, this suggests that moving from hard attention to saturated attention can be thought of as extending the implicit class of circuit gates available in the network to include threshold gates.

Our results make progress in the analysis of transformers by deriving upper bounds for a more realistic model of transformers than has previously been analyzed. RoBERTa, T5, and other pretrained transformers have been shown to be approximately saturated (Merrill et al., 2021), so our results imply TC0\mathsf{TC}^{0} may be a meaningful upper bound on the computation expressible within such networks. Our analysis also motivates future work further refining the characterization of saturated transformers, as well as comparing transformers with soft and saturated attention.

Definitions and Notation

We will often use ww to refer to a string over any generic alphabet Σ\Sigma, i.e., w∈Σ∗w\in\Sigma^{*}. Semantically, ww corresponds to the string a transformer receives as input. In contrast, we use xx and other symbols to refer to binary strings in {0,1}∗\{0,1\}^{*}. These binary strings will represent intermediate values within the transformer computation, rather than the raw input to the transformer.

Under our model, all values in the transformer are binary strings. In order to compute self attention and other operations over binary strings, we need to define datatypes describing the semantics of these binary strings as numbers. We will describe a semantics for binary strings as integers, as often comes up in circuit complexity. We then extend this to rational numbers and floats, which are necessary for representing the division operations that occur in attention heads within transformers.

We can interpret binary strings x∈{0,1}∗x\in\{0,1\}^{*} as unsigned integers in the standard way, i.e., the numerical value of x∈{0,1}nx\in\{0,1\}^{n} is

Rationals

To interpret r∈{0,1}∗r\in\{0,1\}^{*} as a rational number, we first view it as a sign bit ss along with a tuple of two unsigned integer substrings ⟨p,q⟩\langle p,q\rangle.Under the hood, we imagine the pair ⟨p,q⟩\langle p,q\rangle is encoded by padding pp and qq to the same length with ’s and interweaving bits from each. The numerical value represented by rr is

Floats

Size of Binary Strings

Under our model, integers, rationals, and floats are all abstractions built out of binary strings. For any x∈{0,1}∗x\in\{0,1\}^{*} (which can be interpreted semantically as an integer, float, or rational), we define its size ∣x∣\left\lvert x\right\rvert as the total length of xx measured in bits. We imagine a tuple ⟨p,q⟩\langle p,q\rangle is encoded by padding p,qp,q to the same length with leading ’s, and interleaving bits from each sequence. This means the size of a rational is 2max⁡(∣p∣,∣q∣)+12\max(\left\lvert p\right\rvert,\left\lvert q\right\rvert)+1. For example, the integer 22 takes 22 bits to specify, while the float 12\frac{1}{2} takes 55 bits (11 for the sign, 22 for the numerator, 22 for the denominator).

Size Preservation

We say that a function f:{0,1}∗→{0,1}∗f:\{0,1\}^{*}\to\{0,1\}^{*} is size-preserving iff there exist constants c,nc,n such that for all inputs xx with n≤∣x∣n\leq\left\lvert x\right\rvert, ∣f(x)∣≤c⋅∣x∣\left\lvert f(x)\right\rvert\leq c\cdot\left\lvert x\right\rvert. Let P\mathcal{P} be the set of size-preserving functions. While size-preserving functions are defined here over binary strings, they can be equivalently applied over integers, rationals, and floats, since these datatypes, as we have defined them, are just binary strings.

2 Transformers

We define the following general transformer model, which can be parameterized to use different types of attention patterns and whose internal functions (e.g., feedforward blocks) can be computed by different function classes.

Σ\Sigma is a finite input alphabet, i.e., the set of token types in a formal language.

Embedding Layer: v0,i=ϕ(wi,i)v_{0,i}=\phi(w_{i},i).

3 Attention Functions

Hard attention collapses the attention scores to a one-hot distribution with all mass concentrated at one index. Let M(a)={i∣ai=max⁡jaj}\mathcal{M}(a)=\{i\mid a_{i}=\max_{j}a_{j}\}.

In contrast, saturated attention spreads probability mass evenly across “tied” scores.

Merrill (2019) shows how this form of attention can be derived by taking a large-norm limit of the network weights; a derivation can be found there. Saturated attention reduces to hard attention when ∣M(a)∣=1\left\lvert\mathcal{M}(a)\right\rvert=1, and attends uniformly when ∣M(a)∣=n\left\lvert\mathcal{M}(a)\right\rvert=n. Both hard and uniform attention can be implemented with numerical stability, motivating weak saturated (or, “uniform”) attention:

Each head implements either hard attention (Def. 2) or the uniform pattern υ(a)j=1n\upsilon(a)_{j}=\frac{1}{n}.

In general, we will use “saturated attention” to refer to strong saturated attention and provide upper bounds for this setting. On the other hand, our lower bounds only use weak saturated attention, thereby showing that even weak saturated attention is more powerful than hard attention.

4 Language Recognition

Finally, we define language recognition for transformers.

This says the decision problem of recognizing L\mathcal{L} must be linearly separable using the first value in the last layer of the transformer. In practice, the first token in a transformer is often set to CLS, and its output can be passed to a classifier during finetuning (Devlin et al., 2019). This inspires Def. 5. There are other potential ways to define language recognition and generation for transformers (Hewitt et al., 2020; Yao et al., 2021), but they do not lead to meaningful differences for our purposes.

We note that size preservation is a weak condition to assume about the internal functions in practical transformers: since any linear-time-computable function is size-preserving, it is strictly weaker than assuming the internal functions can be computed in linear time. To further justify this condition, we explicitly show in § B that the component functions within transformers are size-preserving.

Circuit Complexity

Circuit complexity is a branch of computational complexity theory that studies circuit families as a model of computation.For more reference material on circuit complexity, we refer the reader to chapters 6 and 14 of Arora and Barak (2009) or chapters 1 and 2 of the Handbook of Theoretical Computer Science, Volume A (van Emde Boas, 1991; Johnson, 1991). Intuitively, circuits are useful for formally studying the types of computational problems that can be efficiently solved with parallelism, as the depth of a circuit corresponds to the runtime of a program on an idealized, fully parallel computer. We review background on circuits, circuit families, and relevant complexity measures and classes.

For a fixed nn, a circuit is a computation graph, where leaves correspond to input bits xix_{i} and their negations ¬xi\neg x_{i}, and the internal nodes are logic gates (typically ∧\wedge and ∨\vee), with one labeled as the output node. The gates can conventionally be taken to have either binary or unbounded fan-in. The circuit computes a function f:{0,1}n→{0,1}f:\{0,1\}^{n}\to\{0,1\} by substituting the input values into the leaf nodes, propagating the computation through the graph, and returning the value of the output node. Fig. 1 shows an example circuit that takes inputs of length 55, and returns whether they contain the bigram 1111.

Circuit Families

Circuit Complexity

Two important notions of complexity for a circuit are its size and depth. The size of a circuit is the number of gates. The depth is the longest path from an input node to the output node. For a circuit family, both quantities can be expressed as functions of the input size nn. A circuit complexity class is a set of formal languages that can be recognized by circuit families of a certain size, depth, and set of gates. In particular, we will discuss the classes AC0\mathsf{AC}^{0} and TC0\mathsf{TC}^{0}.

Intuitively, AC0\mathsf{AC}^{0} represents the class of problems that are highly parallelizable when the computational primitives are standard logic gates. In contrast, TC0\mathsf{TC}^{0} will also represent highly parallelizable computation, but when the gates are expanded to include threshold gates. For a bitstring x∈{0,1}∗x\in\{0,1\}^{*}, define the threshold gate θ≥k(x)\theta_{{\geq}k}(x) to return 11 iff ≥k\geq k bits in xx are 11, and equivalently for ≤k\leq k. For example, θ≥3(110011)=1\theta_{{\geq}3}(110011)=1.

Uniformity

The circuit classes defined above (and which we will use in this paper) are non-uniform, meaning circuits for different input sizes are not constrained to have any relation to each other. Non-uniform circuit families can recognize some uncomputable languages, such as the language of strings 1k1^{k} such that Turing machine kk does not halt on the null input (cf. Arora and Barak, 2009). In contrast, the uniform variants of circuit families are constrained such that a log-space Turing machine must output a string encoding of circuit CnC_{n} on the input string 1n1^{n}, forcing any language the circuit family can recognize to be computable. For these uniform classes (which we write with a u prefix), it is known that

where L\mathsf{L} and P\mathsf{P} denote the conventional complexity classes of log-space and polynomial-time decision problems. Thus, it is unknown whether uTC0\emph{u}\mathsf{TC}^{0} is restricted compared to general polynomial-time computation, but if we accept the common conjecture that one (if not all) of the above containments are strict, then uTC0\emph{u}\mathsf{TC}^{0} forms a restricted family of problems compared to P\mathsf{P}, which, intuitively, are more parallelizable than other problems in P\mathsf{P}.

Aren’t Transformers Universal?

We now begin our analysis of saturated transformers. Hao et al. (2022) and Hahn (2020) were able to give upper bounds on the power of hard attention without imposing any constraints on the embedding, scoring, and activation functions. The same will not be the case with saturated attention: any bounds on transformers will require leveraging some properties constraining their internal functions. One property we use will be size preservation. We will first show though that size preservation is not enough on its own: deriving a nontrivial upper bound will depend on subtle assumptions about the transformer’s datatype.

With rational values and size-preserving internal functions, we will show saturated transformers can recognize any formal language, i.e., the class ALL={L∣L⊆{0,1}∗}\mathsf{ALL}=\{\mathcal{L}\mid\mathcal{L}\subseteq\{0,1\}^{*}\}. Our construction resembles the universal approximation construction of Yun et al. (2020), which relies on the ability of the transformer to uniquely encode the full input string into a single value vector. After the full sequence is encoded locally into a single vector, the activation block can be used as a black box to recognize any language.

Since pi∼ilog⁡ip_{i}\sim i\log i for large ii by the prime number theorem (cf. Goldstein, 1973), the number of bits needed to represent ϕ(wi,i)\phi(w_{i},i) is

Since ii had size log⁡i\log i, this implies ϕ\phi is size-preserving.

Now, we define a single uniform attention head that sums across all ii, outputting ∑wi=11pi\sum_{w_{i}=1}\frac{1}{p_{i}}. The denominator qq of this sum is the product ∏i=1pi\prod_{i=1}p_{i}. Observe that wi=1w_{i}=1 if and only if pip_{i} divides qq. Thus, we can define a function ff that extracts the input sequence ww from qq by checking whether, for each ii, pip_{i} divides qq. We let gg be a function recognizing LL, and set f=g∘ff=g\circ f. The output of the transformer will now compute whether w∈Lw\in\mathcal{L}, since ff outputs an encoding of the original input sequence ww, and gg decides whether w∈Lw\in\mathcal{L}. Note that any function solving a decision problem is size-preserving, hence f∈Pf\in\mathcal{P}. ∎

Thm. 1 says that our transformer architecture parameterized with a rational datatype can recognize any formal language. But a construction of this form feels unrealistic for two reasons. First, it requires the embedding layer to implement an unconventional prime encoding scheme in the embedding layer. Second, we are using the activation layer as a black box to recognize any language—even uncomputable ones! On the other hand, the feedforward subnetworks used in practice in transformers cannot even implement all computable functions when the weights are fixed independent of the sequence length nn. We can get around both these issues by instead restricting the datatype to floats, which is the direction we will pursue in the remaining sections.It may also be possible to derive tighter bounds for rational-valued transformers by imposing stronger constraints on the internal functions. However, with floats, we will see that size preservation is sufficient to derive a tighter characterization of transformers’ power. We leave this alternate direction to future work.

In § C, we develop an alternate perspective on the universality of transformers, showing that, if the embedding function is allowed to be computed in time linear in the sequence length, then the transformer’s complexity is equivalent to its activation functions’ complexity.

If ϕ\phi can be any function computable in time linear in nn, and the scoring and activation functions can be computed in T(m)T(m) time on inputs of size mm with T(m)⩾mT(m)\geqslant m, then languages recognizable by the transformer are TIME(T(m))\mathsf{TIME}(T(m)).

§ C contains a formal statement and proof. For example, allowing polynomial-time functions inside the transformer implies that the transformer will recognize exactly the complexity class P\mathsf{P}. A major unrealism about this setup is the assumption that ϕ\phi can be an arbitrary function computable in time linear in nn, motivating our main results in a more constrained setting in § 8.

2 Discussion

We are not stating the results in this section as evidence that practical transformers are capable of universal or arbitrary polynomial computation. Rather, the unnaturalness of these constructions (specifically, the prime numbers based position encoding) motivates us to slightly constrain our model of the transformer in a realistic way: we will switch the datatype from rationals to floats, since even using only simple uniform attention, a model with rationals and unconstrained internal functions is universal. We will soon see that this realistic constraint prevents universal simulation, and in fact bounds the capacity of the saturated transformer within TC0\mathsf{TC}^{0}.

Beyond Hard Attention, with Floats

We now move to the setting of saturated transformers over floats. Hao et al. (2022) identified that hard-attention transformers can only recognize languages within AC0\mathsf{AC}^{0}. In contrast, saturated transformers over floats can recognize the “majority” language maj, which is known to lie outside AC0\mathsf{AC}^{0} (Furst et al., 1981). Pérez et al. (2019, Prop. 3.3) show how maj can be recognized by transformers. In Thm. 3, we offer a simpler construction that leverages only a single uniform attention head, as opposed to the model of transformers they were considering. Thus, this construction is achievable with saturated attention.

Let xi=ϕ(wi,i)x_{i}=\phi(w_{i},i) be a 11-hot encoding of wiw_{i}. For all i,ji,j, set s(xi,xj)=1s(x_{i},x_{j})=1, resulting in a single head attending everywhere:

Finally, set f(bi)f(b_{i}) to return whether #1(w)/n>#0(w)/n\#_{1}(w)/n>\#_{0}(w)/n, which, for n>0n>0, is true iff w∈\textscmajw\in\textsc{maj}. ∎

Notably, the construction in Thm. 3 is not just possible within our generalized transformer framework, but can also be implemented by the standard parameterization of ϕ,s\phi,s, and ff in real transformers (Vaswani et al., 2017). The uniform attention pattern can be implemented by setting all query and key attention parameters to . Then, we can use the affine transformation that aggregates the head outputs to compute the tuple:

This tuple is then passed through layer normalization (Ba et al., 2016), resulting in a new tuple ⟨t1,t2⟩\langle t_{1},t_{2}\rangle. Crucially, t1>t2t_{1}>t_{2} if and only if the same applies to the quantities in the original tuple. Thus, a linear classifier can decide whether t1>t2t_{1}>t_{2} to successfully recognize the language, as per Def. 5.

In Fig. 3, we show empirically that a 11-layer transformer can learn and generalize maj. This supports our argument that the theoretical limitations of hard-attention transformers do not apply to practical transformers. We train with three different types of positional encoding: none, meaning no positional information; learned, where each position gets a trainable embedding vector, and the sinusoidal scheme of Vaswani et al. (2017). The model with no positional embeddings generalizes the best, followed by the learned embeddings. It appears that while maj is in the capacity of the transformer, the standard sinusoidal positional embedding scheme provides the wrong inductive bias for learning it. This recalls the finding of Yao et al. (2021) that the choice of positional encodings seems to greatly impact the transformer’s ability to generalize formal language tasks to longer sequences.

Size of Transformer Values

Let v1,⋯ ,vnv_{1},\cdots,v_{n} be a sequence of floats, each with size at most zz. Then there exists cc such that ∑i=1nvi\sum_{i=1}^{n}v_{i} has size at most 4cz+2log⁡n+14cz+2\log n+1.

which, represented as an integer, has size:

2 Size of Transformer Values

We will now leverage Lem. 1 to show that the values are of bounded size in any transformer over floats with an elementwise-size-preserving attention function.

Note that saturated attention satisfies this definition. We are ready to prove a theorem bounding the size of the representations in transformers with elementwise-size-preserving attention.

Inductive Case

Cor. 4.1 follows because saturated attention is elementwise-size-preserving. Softmax attention, on the other hand, is not guaranteed to fulfill this property, since it requires computing the exponential function. This technical challenge prevents generalizing our technique to soft attention.

3 Discussion

Threshold Circuit Simulation

Any function f:{0,1}c→{0,1}df:\{0,1\}^{c}\to\{0,1\}^{d} can be computed by a boolean circuit of depth 33 and size at most (2c+c+1)d(2^{c}+c+1)d.

So that our results are self-contained, we reproduce a proof of this lemma in § D. Applying Lem. 2 to a size-preserving function with at most clog⁡nc\log n input bits immediately yields:

Any size-preserving function with at most clog⁡nc\log n input bits can be computed by a boolean circuit of depth 33 and polynomial size.

In other words, such functions can be computed with AC0\mathsf{AC}^{0} circuits. In addition, we will show that the sum of nn floats of size at most clog⁡nc\log n can be computed by TC0\mathsf{TC}^{0} circuits.

Let v1,⋯ ,vnv_{1},\cdots,v_{n} be a sequence of floats, each with size at most clog⁡nc\log n for some cc. Then the sum ∑i=1nvi\sum_{i=1}^{n}v_{i} is computable by a threshold circuit of constant depth and polynomial size.

We now construct a TC0\mathsf{TC}^{0} circuit that simulates a saturated transformer over floats.

For each nn, we construct a TC0\mathsf{TC}^{0} circuit that simulates a saturated transformer on inputs of size nn. We construct the circuit modularly, with one subcircuit for the attention mechanism, and another for the feedforward subnetwork.

Feedforward

We have simulated each transformer component with a TC0\mathsf{TC}^{0} subcircuit, completing the proof. ∎

1 Discussion

Recall that, over rationals, we found that size-preserving saturated transformers could recognize any language. In contrast, we have now shown that using floating-point representations places such transformers within TC0\mathsf{TC}^{0}. In this paper, we have only considered non-uniform AC0\mathsf{AC}^{0} and TC0\mathsf{TC}^{0}, as opposed to the uniform variants of these classes, which are more closely connected to familiar formal language classes like the regular and context-free languages (cf. Cojocaru, 2016; Mahajan, 2007). As transformers satisfy some intuitive notion of uniformity, an open question is whether saturated transformers also fall into uniform TC0\mathsf{TC}^{0}.

Conclusion

Compared to hard attention, saturated attention adds theoretical power to transformers. We showed that saturated attention lets transformers recognize languages outside AC0\mathsf{AC}^{0}, which is the upper bound with hard attention. Further, while saturated transformers with rational values and size-preserving internal functions can recognize any language, we characterize the limits of size-preserving saturated transformers with floats. Specifically, saturated transformers with float values fall in TC0\mathsf{TC}^{0}, a more powerful circuit class than AC0\mathsf{AC}^{0}. Thus, going from hard to saturated attention can be understood as augmenting the model with threshold gates. This illustrates one way that the circuit complexity paradigm characterizes the power of transformers. Going forward, there are many interesting open questions that circuit analysis can answer, such as comparing the power of saturated and soft attention, and refining existing upper bounds for transformers in terms of uniform circuit families.

Acknowledgments

Thanks to Yiding Hao, Dana Angluin, and Robert Frank for sharing an early draft of their work. We also appreciate helpful feedback from Dana Angluin, Matt Gardner, Yoav Goldberg, Michael Hahn, Kyle Richardson, and Roy Schwartz.

Appendix A Float Division

Let // be truncated division between integers. We divide a float by an integer pp by defining an approximate multiplicative inverse p−1p^{-1}. The numerator is 2∣p∣/p2^{\left\lvert p\right\rvert}/p and the denominator is 2∣p∣2^{\left\lvert p\right\rvert}. For division by a float p,qp,q, we simply apply the integer approach and then multiply by qq. This yields numerator 2∣p∣/p⋅q2^{\left\lvert p\right\rvert}/p\cdot q and denominator 2∣p∣2^{\left\lvert p\right\rvert}.

The fact that float division is defined in terms of integer multiplication and division implies it is size-preserving and can be simulated in TC0\mathsf{TC}^{0}, which we use in § 8.

Appendix B Justifying Size Preservation

Division can be analyzed in terms of the approximate multiplicative inverse (§ A).The exact multiplicative inverse ⟨p,q⟩↦⟨q,p⟩\langle p,q\rangle\mapsto\langle q,p\rangle over unconstrained rationals is also size-preserving. Thus, neural networks are size preserving over both floats and rationals. Its numerator has size ≤∣p∣+1+∣q∣≤2(∣p∣+∣q∣)\leq\left\lvert p\right\rvert+1+\left\lvert q\right\rvert\leq 2(\left\lvert p\right\rvert+\left\lvert q\right\rvert) for large enough input size. The denominator has size ≤∣p∣+1≤2∣p∣\leq\left\lvert p\right\rvert+1\leq 2\left\lvert p\right\rvert for large enough input size.

Size preservation is trivially satisfied for ReLU, which cannot expand the size of the input.

To make layer norm work, we just need to analyze square root, which we will define in a truncated fashion over integers. The square root of a rational, then, simple takes the square root of pp and qq. We have that ∣p∣≤∣p∣\left\lvert\sqrt{p}\right\rvert\leq\left\lvert p\right\rvert and analogously for qq.

Appendix C Resource-Bounded Transformers

Each of these components is computable in time linear in nn. Define three heads b1,ib_{1,i}, b2,ib_{2,i}, b3,ib_{3,i}. Without loss of generality, consider bh,ib_{h,i} to act on ϕ(wi,i)h\phi(w_{i},i)_{h} alone, rather than the full embeding vector. b1,ib_{1,i} is defined as a uniform head, while b2,ib_{2,i} and b3,ib_{3,i} are computed with sh(vi,vj)=vjs_{h}(v_{i},v_{j})=v_{j}. Thus,

Appendix D Proof from Hao et al. (2022)

The proof for Lem. 2 largely follows the proof of a core lemma of Hao et al. (2022). We reproduce a slightly adapted version of their proof here, since their manuscript is not yet publicly available, and we wish for our paper to be self-contained.

Any function f:{0,1}c→{0,1}df:\{0,1\}^{c}\to\{0,1\}^{d} can be computed by a boolean circuit of depth 33 and size at most d(2c+c+1)d(2^{c}+c+1).

The idea of the proof is to define dd subcircuits of size at most 2c+c+12^{c}+c+1 that compute the dd output bits of ff in parallel. We will build a circuit that computes each output bit of ff according to its representation in disjunctive normal form (DNF). We define a first layer of the circuit that computes the negation of each input, which takes cc gates. The second layer then computes the value of each DNF term by computing a conjunction (∧\wedge gate) over the corresponding literals or negated literals. Note that a formula of cc variables has at most 2c2^{c} DNF terms. Finally, the third layer of the circuit computes a disjunction (∨\vee gate) over the values of all terms, yielding the output of ff, and adding a single gate. In summary, we have shown how to compute each output bit with a circuit of size at most 2c+c+12^{c}+c+1, which implies the full function ff can be computed by a circuit of size at most d(2c+c+1)d(2^{c}+c+1). ∎

References