Combiner: Full Attention Transformer with Sparse Computation Cost
Year: 2021

Abstract:
Transformers provide a class of expressive architectures that are extremely effective for sequence modeling. However, the key limitation of transformers is their quadratic memory and time complexity O(L) with respect to the sequence length in attention layers, which restricts application in extremely long sequences. Most existing approaches leverage sparsity or low-rank assumptions in the attention matrix to reduce cost, but sacrifice expressiveness. Instead, we propose Combiner, which provides full attention capability in each attention head while maintaining low computation and memory complexity. The key idea is to treat the self-attention mechanism as a conditional expectation over embeddings at each location, and approximate the conditional distribution with a structured factorization. Each location can attend to all other locations, either via direct attention, or through indirect attention to abstractions, which are again conditional expectations of embeddings from corresponding local regions. We show that most sparse attention patterns used in existing sparse transformers are able to inspire the design of such factorization for full attention, resulting in the same sub-quadratic cost (O(L log(L)) or O(L √ L)). Combiner is a drop-in replacement for attention layers in existing transformers and can be easily implemented in common frameworks. An experimental evaluation on both autoregressive and bidirectional sequence tasks demonstrates the effectiveness of this approach, yielding state-of-the-art results on several image and text modeling tasks.

text: √ L)). Combiner is a drop-in replacement for attention layers in existing transformers and can be easily implemented in common frameworks. An experimental evaluation on both autoregressive and bidirectional sequence tasks demonstrates the effectiveness of this approach, yielding state-of-the-art results on several image and text modeling tasks.

heading: 1 Introduction
text: The Transformer [1] is a powerful neural network architecture that has demonstrated state-of-the-art performance in machine translation [2] and many other natural language processing (NLP) tasks via pretraining, using either unidirectional language modeling [3] or bidirectional language modeling [4–8]. It has also achieved excellent results in other domains like image recognition [9], code understanding [10], speech recognition [11], protein [12], music [13] and image [14] generative modeling. The core component of Transformer is the attention mechanism, which computes dependencies between all pairs of positions in a sequence. However, for a sequence of length L, the expressiveness of pairwise attention comes at a quadratic cost O(L2) in both time and memory consumption. This makes the vanilla Transformer [1] prohibitive for applications that involve long sequences, including high-resolution images, protein sequences, or raw speech signals [15], where the sequence length L is often larger than 10, 000 [14].
Recently, there have been several attempts to scale up attention to long sequences. A popular class of methods sparsifies the attention matrix with different sparsity patterns, including local
∗indicates equal contribution. The work was completed during HR’s internship at Google Brain.
35th Conference on Neural Information Processing Systems (NeurIPS 2021).
window [16, 17], local+stride [14], log-sparse [18], axial [19, 20], or learnable patterns through hashing [21] or clustering [22]. Sparse attention enjoys sub-quadratic cost, but is lossy in capturing all-pair relationships. Generally, sparse attention requires more layers [14, 20, 23] to achieve full autoregressive or bidirectional dependencies (or receptive fields [20]) for each location in a long sequence.
Alternatively, another line of research has tried to achieve scalability with an explicit low-rank assumption [24, 25] on the attention matrix or by using explicit feature maps of some kernels [26]. However these explicit low dimensional approximations might be too restricted for the potentially full rank attention matrix, which uses exponential kernels that are effectively infinite dimensional [27]. The Performer [28] is among the first works that attempts to approximate regular full-rank attention with the random feature trick [29]. However such random-feature based approaches [30] require many more bases to better approximate the exponential kernel [27], and empirically we found it produces inferior results in some sequence modeling tasks, such as density estimation.
In this paper we propose Combiner, a drop-in replacement for the vanilla quadratic attention mechanism with sub-quadratic computation and memory cost. Combiner still achieves full attention capability within each head of Multi-Head Attention, unlike approaches that adopt sparse or low-rank approximations. As we will discuss, the standard attention computed at each location can be seen as the conditional expectation of the value embeddings at all feasible locations given the current location. Based on such an understanding, Combiner explicitly approximates the conditional distribution in through a structured factorization of the probability space. Specifically, given a location x, the probability of attending to location y can be either directly calculated via the query vector of x and key vector of y, or indirectly through a local abstraction where x first attends to the key vector that represents a group of locations containing y, and multiplying the probability of choosing y within that group. We refer to this model as Combiner since the conditional distributions in attention become a combination between several local attentions and direct attentions. This structured decomposition enables Combiner to take existing sparse attention patterns and convert them into corresponding design choices for probability factorizations that achieve full attention. As shown in Figure 1, Combiner achieves full attention with the same asymptotic complexity as sparse variants. Combiner can be easily implemented in most existing deep learning frameworks without the need for specialized hardware implementation, and is GPU/TPU friendly. In fact, both the fixed and learnable sparse attention patterns from many existing Transformer variants [14, 18, 20, 22] can be enhanced with such structured factorizations, with the same order of time or memory cost.
We validate Combiner on both autoregressive and bidirectional sequence modeling tasks over a variety of domains including text and images. We show that Combiner can achieve better perplexity and accuracy when using the same transformer architectures while being much faster in terms of runtime, and achieves state of the art performance on density estimation on standard datasets CIFAR-10 (2.77 bits/dim) and ImageNet-64 (3.42 bits/dim), as well as the Long-Range Arena [31]. The implementation of Combiner can be found at https://github.com/google-research/googleresearch/tree/master/combiner.

heading: 2 Attention as Conditional Expectation
text: In this section, we revisit the formulation of the standard Transformer [1] from the perspective of conditional expectation, which inspires the derivation of Combiner.
Without loss of generality, we use a single sequence in the self-attention scenario. Given a sequence of L embeddings X = [x1, x2, . . . , xL], where X ∈ RL×d and each embedding xi ∈ Rd is a d-dimensional vector, the core component of Transformer is the multi-head attention, where each head h is a scaled dot-product attention:
Ah(X) = softmax ( Qh√ d K⊤h ) Vh, { Qh = XW Q h ,Kh = XW K h , Vh = XW V h } ∈ RL×d, (1)
and the attention vector from each head Ah(X) is concatenated and projected: MultiHeadAttn(X) = [A1(X), A2(X), . . . , AH(X)]W o,W o ∈ RHd×d. (2) Here H is the total number of heads per Transformer layer. In this paper, we focus on how to approximate full attention within each head of multi-head attention. For ease of notation, we drop the head index h whenever possible, and use lower-case letters xi, qi, ki, vi ∈ Rd to denote rows in
X,Q,K, V respectively, which corresponds to a location i in the original sequence of length L. We use [n] to denote the set of positive integers {1, 2, . . . , n}. For a position i ∈ [L], the attention formulation (1) can be viewed as conditional expectation of rows in V . Specifically, since softmax outputs a probability distribution, we can rewrite (1) as
A(xi) = Ep(j|i) [vj ] , p(j|i) = 1
Z (xi) exp ( qi√ d k⊤j ) , (3)
where p(j|i) denotes the conditional probability at position j given the token at position i and the partition function Z (xi) = ∑ j∈Ωi exp ( qi√ d k⊤j ) over support Ωi. The support Ωi of p (j|i) defines the set of valid locations that the i-th token can attend to. For instance, the support set in autoregressive language modeling (LM) consists of all previous tokens, i.e., ΩLMi = [i]
2; in masked language modeling (MLM) the support consists of all tokens in the sequence, i.e., ΩMLMi = [L]. That is, ΩLMi and Ω MLM i represent the full attention capability respectively in the LM and MLM setting.

heading: 3 Combiner: Full Attention via Structured Conditional Expectation
text: The complexity of p (j|i) is the bottleneck of the computation for A (xi). Generally, in existing sparse transformers, the support of p (j|i) is sparsified to reduce the computation and memory complexity, e.g., ΩSparsei ⊊ ΩLMi for LM and Ω Sparse i ⊊ ΩMLMi for MLM, but this can lead to either reduced capacity or limited applicability. We defer detailed discussion of the full capacity of the model to Appendix A. In this section we introduce the Combiner, which achieves ΩCombineri = Ω LM i for LM and ΩCombineri = Ω MLM i for MLM, while still maintaining sub-quadratic computation and memory cost. Below we denote Ωi as the support for full attention if there is no ambiguity or need to distinguish between LM or MLM. We introduce the main design framework in Section 3.1 and possible parameterizations in Section 3.2. Then in Section 3.3 we analyze the trade-off of Combiner.

heading: 3.1 Local Factorization for Conditional Expectation
text: The main idea of Combiner is to exploit a hierarchical structure for conditional probability modeling in (3), which provides the opportunity for reducing computation complexity while maintaining the
2Following the conventional implementation, the input sequence will be “right-shifted” so that the position i can attent to itself in LM setting.
same support. Specifically, we introduce support variables Ωri , for r = 0, . . . , ni and i ∈ [L]. The support variables are disjoint, i.e., Ωri ∩ Ωsi = ∅,∀r ̸= s, and ∪ ni r=0Ω r i = Ωi. Then we can factorize p(j|i) as
p(j|i) = ni∑ r=0 p(j,Ωri |i) = ni∑ r=0 p(j|Ωri , i)p(Ωri |i) = p(j|Ω rj i , i)p(Ω rj i |i), (4)
where rj denotes the index of the support to which j belongs. The last equation arises from the fact that the Ωri are disjoint from each other (Ω r i ∩ Ωsi = ∅,∀r ̸= s). Therefore, there is only one support, Ω rj i , containing j. The remaining terms, where j ̸∈ Ωri for r ̸= rj , are all zero since p (j|Ωri , i) = 0.
Furthermore, assume Ωrji is a sufficient statistic, i.e., j and i are independent given Ω rj i , we obtain
p(j|i) = p(j|Ωrji )p(Ω rj i |i). (5)
Given the partition {Ωri } ni r=0, the attention form in (3) can be rewritten as
A (xi) = Ep(j|i) [vj ] = ni∑ r=0 ∑ j∈Ωri p (j,Ωri |i) vj (6)
= ∑ j∈Ω0i p̃(j|i)vj
︸ ︷︷ ︸ direct expectation
+ ∑ni
r=1 p(Ω r i |i) ( ∑ j∈Ωri p(j|Ωri )vj )
︸ ︷︷ ︸ local expectation
, (7)
where we consider direct attention in partition Ω0i and apply the local factorization (5) to the partition r = 1, . . . , ni. Here p̃(j|i) ∝ p(j|i) but with different normalization constants, which will be explained below. We refer to this model as Combiner since the structured attention (7) combines the direct expectation of Ω0i and multiple local expectations via p(j|Ωri ) and p(Ωri |i) to form the final conditional expectation.
Equivalently, we can also rewrite the structured attention (7) as
A(xi) = ∑
j∈Ωi
[ I(j ∈ Ω0i )p̃(j|i) + ni∑ r=1 I(j ∈ Ωri )p(j|Ωri )p(Ωri |i) ] ︸ ︷︷ ︸
the new effective conditional probability q(j|i)
vj , (8)
where I(·) is a binary indicator function. After reordering, one can see from (8) that we obtain the effective conditional probability q(j|i) that tries to approximate the original p(j|i). Each probability term depends on both current location i and other location j, and the expectation is still obtained with respect to a valid conditional probability (non-negative and sums up to 1 over Ωi).
Requirement for Sub-quadratic Cost. We can immediately see the benefit of this formulation from the fact that the local expectation in (7) is independent of the position i. The full dependence is achieved via the multiplier p(Ωri |i) where j ∈ Ωri . If we can design the local factorization such that:
1. the order of number of terms in (7) for p(·|i), ∀i ∈ [L]: ∑L
i=1(ni + |Ω0i |) is sub-quadratic; and 2. let U = {Ωri }i∈[L],r∈[1,ni] be the unique set of partitions used for local expectation calculation,
then the order of |U| (i.e., the number of unique partitions in U) is sub-quadratic; 3. the order of total number of unique calculations of local expectation across all locations in (7),∑ Ω∈U |Ω| is sub-quadratic; then one can see that the overall computation and memory cost will be sub-quadratic with full attention support ΩCombineri = Ωi, ∀i ∈ [L]. We will discuss in detail in Section 4 how to instantiate such a principle by drawing inspiration from existing sparse transformers, and how to convert them into a full attention model almost for free with identical asymptotic complexity.
Remark (Further Hierarchical Decomposition): We introduce the local decomposition with a one layer partition of support of p(·|i) for simplicity. In fact, such local decompositions can be stacked further, which introduces a partition tree. Specifically, we can further partition Ωri with disjoint subsets { Ωrki }nr k=1 , and consider local decomposition p(j,Ωri |i) = p(j|Ω rkj i , i)p(Ω rkj i |Ωri , i)p(Ωri |i), where kj is the index of sub-region which j belongs to. Thus, we obtain a hierarchical decomposition of p(j|i), which can also be plugged to (6) and yield a new full attention formulation.

heading: 3.2 Parameterizing Conditional Probabilities
text: While we obtained a possible way to speed up the standard Transformer via a combination of direct expectation and local expectations, it is also important to have an efficient design choice for the probability terms in (7), namely p̃(j|i) from direct expectation, p(j|Ωri ) from local expectation and p(Ωri |i) for r ∈ [1, ni]. For simplicity we use the scaled dot-product, which means that we will associate positions i, j and variable sets Ωri with the corresponding embedding representation, and thus the probability is proportional to the exponential of the embedding inner products. Specifically:
• p̃(j|i): As this term is for the direct expectation, we can let p̃(j|i) ∝ exp( qi√ d k⊤j ), which is the same
as vanilla attention (3) but with different normalizations, which will be explained in Equation 9. • p(Ωri |i): This term aims to capture the joint event probability, i.e., p(Ωri |i) ∝ exp ( qi√ d k⊤Ωri ) . Thus
the design choice of kΩri should make an abstraction of the corresponding support Ω r i . We find kΩri = max poolingj∈Ωri kj already provides good empirical results without introducing additional parameters; we can also use DeepSets [32] to obtain such abstraction. • p(j|Ωri ): This term is the probability of getting j within this local span Ωri . We make p(j|Ωri ) ∝ exp ( qΩr
i√ d k⊤j ) , where we use max pooling or DeepSets over {qj}j∈Ωri to obtain qΩri similarly.
Normalizing Probability Terms. The terms in each local expectation p(j|Ωri ), ∀j ∈ Ωri can be normalized within the local span; the direct expectation p̃(j|i) and the terms in p(Ωri |i) should be normalized together,
Z(xi) = ∑
j∈Ω(0)i
exp ( qi√ d k⊤j ) + ni∑ r=1 exp ( qi√ d k⊤Ωri ) , (9)
and Z(xi) is the normalizing constant when calculating p̃(j|i) and p(Ωri |i).

heading: 3.3 Trade-offs in Combiner
text: Combiner achieves full attention with reduced cost without making explicit sparsity or low-rank assumptions over the attention matrix. However this efficiency gain is not free. In this section we discuss the limitations of the simplification made by Combiner, and provide a simple workaround.
Structured Attention Approximation. We obtain the local decomposition (5) under the conditional independence assumption. Therefore, the local expectation in (7) is independent of the position i, this suggests that any two locations i1 and i2 with Ωri1 = Ω r i2
= Ω would have linearly dependent attention scores over the region Ω. Formally, the probabilities formed by the effective conditional distribution a⃗(Ω)i1 = [ q(j1|i1), q(j2|i1), . . . , q(j|Ωri1 ||i1) ] = p(Ωri1 |i1) p(Ωri2 |i2) a⃗(Ω)i2 . In other words, the rank of the sub-matrix over the same partition in the resulting attention matrix is 1, therefore, the attention matrix is locally low-rank based on the partition. On the other hand, the direct expectation fully attends to each position in sub-support Ω0, which ensures the full-rank block. These two attention schemes make the attention matrix of Combiner structured. Compared with the low-rank approximation for attention [26, 28, 30], which is inspired from random features [29] in the kernel community, a structured approximation that exploits both the locally low-rank and full-rank blocks has been proved more powerful theoretically and empirically in large-scale kernel machines [27].
Improving Expressiveness Using a Mixture Model. One way to further improve the expressiveness of the local factorization is to use a mixture model. This idea is adapted from the mixture of softmaxs [33] to obtain high-rank softmax layer in language modeling. Let ω be a certain partition of the support (i.e., collection of Ωri ) of Ωi, then one can easily use A(xi) = 1 M ∑M m=1 A(xi;ωm) to compute the attention, where each component of the mixture A(xi;ωm) is the term (7) using a specific factorization plan ωm. Empirically we find two components are already sufficient to improve performance.

heading: 4 Combiner Instantiations
text: In this section we show several local factorization schemes satisfying the requirements in Section 3.1. As we will see, Combiner is able to convert several sparse transformers [14, 18, 20–22] into full
attention, with the same order of computation and memory consumption. One can also design other factorization patterns, which can be easily instantiated in Combiner.

heading: 4.1 Combiner-Fixed
text: The Sparse Transformer [14] is one of the most representative variants that can achieve O(L √ L) computation and memory cost with sparse attention. Here we show how to convert this fixed pattern proposed in [14] (Figure 1(A)) into a factorization plan, and instantiate a full attention variant named the Combiner-Fixed (Figure 1(D)).
In the fixed-sparse attention, the support is Ωsparse MLMi = {j : j mod s = 0} ∪ {j : j ≡ i (div s)} where s is a hyper-parameter, div is integer division, and j ≡ i (div s) denotes that the quotients of i and j w.r.t. s are the same. In the autoregressive case, Ωsparse LMi = Ω sparse MLM i ∩ [i]. Please refer to Figure 1(A) for an illustration of the LM version.
Our design of ωMLMfixed has the following form: Ω0i = {j : j ≡ i (div s)} ,Ωri = { j : j div s = r, j /∈ Ω0i } ,∀r ∈ [L div s], ∀i ∈ [L] (10) where each local expectation is performed in each span of size s, and there are totally L div s spans across all locations. For each position i ∈ [L], there are (s + (L div s)) terms in (7) ; the local expectation has (L div s) terms . The overall complexity is O(L · (s+ 2(L div s))). The optimal s is O( √ L), and we can achieve O(L √ L) computation and memory complexity, which is the same as [14] but here we gain full attention capability in each attention head. For the LM case, we can simply have ωLMfixed : {Ωri ∩ [i] | Ωri ∈ ωMLMfixed }, which has the same O(L √ L) optimal complexity.

heading: 4.2 Combiner-Logsparse
text: The Logsparse Transformer is proposed in [18] and can theoretically achieve O(L logL) cost. The general idea is to make the size of support Ωsparsei no larger than ⌈log2 i⌉. For the ease of notation, we first define bits(n) = [b1, b2, . . . , b⌈log2 n⌉] to be the binary representation of integer n, with bt ∈ {0, 1} the coefficient of basis 2t. Thus we have n = ∑⌈log2 n⌉ t=1 bt ∗2t. One of the possible design
choices to make Logsparse in the LM case is Ωsparse LMi = { sufft := ∑⌈log2 i−1⌉ τ=t bτ ∗ 2τ }⌈log2 i−1⌉ t=1
∪ {i}, i.e., attend to the location indices that equal to the suffix sum of the weighted bits(i− 1), as well as location i itself. This serves as our base sparse version as shown in Figure 1(B).
To exploit this scheme in the Combiner framework, we can define ⌈log2 n⌉ non-overlapping supports, where Ωri = [suffr] \ [suffr+1] with the boundary case [suff⌈log2 i−1⌉+1] = ∅. Note that for the ease of notation, some of the Ωri are empty which will be ignored. In this case, the direct attention set Ω0i includes {i}, as well as {i− 1} when i is an even number. Such a factorization leads to Combiner-Logsparse, as shown in Figure 1(E). From the Figure, we observe that in total we will have span summaries for every 2, 4, 8, . . . , 2⌊log2 L⌋ locations, resulting in total ∑⌊log2 L⌋ t=1 ⌊ L 2t ⌋ or O(L) summaries. Each location i will select at most O(log(i)) non-overlapping spans to cover the full support Ωi, and thus, the total cost will be O (L logL). We leave the design of MLM case to Appendix B.

heading: 4.3 Combiner-Axial
text: The Axial Transformer [20] builds the attention along each axis of the input data. Without loss of generality, we focus on 2D case where the input sequence is reshaped into a matrix of size n×m = L. Specifically, the location i in original sequence will be in rowi = (i− 1) div m+ 1 and coli = (i− 1) mod m+ 1. We show how to simply enable full attention with factorization on 2D matrix, hence Combiner-Axial.
The sparse axial has Ωsparse MLMi = {j : j − 1 ≡ i− 1(mod m)} ∪ {j : j − 1 ≡ i− 1(div m)}, and Ωsparse LMi = Ω sparse MLM i ∩ [i], which all have at most O(m + n) entries for each i, as illustrated in Figure 1(C). We propose several factorization schemes to make it an attention with full support.
• ωLMaxial-vertical: Ω 0 i = Ω sparse LM i , and Ω r i = {j : j ≡ r(mod m)} ∩ [i− coli], for r ∈ [m] \ {coli}. As
depicted in Figure 2(A), Ωri corresponds to the column r above rowi, where we use max pooling to
obtain the abstraction. To obtain such abstraction for all the locations, we can leverage the cummax operator for each column to efficiently obtain the prefix-max.
• ωLMaxial-horizontal: similar as ωaxial-vertical except that each Ω r i summarizes the row r before rowi and
excludes coli (Figure 2(B)).
• ωLMaxial-rowmajor: Ω 0 i = {j : j − 1 ≡ i− 1(div m)} ∩ [i], i.e., elements in the same row are directly
attended, while Ωri = {j : j ≡ r(div m)} ∩ [i− coli] captures the rows before rowi. This structure is similar to Combiner-Fixed, except for the way that the abstraction (and thus the local expectation) is computed. Combiner-Fixed computes the abstraction only based on r of partition Ωri , where ωaxial-rowmajor depends on both r and the column coli (Figure 1(F)).
In all cases above, the cost is similar to the Axial Transformer [20], which is O(L √ L) if we reshape the sequence to a 2D matrix with n,m = O( √ L). We defer the MLM case to Appendix C.

heading: 4.4 Combiner-Learnable
text: Inspired by the Reformer [21] and Routing Transformer [22], we can also learn the factorization plan ω from the data. We illustrate this with Routing Transformer and provide a way to enable full attention in Routing Transformer following the Combiner principle.
For a specific layer, suppose we have a learned disjoint region (or cluster in Routing Transformer) {Ωr}nr=1 where ∪rΩr = [L]. In Routing Transformer, we simply have Ω sparse MLM i = Ω
ri where Ωri denotes the region where position i belongs to. To define the Combiner factorization, we let
ωrouting MLM : Ω 0 i = Ω ri , Ωri = Ω r \ Ω0i , ∀r ∈ [ni]. (11)
Note that ni = n (i.e., number of learned clusters) for all locations. The above factorization can only work for MLM. LM requires the following definition:
ωrouting LM : Ω 0 i = Ω ri ∩ [i], Ωri = ( Ωr \ Ω0i ) ∩ [i], ∀r ∈ [ni]. (12)
In general, both LM and MLM can have sub-quadratic cost when n = O( √ L). However, routing variants (including the Routing Transformer) require a gather operation, which can be slow on TPUs (see illustration in Appendix D).

heading: 5 Experimental Evaluation
text: We evaluate Combiner with different full attention patterns on both autoregressive and bidirectional sequence modeling tasks, covering a wide range of input data from images to texts. All tasks considered involve long sequences for up to 12,000 in length, some of which prevent the applicability of the vanilla transformer. We compare Combiner with state-of-the-art Transformers. We also perform a series of ablation studies where all of the models being compared use the exact same architecture that only differ in the attention module, avoiding individual tricks employed in the original works (e.g., using both learnable and fixed patterns in Routing Transformer [22]). Details to reproducing all experimental results can be found in Appendix E.

heading: 5.1 Autoregressive Sequence Modeling
text: In this subsection, we first perform density estimation on text and image using Combiner.
5.1.1 Language Modeling Table 2: LM Perplexity on Wiki-40B (Main).
Model Perplexity Transformer-2k [1] 17.26 Performer-2k [28] 19.66 Routing-2k [22] 20.85
Fixed-2k [14] 18.04 Combiner-Fixed-2k (Ours) 17.70
Axial-2k [20] 20.82 Combiner-Axial-2k (Ours) 17.56
Combiner-Fixed-8k (Ours) 16.60 Combiner-Axial-8k (Ours) 16.49
For language modeling, we focus on the Wiki-40BEn dataset [34], which consists of clean Wikipedia pages in English. We use a sentence piece model with vocabulary size 32K to tokenize the text and measure the perplexity at the sentence piece level. To ensure fair comparison, all models being compared again have the same number of layers and hidden sizes, are are implemented under the same code base.
Table 2 shows the results of the comparison. As we can see, under 2k sequence length, Combiner variants are consistently better than their corresponding baselines, and are very close to the standard Transformer. When sequence length goes to 8k, the standard Transformer runs out of memory, whereas Combiner continues to achieve improved perplexity, surpassing the result of Transformer-2k. If we further use DeepSets to calculate the summarization terms qΩri and kΩri , we may further achieve lower perplexity as shown in Table 3.

heading: 5.1.2 Image Generative Models
text: CIFAR-10. We first perform a sanity check where we compare sparse attention baselines against Combiner with full attention under the same architecture on the CIFAR-10 dataset. The sequence length is 3072. For all the methods, we use a same 6-layer transformer with 8 attention heads and 512 embedding dimensions. We train all models for 500k iterations using batch size 32 on TPU v2. As shown in Table 1, given the same model architecture, Combiner-X performs significantly better than the base model X under the bits per dimension (BPD) metric on the 10,000 test images. In particular, Combiner significantly decreases BPD by 0.887, 0.087, and 0.626 compared to the base models Logsparse, Fixed and Axial, respectively. Note that all of the Combiner variants achieve better performance than the best of the base models. This demonstrates the advantage of Combiner over the baselines given the same 6-layer architecture. We observe a similar trend under a 12-layer architecture.
Following the 128-layer architecture in Child et al. [14], we apply Combiner-Axial and achieve state-of-the-art performance, 2.77 BPD on CIFAR-10, as listed in Table 4. We run all of the models in Table 4 without data augmentation [35].
ImageNet-64. We also evaluate performance under the autoregressive setting on ImageNet-64, where sequence length is 12,288. We first perform the same analysis as CIFAR-10 and compare Combiner-X with the baselines using the same model architecture. As shown in Table 1, Combiner consistently outperforms the baselines with the same attention pattern. We further apply CombinerAxial to a 30-layer Transformer, which achieves state-of-the-art performance on density estimation on ImageNet-64, demonstrating the effectiveness of full attention achieved by Combiner.

heading: 5.2 Bidirectional Sequence Modeling
text: Besides autoregressive tasks, we also evaluate Combiner on a set of standard bidirectional tasks to show the general applicability of the method.

heading: 5.2.1 Long-Range Arena
text: Long-Range Arena (LRA) is a unified benchmark [31] for probing the capability of efficient transformers on handling long sequences. We evaluate our models on five tasks from LRA: ListOps, Text Classification, Retrieval, Image Classification and Pathfinder. All of the tasks are sequence-level multi-class classification. Please refer to the original LRA paper for more details.
As shown in Table 5, Combiner is able to match the performance of vanilla Transformer and achieves even better performance in some tasks. Following the protocol of LRA, all methods use the same architecture and hyperparameters for a controllable comparison. We use the numbers from Tay et al. [31] for all tasks except for Pathfinder. Since we were unable to reproduce the original Pathfinder results using the default setup in LRA Github repository, we rerun all the baselines using Pathfinderinter configuration to conduct fair comparison. However, as the benchmark is still of small-scale and the LRA official website discourages hyperparameter tuning, Table 5 should be treated as results for the test bench of expressiveness compared to vanilla Transformer.

heading: 5.2.2 Masked Language Modeling
text: As the core element of BERT langauge pretraining [5], masked language modeling (MLM) refers to the task of reconstructing tokens that are randomly masked out in the input sequence. As with the LM task, we use perplexity as the main metric, which correlates relatively well with down-stream task performance. Specifically, we use the large scale C4 dataset [8] for training and evaluation, and consider different sequence lengths. Following the original BERT setup, we mask out 15% of the tokens in each input sequence. The comparison is summarized in Table 6. Similar to the LM result, different Combiner variants consistently outperform their corresponding baselines under 2k sequence length. However, apart from the standard Transformer, Combiner-2k also falls behind BigBird-2k. We conjecture that this is related to the special design in BigBird such as all tokens can always attend to the <cls> token directly, which is only applicable in non-causal problems. That said, when we further increase sequence length to 8k, the standard Transformer runs into OOM issue, whereas Combiner not only outperforms BigBird but also substantially surpasses Transformer-2k. This suggests that Combiner can truly benefit from scaling learning to longer sequence lengths.

heading: 5.3 Runtime and Memory Usage of Combiner
text: Here we evaluate the inference runtime and memory usage of five baselines – Transformer, Performer, BigBird, Sparse-Fixed and Sparse-Axial, as well as three variants of Combiner– Combiner-Fixed, Combiner-Axial and Combiner-Mixture. We run inference of all the models on a TPU v3-16 (16 cores x 16GB) with batch size 16, and we test sequences of length from 210 to 214. As shown in Figure 3, Combiner instantiations achieve comparable runtime and memory usage with their sparse counterpart and Performer. Note Combiner achieves much better empirical performance than the sparse models and Performer. Combiner-Mixture has the same asymptotic complexity with Combiner-Fixed and Combiner-Axial, however, since it requires running two partition plans, it is slower than Combiner-Fixed and Combiner-Axial. Due to the gather operation required by the random attention which is not very TPU/GPU friendly, BigBird is very computationally expensive. And the Transformer model quickly runs out of memory when sequence length increases.

heading: 6 Conclusion
text: Inspired by the conditional expectation view of attention mechanism, we propose Combiner, a drop-in replacement of the attention module. By introducing structured decomposition to the conditional probability, Combiner achieves full attention capability while maintaining sub-quadratic computational and memory cost. We instantiate several Combiner variants converting existing sparse transformers to full attention. Combiner achieves state-of-the-art performance on both autoregressive and bidirectional tasks for image and text modeling, showing benefits in both modeling effectiveness and runtime efficiency. Future work includes additional factorization pattern designs, as well as applications of Combiner in domains like bioinformatics and speech.
Acknowledgments and Disclosure of Funding
We would like to thank Richard Song and David Dohan for the help on introducing Performer codebase and experiment configurations, Yi Tay and Mostafa Dehghani for clarifications on the LRA benchmark, James Lee-Thorp, Joshua Ainslie, and Ilya Eckstein for clarification on their LRA experiment results, Adams Yu for performing internal paper review and helpful suggestions. We also gratefully acknowledge the support of DARPA under Nos. HR00112190039 (TAMI), N660011924033 (MCS); ARO under Nos. W911NF-16-1-0342 (MURI), W911NF-16-1-0171 (DURIP); NSF under Nos. OAC-1835598 (CINES), OAC-1934578 (HDR), CCF-1918940 (Expeditions), IIS-2030477 (RAPID), NIH under No. R56LM013365; Stanford Data Science Initiative, Wu Tsai Neurosciences Institute, Chan Zuckerberg Biohub, Amazon, JPMorgan Chase, Docomo, Hitachi, Intel, JD.com, KDDI, NVIDIA, Dell, Toshiba, Visa, and UnitedHealth Group. Hongyu Ren is supported by the Masason Foundation Fellowship and the Apple PhD Fellowship. Jure Leskovec is a Chan Zuckerberg Biohub investigator.

Review summaries:
This paper focuses on the problem of reducing the computational cost of attention in transformers. In particular, it addresses the lack of expressiveness in existing attention approaches that leverage sparsity. To this end, the authors propose to view attention as a conditional expectation of embeddings for each token which can be approximated with a structured factorization that includes a direct expectation and an indirect/local expectation term.  Existing sparse attention patterns with sub-quadratic cost can then be used to design such factorizations which result in more expressive attention mechanisms with the same theoretical cost. The evaluation shows that this model can also reach competitive performance in several benchmarks.

Combiner - a new cheaper computationally attention algorithm. By introducing a new factorization structure, the design an algorithm with low complexity but capability close to full attention. Numerous experiments demonstrate the utility of the proposed approach.