M RS F ORMER : T RANSFORMER WITH M ULTIRESOLUTION - HEAD A TTENTION
Anonymous authors
Paper under double-blind review
A BSTRACT
We propose the Transformer with Multiresolution-head Attention (MrsFormer), a class of efficient transformers inspired by the multiresolution approximation (MRA) for approximating a signal f using wavelet bases.
MRA decomposes a signal into components that lie on orthogonal subspaces at different scales.
Similarly, MrsFormer decomposes the attention heads in the multi-head attention into fine-scale and coarse-scale heads, modeling the attention patterns between tokens and between groups of tokens.
Computing the attention heads in MrsFormer requires significantly less computation and memory footprint compared to the standard softmax transformer with multi-head attention.
We analyze and validate the advantage of MrsFormer over the standard transformers on a wide range of applications including image and time series classification.
I NTRODUCTION
The transformer architectures (Vaswani et al., 2017) is popularly used in natural language processing (Devlin et al., 2018;
Al-Rfou et al., 2019; Dai et al., 2019; Child et al., 2019; Raffel et al., 2020;
Baevski & Auli, 2019; Brown et al., 2020; Dehghani et al., 2018), computer vision (Dosovitskiy et al., 2021; Liu et al., 2021; Touvron et al., 2020; Ramesh et al., 2021; Radford et al., 2021; Arnab et al., 2021;
Liu et al., 2022; Zhao et al., 2021; Guo et al., 2021; Chen et al., 2022), speech processing (Gulati et al., 2020;
Dong et al., 2018; Zhang et al., 2020;
Wang et al., 2020b), and other relevant applications (Rives et al., 2021; Jumper et al., 2021; Chen et al., 2021; Zhang et al., 2019; Wang & Sun, 2022).
Transformers achieve state-of-the-art performance in many of these practical tasks, and the results get better with larger model size and increasingly long sequences.
For example, the text generating model in (Liu et al., 2018a) processes input sequences of up to 11,000 tokens of text.
Applications involving other data modalities, such as music (Huang et al., 2018) and images (Parmar et al., 2018), can require even longer sequences.
Lying at the heart of transformers is the self-attention mechanism, an inductive bias that connects each token in the input through a relevance weighted basis of every other tokens to capture the contextual representation of the input sequence (Cho et al., 2014; Parikh et al., 2016; Lin et al., 2017; Bahdanau et al., 2014; Vaswani et al., 2017;
Kim et al., 2017).
The capability of self-attention to attain diverse syntactic and semantic representations from long input sequences accounts for the success of transformers in practice (Tenney et al., 2019; Vig &
Belinkov, 2019; Clark et al., 2019; Voita et al., 2019a; Hewitt & Liang, 2019).
In spite of the success of MHA, it has been shown that attention heads in MHA are redundant and tend to learn similar attention patterns, thus limiting the representation capacity of the model (Michel et al., 2019; Voita et al., 2019b; Bhojanapalli et al., 2021).
Furthermore, additional heads increase the computational and memory costs, which becomes a bottleneck in scaling up transformers for very long sequences in large-scale practical tasks.
These high computational and memory costs and head redundancy issues of the MHA motivates the need for a new efficient attention mechanism.
1. C ONTRIBUTION
Levaraging the idea of the multiresolution approximation (MRA) (Mallat, 1999; 1989; Crowley, 1981), we propose a class of efficient and flexible transformers, namely the Transformer with Multiresolutionhead Attention (MrsFormer).
At the core of MrsFormer is to use the novel Multiresolution-head
Attention (MrsHA) that computes the approximation of the outputs
H h , h = 1 , . . .
, H , of attention heads in MHA at different scales for saving computation and reducing the memory cost of the model.
The MRA has been widely used to efficiently approximate complicated signals like video and images in signal and image processing (Mallat, 1999; Taubman & Marcellin, 2002; Bhaskaran &
Konstantinides, 1997), as well as to approximate solutions of partial differential equations (Dahmen et al., 1997; Qian & Weiss, 1993).
While existing works have been proposed to approximate the attention matrices using the MRA (Zeng et al., 2022; Fan et al., 2021; Tao et al., 2020; Li et al., 2022), our MrsHA is the first method that approximates the output of an attention head, resulting in a better approximation scheme compared to other works that try to approximate the attention matrices.
Our contribution is three-fold:
We derive the approximation of an attention head at different scales via two steps: i)
Directly approximating the output sequence H , and ii) approximating the value matrix V ,
i
e. the dictionary that contains bases of H .
We develop MrsHA, a novel MHA whose attention heads approximate the output sequences H h , h = 1 , . . .
, H , at different scales.
We then propose MrsFormer, a new class of transformers that use MrsHA in their attention layers.
We empirically verify that the MrsFormer helps reduce the head redundancy and achieves better efficiency than the baseline softmax transformer while attaining comparable accuracy to the baseline.
Organization: We structure this paper as follows:
In Section 2, we derive the approximation for the output sequence H h , h = 1 , . . .
, H , at different scales and propose the MrsHA and MrsFormer.
In Section 3 and 4, we empirically validate and analyze the advantages of the MrsFormer over the baseline softmax transformer.
We discuss related work in Section 5.
The paper ends up with concluding remarks.
More experimental details are provided in the Appendix.
T RANSFORMER WITH M ULTIRESOLUTION - HEAD A TTENTION 2. B ACKGROUND : S ELF - ATTENTION
The self-attention mechanism learns long-range dependencies via parallel processing of the input sequence.
For a given input sequence X :=
[ x 1 , · · · , x N ] ⊤ ∈ R N × D x of N feature vectors, the self-attention transforms X into the output sequence H :
= [ h 1 , · · · , h N ] ⊤ ∈ R N × D v as follows
[Equation]
where Q :=
[ q 1 , · · · , q N ] ⊤ , K :=
[ k 1 , · · · , k N ] ⊤ , and V :=
[ v 1 , · · · , v N ] ⊤ are the projections of the input sequence X into three different subspaces spaned by W Q , W K ∈ R D
× D x , and W V ∈
R D v × D x , i.e. Q = XW ⊤ Q , K = XW ⊤ K , V = XW ⊤ V .
Here, in the context of transformers, Q , K , and V are named the query, key, and value matrices, respectively.
The softmax function is applied to row-wise.
The matrix A = softmax (cid:16) QK ⊤ √ D (cid:17)
∈ R N × N is the attention matrix, whose component a ij for i, j = 1 , · · · , N are the attention scores.
The structure of the attention matrix A after training from data determines the ability of the self-attention to capture contextual representation for each token.
Eqn.
(1) is also called the scaled dot-product or softmax attention.
In our paper, we call a transformer that uses this attention the softmax transformer.
Multi-head Attention (MHA).
In MHA, multiple heads are concatenated to compute the final output.
Let H be the number of heads and W multi O = (cid:104) W (1) O , . . .
, W ( H )
O (cid:105) ∈
R D v × HD v be the projection matrix for the output where W (1) O , . . .
, W ( H ) O ∈ R D v × D v .
The multi-head attention is defined as
MultiHead ( { H } Hh =1 ) =
Concat ( H (1) , . .
, H ( H ) )
W multi ⊤ O =
H (cid:88) h
=
H ( h
[Equation]
W h
⊤ O =
H (cid:88) h
=
A ( h ) V ( h
[Equation]
The MHA extends the single-head attention and enables transformers to capture more diverse attention patterns.
2. B ACKGROUND : W AVELET T RANSFORM AND M ULTIRESOLUTION A PPROXIMATIONS
The wavelet transform uses time-frequency atoms with different time supports to analyze the structure of a signals.
In particular, it decomposes signals over dilated and translated copies of a fixed function φ .
A dictionary of time-frequency atoms is obtained by scaling φ by s and translating it by t :
[Equation]
Here, s controls the dilation, i.e., the scale, and t controls the location, e.g., the time.
Using this dictionary of time-frequency atoms, a signal f ∈ L 2 ( R ) can be expanded in the following form:
[Equation]
The wavelet transform then maps the signal f to the coefficient α st as follows
[Equation]
[Equation]
where φ ∗ is the complex conjugate of φ .
The coefficient α st captures the measurement of the signal f
at scale s and location t (Mallat, 1999).
2. T RANSFORMER WITH M ULTIRESOLUTION - HEAD A TTENTION 2.3. F IRST L EVEL A PPROXIMATION : A PPROXIMATING THE O UTPUT S EQUENCE H AT D IFFERENT S CALES
Let B s = { φ st ∈ R N } be a set of orthogonal expansion functions for possible translations at scale s where s = 1 , 2 , 4 , . . .
, N .
For simplicity, we assume that the sequence length N = 2 k .
The expansion functions φ st are chosen to be the boxcar functions as follows
[Equation]
(6) for s ∈ { 1 , 2 , 4 , . . .
, N } and t ∈ { 1 , . .
. , N/s } .
At each scale s , we approximate the columns H [: , d ] , d = 1 , . . .
, D v , of the output sequence H as follows
[Equation]
where the coefficient α std is computed as follows
[Equation]
Plug Eqn.
(1) and Eqn.
(8) into Eqn.
(7), we obtain
[Equation]
Here, we employ the notations for downsampling and upsampling from signal processing.
In particular, ↓ s,ℓ denotes the average pooling by the factor s along the ℓ th dimension, and ↑ s,ℓ denotes the nearest-neighbor interpolation by the factor s along the ℓ th dimension.
Applying Eqn.
(10) for d = 1 , . . .
, D v , we achieve the approximation of H at scale s as follows:
[Equation]
An illustration of Eqn.
11 is given in Figure.
1 (Left).
Remark 1 (Approximating the columns of H independently)
As pointed out in (Nguyen et al., 2022), the features H [: , d ] in the ouput sequence H , as well as the features V [: , d ] in the value matrix
V , d = 1 , . . .
, D v , in the softmax attention are independent due to the use of the unnormalized
Gaussian kernels with the isotropic covariance.
This finding justifies our approach of approximating the columns of H independently.
Remark 2 (Group-to-token attention)
The downsampling ↓ s, 1 A of the matrix A in Eqn.
(11) computes the attentions between groups of tokens and individual tokens in the sequence.
2.3. S ECOND L EVEL A PPROXIMATION : A PPROXIMATING THE H EAD B ASES V AT D IFFERENT S CALES
In Eqn.
(11) that approximates the output sequence H at scale s by H s , we can further approximate the bases V , i.e., the value matrix, by its approximation at scale s ′ .
Following the derivation in
Section 2.3.1 above, we can derive the approximation V s ′
[: , d ] for the d th columns of V as follows
[Equation]
Plugging Eqn.
(12) into Eqn.
(9), we obtain the second level approximation of the head output H :
[Equation]
Same as above, by applying Eqn.
(13) for d = 1 , . . .
, D v , we achieve the full approximation of H at scale s of H and scale s ′ of V as follows:
[Equation]
An illustration of Eqn.
14 is given in Figure.
1 (Right).
Given the approximation H s,s ′ of the attention matrix H , we have the following upper bound on the approximation error.
Theorem 1 Assume that δ > 0 is chosen such that the attention matrix A satisfies the following inequalities
| A i,j − A i ± 1 ,j | ≤ δ, | A i,j − A i,j ± 1 | ≤ δ for all 1 ≤ i, j ≤ N .
Then, we obtain that
[Equation]
where ∥
∥
F denotes the Frobenius norm and ∥ .
∥ 2 denotes the spectral norm of a matrix.
Proof of Theorem 1 is in Appendix B.
The result of Theorem 1 shows that the approximation matrix H s,s ′ approximates H exactly when s = s ′
= 1 , which is true.
In the coarsest scale when s = s ′
=
N , the upper bound achieves the maximum value ( N − 1)
δ
∥ V ∥ 2 .
Remark 3 (Group-to-group attention)
The downsampling ↓ s, 1 ↓ s ′ , 2 A of the matrix A in Eqn.
(14) computes the attentions between groups of tokens and groups of tokens in the sequence.
2.3. E FFICIENT D OWNSAMPLING OF THE A TTENTION M ATRIX A
As shown in Eqn.
(1), A = softmax (cid:16)
QK ⊤ √ D (cid:17) .
Since the softmax function needs access to the full matrix QK ⊤ √ D , downsampling A via average pooling still requires to compute the full product QK ⊤ √ D first.
In order to avoid this redundant computation, we propose to compute the lower bound of this average pooling (due to the convexity of the exponential in the softmax function).
In particular, we approximate the downsampling of A as follows:
[Equation]
2.3. T RANSFORMER WITH M ULTIRESOLUTION - HEAD A TTENTION : E ACH H EAD A PPROXIMATES THE A TTENTION AT A D IFFERENT S CALE
In this section, we formally define our Multiresolution-head Attention (MrsHA) and Transformer with Multiresolution-head Attention (MrsFormer).
MrsHA combines Eqn.
(14) and (15) to implement the approximation of the output sequences H ( h ) , h = 1 , . . .
, H , at different scales s and s ′ .
Definition 1 (Multiresolution-head Attention) Let H be the number of heads and W multi O = (cid:104)
W (1) O , . . .
, W ( H )
O (cid:105) ∈
R D v × HD v be the projection matrix for the head outputs where
W (1) O , . . .
, W ( H ) O ∈ R D v × D v .
Given a set of scales { s ( h ) , s ′ ( h ) } Hh =1 for the output H ( h ) and the value matrix V ( h ) , h = 1 , . . .
, H , at each head, the MrsHA is an efficient attention mechanism that computes the approximation of H ( h ) at scale s ( h ) using an approximation of V ( h ) at scale s ′ ( h ) by the following attention formula:
[Equation]
The MrsFormer is the class of transformers that use the MrsHA in their attention layers.
Remark 4 (Downsampling Q , K , and V ) Downsampling Q , K , and V can be efficiently implemented by downsampling the input sequence X before projecting it into the query matrix Q , the key matrix K , and the value matrix V via the linear transformations W Q , W K , and W V , respectively.
Eqn.
(16) of the MrsHA then becomes
[Equation]
An illustration of Eqn. 17 is given in Figure.
Remark 5 (Choosing s ( h ) and s ′ ( h ) ) s ( h ) and s ′ ( h ) are hyperparameters that can be tuned for each head.
In our experiments, we use s ( h ) =
s ′ ( h )
= 2 k ( h ) , where k ( h ) is an integer.
Remark 6 (Choosing the expansion functions φ st and 1-D convolution)
In order to derive the
MrsHA in Eqn.
(16), we have chosen the expansion functions φ st to be the boxcar functions.
Other expansion functions, such as the wavelet bases or the triangular functions, can be used to derive different forms of the MrsHA.
In a general case, the average pooling and the nearest-neighbor interpolation in Eqn.
(16) and (17) can be replaced by the 1-D convolution operators with φ st as the corresponding filters.
E XPERIMENTAL R ESULTS
In this section, we empirically justify the advantages of our propsed MrsFormer model.
We compare the performance of the MrsFormer with the baseline softmax transformer, the MRA-2 (Zeng et al., 2022), and the MRA-2-s (which is the sparse version of the MRA-2) on various benchmarks.
Unlike our method, the MRA-2 and MRA-2-s perform multiresolution analysis for each head by approximating the attention matrix by blocks of different scales, while the MrsHA in our MrsFormer computes the approximation of each head
H h at a specific scale.
The benchmarks studied in our experiments include 10 tasks from the UEA time series classification dataset (Bagnall et al., 2018), 3 tasks from Long Range Arena (Tay et al., 2021b)
(LRA) benchmark, and ImageNet image classification task (Russakovsky et al., 2015).
In addition, we also study the performance of the MrsHA when being combined with other attention mechanism such as the linear attention (Katharopoulos et al., 2020), the MRA-2 attention, and the MRA-2-s attention (Zeng et al., 2022).
We aim to show that: (i) the MrsFormer can achieve better or comparable accuracy over the baseline softmax, MRA-2, and
MRA-2-s transformers; (ii) the MrsFormer saves significant amount of FLOPs and memory compared to the baseline softmax transformer, and this advantage grows with the sequence length; (iii) the
MrsHA can be combined with other attentions to achieve similar or better performance with better efficiency; and (iv) the MrsFormer reduces redundancy between heads comparing to the softmax baseline.
In our experiment, we keep the hyperparameters the same for all models for fair comparisons.
All of our results are averaged over 5 runs with different seeds.
3. UEA T IME S ERIES C LASSIFICATION
Models and baselines.
We adapt code from (Wu et al., 2022; Zerveas et al., 2021) for our experiments.
Following the same setting from these papers, we set the number of heads and layers to 8 and 2, respectively.
For the MrsFormers, we use the same set of scales at each layer, which is given by s = [1 , 1 , 2 , 2 , 4 , 4 , 8 , 8] .
For MRA-2 and MRA-2-s models (Zeng et al., 2022), each head is approximated by blocks of scales [1 , 32] as suggested in their paper.
The percentage of blocks with scale 1 in these
MRA-2 models is set to 25% of the full attention matrix.
Other hyperparameters have the same values as in (Wu et al., 2022) (for the PEMS-SF, SelfRegulationSCP2, and UWaveGestureLibrary tasks) and (Zerveas et al., 2021) (for other tasks).
Results.
We summarize the results in Table 1.
The MrsFormer achieves bettter test accuracy than the baseline softmax transformer for 5 out of 10 tasks while being much more efficient.
Among these tasks, the MrsFormer outperforms the baseline by at least 1% accuracy.
For the remaining tasks, besides Handwriting, our model maintains an accuracy gap less than 0.8% compared to the baseline.
Our model gets the best accuracy for 4 out of the 10 tasks.
In addition, it achieves second best accuracy for 4 out of the remaining tasks.
The MrsFormer achieves the average accuracy across all tasks.
Note that among 8 heads at each layer, our model computes 6 of them with the size of only 14 , 14 , 116 , 116 , 164 and 164 of the size of the corresponding heads in the baseline softmax transformer.
Thus, the MrsFormer has a significant smaller FLOPS and memory usage compared to the baseline.
3. L ONG R ANGE A RENA
Models and baselines.
We follow the same settings and adapt code for LRA task from (Zeng et al., 2022), which uses transformer with 2 heads and 2 layers.
We choose the same set of scales s =
[1 , 2] for all the layers in MsFormer.
Results.
Table 2 summarizes our results.
Although being an approximation of the softmax attention, it is evidently from Table 2 that MrsFormer can consistently achieve better than or comparable accuracy as the baseline softmax attention on the LRA tasks.
The MRA-2 and MRA-2-s models (Zeng et al.,
[Table]
[Table] [Table]
2022) are also included for comparison.
Our MrsFormer’s performance is comparable with these
MRA baselines.
Overall, the MrsFormer yields the best average accuracy across the LRA tasks.
3. I MAGE N ET
Models and baselines:
In this section, we apply the MrsFormer to the Deit model (Touvron et al., 2020) with 4 heads.
Since Deit uses special class token [ CLS ] for the classification, we do not downsample this token along with other tokens in the sequence.
For our MrsFormers, we use the set of scales s =
[1 , 2 , 2 , 4] at each layer.
We also study the MRA-2-s attention on this task.
As reported in (Zeng et al., 2022), the MRA-2-s is a better model than the MRA-2 on the ImageNet image classification task since its sparse attention structure is more effective for modeling images.
Results: We present our results in Table 3.
The MrsFormer DeiT’s top-1 accuracy is about 0 .
5% higher than MRA-2-s DeiT and is the closest model to the performance of the softmax DeiT baseline.
The performance gap of less than 1% of MrsFormer DeiT is very promising for applying the
MrsFormer-based model in large scale tasks to reduce the computational and memory cost while maintaining comparable performance with the baseline transformer.
E MPIRICAL A NALYSIS
In this section, we use the models trained on the LRA retrieval task for our analysis.
4. E FFICIENCY A NALYSIS
We study the efficiency of MrsFormer over the baseline softmax transformer.
Figure 3 demonstrates the reduction ratio of train and test flops of the MrsFormer over the softmax transformer.
Although
[Table]
in this experiment we only approximate one head with scale s = 2 and preserve the other head the same as in the baseline, the FLOP saving ratio over softmax attention still ranges from 18% up to more than 36% and grows with sequence length in both the training and testing phases.
Figurepresents the memory saving ratio of the MrsFormer over the softmax transformer.
This figure shows a similar trend of more memory saving when the sequence length increases.
Our model achieves up to 49% and 31% decrease in memory usage in the training and testing phases, respectively.
This indicates that our model scales well with long sequences and takes significantly less resource than the baseline softmax attention in both training and testing.
4. M RSFORMER HELPS REDUCE HEAD REDUNDANCY
To show that the MrsFormer captures more diverse attention patterns, we compare the average Ldistances between the heads of our trained MrsFormer model (on the retrieval task) and the softmax baseline.
Table 4 reports the layer-average mean and standard deviation of distances between heads.
Since the MrsFormer attains higher L 2 distances, it reduces the risk of learning redundant heads compared to the softmax baseline.
4. B EYOND THE S OFTMAX A TTENTION : C OMBINING M RS HA WITH OTHER A TTENTIONS
The MrsHa is complementary to many other types of attentions.
Therefore, a natural question arises is whether we can combine the MrsHa with other attentions besides the softmax attention?
To answer this question, we combine the MrsHA with the MRA attention (Zeng et al., 2022) and the linear attention (Katharopoulos et al., 2020) and train these combined models for the LRA tasks (Tay et al.,
[Table]
2021a)
as in Section 3.2.
The results are presented in Table 5.
It is interesting to see from Table 5 that all combined models gain an improvement in average test accuracy over the original models despite being an approximation.
This observation suggests that the MrsHa can be applied to other attention mechanisms besides softmax to reduce computation and memory while maintaining the accuracy of the original models
[Table]
R ELATED W ORK
Efficient Transformers.
To reduce the quadratic computational cost and memory usage of transformers
[Table]
many efficient transformer models have been developed (Roy et al., 2021).
Sparse transformers are a line of works in this branch, which explore and design the sparsity structure of attention matrix, resulting in more efficient models (Parmar et al., 2018; Liu et al., 2018b; Qiu et al., 2019; Child et al., 2019; Beltagy et al., 2020).
Another class of efficient transformers is patterns integration, combining different attention patterns to cover a diverse and wide range of dependencies (Child et al., 2019;
Ho et al., 2019).
These patterns can be set as pre-specified or learnable during training, along with model parameters (Kitaev et al., 2020; Roy et al., 2021; Tay et al., 2020).
In another attempt, multiple tokens can be accessed simultaneously with a side memory module, saving the cost of computing and memory storage(Lee et al., 2019; Sukhbaatar et al., 2019; Asai & Choi, 2020; Beltagy et al., 2020).
In a different approach, observing that the attention matrices are low-rank, kernelization and low-rank approximation methods have been proposed to replace the softmax attention with more efficient attentions (Tsai et al., 2019; Wang et al., 2020a; Katharopoulos et al., 2020; Choromanski et al., 2021;
Shen et al., 2021; Nguyen et al., 2021; Peng et al., 2021; Jaegle et al., 2021).
From a signal processing perspective, wavelet-based and multiscale methods has been used lately to learn a multiresolution approximation of self-attention (Zeng et al., 2022; Fan et al., 2021;
Tao et al., 2020; Li et al., 2022), which flexibly discover the coarse and fine attention patterns.
Our approach decomposes the attention heads into coarse- and fine-scale heads, diversely modeling the dependencies between tokens and between group of tokens to reduce the computational and memory costs of the model in both training and testing.
Redundancy in Transformers.
Pre-trained transformers contain redundant neurons and heads which can be pruned away for downstream tasks (Dalvi et al., 2020; Michel et al., 2019; Durrani et al., 2020).
Studying the contextualized embeddings in these pre-trained networks shows the anisotropicity of the learned representation from these models under this redundancy (Mu & Viswanath, 2018; Ethayarajh, 2019).
Multiple approaches have been proposed to reduce this redundancy and improve the efficiency of transformers, such as the knowledge distillation and sparse approximation (Sanh et al., 2019;
Sun et al., 2019; Voita et al., 2019b; Sajjad et al., 2020).
Our MrsHA/MrsFormer represent the attention heads at different scales and are complementary to these methods.
C ONCLUDING R EMARKS
In this paper, we propose the MrsFormer, a class of efficient transformers that calculates the approximation of the attention heads at different scales using the Multiresolution-head Attention (MrsHA).
The MrsFormer achieves better computational and memory cost than the corresponding softmax transformers baseline.
Furthermore, the MrsFormer helps reduce the redundancy between attention heads and can be easily combined with other attention mechanisms.
In the MrsFormer, we use the boxcar function to form a set of orthogonal expansion functions.
It is natural to further develop the
MrsFormer using other basis functions including the popular wavelets.
Furthermore, in our derivation of the MrsHA and MrsFormer in Section 2.3, we employ the observation from (Nguyen et al., 2022) that the features H [: , d ] in the output sequence H are independent.
We leave the extenson of the
MrsHA and MrsFormer to capture dependent output features as future work.
A A DDITIONAL DETAILS ON THE EXPERIMENTS A. UEA TIME SERIES CLASSIFICATION
Datasets and metrics The benchmark (Bagnall et al., 2018) consists of 30 datasets.
Following (Wu et al., 2022), we choose 10 datasets, which vary in input sequence lengths, the number of classes, and dimensionality, to evaluate our models on temporal sequences.
Models and baselines We adapt code from (Wu et al., 2022; Zerveas et al., 2021) for our experiments.
Following the same setting from these papers, we set the number of heads and layers to 8 and 2, respectively.
For the MrsFormers, we use the same set of scales at each layer, which is given by s = [1 , 1 , 2 , 2 , 4 , 4 , 8 , 8] .
For MRA-2 and MRA-2-s models (Zeng et al., 2022), each head is approximated by blocks of scales [1 , 32] as suggested in their paper.
The percentage of blocks with scale 1 in these MRA-2 models is set to 25% of the full attention matrix.
Other hyperparameters have the same values as in (Wu et al., 2022) (for the PEMS-SF, SelfRegulationSCP2, and UWaveGestureLibrary tasks) and (Zerveas et al., 2021) (for other tasks).
Hyperparameters for these tasks are presented in Table 6.
A. L ONG RANGE ARENA BENCHMARK
Datasets and metrics We adopt the tasks: Listops (Nangia & Bowman, 2018), byte-level IMDb reviews text classification (Maas et al., 2011), and byte-level document retrieval (Radev et al., 2013) in the LRA benchmark for our experiments.
They consist of long sequences of length 2 K , 4 K , and 4 K , respectively.
The evaluation protocol and metric are the same as in (Tay et al., 2021b).
Models and baselines We follow the same settings and adapt code for LRA task from (Zeng et al., 2022), which uses transformer with 2 heads and 2 layers.
We choose the same set of scales s =
[1 , 2] for all the layers in MsFormer.
Hperparameters for these tasks are presented in Table 7.
A. I MAGE C LASSIFICATION ON I MAGENET
Dataset and metric: We perform classification task on ILSVRC-2012 ImageNet dataset to validate the performance of our model on large dataset.
This dataset has 1000 classes and about 1.28 million images.
Models and baselines In this section, we apply the MrsFormer to the Deit model (Touvron et al., 2020) with 4 heads.
Since Deit uses special class token [ CLS ] for the classification, we do not downsample this token along with other tokens in the sequence.
For our MrsFormers, we use the set of scales s =
[1 , 2 , 2 , 4] at each layer.
We also study the MRA-2-s attention on this task.
As reported in (Zeng et al., 2022), the MRA-2-s is a better model than the MRA-2 on the ImageNet image classification task since its sparse attention structure is more effective for modeling images.
B P ROOF OF T HEOREM
Recall from Eqn.
(14) that
[Equation]
Let T s be the down-sampling operator (matrix multiplication) on the first dimension of a matrix corresponding to the scale s .
T s is the Kronecker product (or outer product) between an identity matrix
I and the row vector 1 s i −→ 1 of size 1 × s , i.e. T s =
I ⊗ 1 s −→ 1 .
Under this notation, the up-sampling operator is the transpose of T s .
In addition, the down-sampling operator on the second dimension of a matrix is also T Ts but with the right multiplication instead.
Then, we can rewrite the approximation H s,s ′ as follows:
[Equation]
From the above equation, we have
[Equation]
[Table] [Table]
From the inequality with the Frobenius norm, we have
[Equation]
Therefore, it suffices to approximate the upper bound ∥
A − T
Ts T s AT
Ts ′
T s ′
∥ F .
Let A s,s ′ =
T Ts T s AT
Ts ′ T s ′ and obviously A s,s ′ contains blocks matrices of the same values.
We can rewrite
A and A s,s ′ as block matrices of size s × s ′ :
A =
[ A m,n ] m,n and A s,s ′ =
[ A s,s ′ m,n ] m,n where m = 0 , 1 , ..., qlen /s, and n = 0 , 1 , ..., klen /s ′ .
Note that all elements of A s,s ′ m,n have an identical value to the average of all elements of the sub-matrix A m,n .
Now we can decompose the above quantity into a sum of Frobenius norms:
[Equation]
Recall that from the hypothesis, we have
[Equation]
Then, by applying Popoviciu’s inequality, we have
[Equation]
where m = inf X and M = sup X .
Since matrix is finite, the infimum and the maximum become the maximum and minimum respectively.
By Assumption 18, we can approximate the upper bound of M − m as follows:
[Equation]
Integrate the sum, we find that
[Equation]
When we plug in klen = qlen =
N , we obtain a simpler version:
[Equation]
As a consequence, we obtain the conclusion of the theorem.
C A DDITIONAL EXPERIMENTS C. C OMBINING M RS HA WITH OTHER EFFICIENT ATTENTIONS
In this section, we combine the proposed MrsHA architecture with other efficient attention mechanisms to demonstrate MrsHA can be combined with other efficient transformer to reduce memory and computation requirements.
We run our experiments on 5 efficient transformer including
[Table] [Table]
[Table]
Linformer (Wang et al., 2020a), Linear transformer (Katharopoulos et al., 2020), FMM transformer (Nguyen et al., 2021), Performer (Choromanski et al., 2021) and Luna transformer (Ma et al., 2021).
All experiments settings in this section follows directly from subsections
[Table]
1 and
[Table]
2 unless stated otherwise.
C.1. UEA TIME SERIES CLASSIFICATION
Results in Table 8 presents the accuracy of the combined and original models on the UEA Time
Series Classification task.
All the efficient transformers in this experiment either maintain comparable performance or experience a boost in average accuracy when combined with MrsHA
. C.1. L ONG RANGE ARENA
In Listops experiments, we increase the number of training step from 5000 to 15000 to ensure convergence for all models.
Table 9 further consolidates the advantage of the proposed MrsHA architecture.
In fact, all the combined models obtain better average accuracy than the original models in the LRA task.
C. T ABULAR DATA
We include a diverse set of 11 tabular dataset for our benchmarking: California Housing (Kelley
Pace & Barry, 1997), Adult (Kohavi, 1996), Helena (Guyon et al., 2019), Jannis (Guyon et al., 2019),
Higgs (Baldi et al., 2014), ALOI (Geusebroek et al., 2005), Epsilon (EP, simulated physics experiments), Year (Bertin-Mahieux et al., 2011), Covertype (Blackard & Dean, 1999), Yahoo (Chapelle & Chang, 2011), Microsoft (Qin & Liu, 2013).
We follow all the train settings and use the default set of hyperparameters used in paper (Gorishniy et al., 2021) for all models.
For simplicity, we omit the ensemble step from paper (Gorishniy et al., 2021).
We report average accuracy overrandom seed for both FT-Transformer (Gorishniy et al., 2021) and the combined model of MrsHA and FT-Transformer, which we denote MrsFT-Transformer.
Table 10 evidently shows that our combined model obtained better results in 7 over 11 tasks, while other tasks maintain comparable performance.
This result consolidates the benefit of combining
MrsHA with other transformer models in a diverse set of tasks.
C. E FFICIENCY WHEN COMBINING M RS HA WITH OTHER EFFICIENT TRANSFORMER
For illustration, we present FLOP and memory reduction ratios of train and test phases of our MrsFMM transformer comparing to the original FMM transformer for LRA retrieval task in Figure 5.
Our model saves up to 35% of the original FLOP and has lower memory footprint, less than 65% and 85% of the original model for training and testing phases, respectively.