Stable, Fast and Accurate: Kernelized Attention with Relative Positional Encoding
Shengjie Luo, Shanda Li, Tianle Cai, Di He, Dinglan Peng, Shuxin Zheng, Guolin Ke, Liwei Wang, Tie-Yan Liu
Abstract
The attention module, which is a crucial component in Transformer, cannot scale efficiently to long sequences due to its quadratic complexity. Many works focus on approximating the dot-then-exponentiate softmax function in the original attention, leading to sub-quadratic or even linear-complexity Transformer architectures. However, we show that these methods cannot be applied to more powerful attention modules that go beyond the dot-then-exponentiate style, e.g., Transformers with relative positional encoding (RPE). Since in many state-of-the-art models, relative positional encoding is used as default, designing efficient Transformers that can incorporate RPE is appealing. In this paper, we propose a novel way to accelerate attention calculation for Transformers with RPE on top of the kernelized attention. Based upon the observation that relative positional encoding forms a Toeplitz matrix, we mathematically show that kernelized attention with RPE can be calculated efficiently using Fast Fourier Transform (FFT). With FFT, our method achieves time complexity. Interestingly, we further demonstrate that properly using relative positional encoding can mitigate the training instability problem of vanilla kernelized attention. On a wide range of tasks, we empirically show that our models can be trained from scratch without any optimization issues. The learned model performs better than many efficient Transformer variants and is faster than standard Transformer in the long-sequence regime.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 88df8e35-3915-4253-bb57-0a9710004acdCited by top-tier papers22
- Hungry Hungry Hippos: Towards Language Modeling with State Space ModelsDaniel Y. Fu, Tri Dao, Khaled Kamal Saab, Armin W. Thomas et al.ICLR 2023 · 117 citations
- KERPLE: Kernelized Relative Positional Embedding for Length ExtrapolationTa-Chung Chi, Ting-Han Fan, Peter J. Ramadge, Alexander RudnickyNeurIPS 2022 · 112 citations
- ESSAformer: Efficient Transformer for Hyperspectral Image Super-resolutionMingjin Zhang, Chi Zhang, Qiming Zhang, Jie Guo et al.ICCV 2023 · 73 citations
- Your Transformer May Not be as Powerful as You ExpectShengjie Luo, Shanda Li, Shuxin Zheng, Tie-Yan Liu et al.NeurIPS 2022 · 69 citations
- Functional Interpolation for Relative Positions improves Long Context TransformersShanda Li, Chong You, Guru Guruganesh, Joshua Ainslie et al.ICLR 2024 · 66 citations
Builds on15
- Swin Transformer: Hierarchical Vision Transformer using Shifted WindowsZe Liu, Yutong Lin, Yue Cao, Han Hu et al.ICCV 2021 · 31,683 citations
- An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn et al.ICLR 2021 · 21,477 citations
- Training data-efficient image transformers & distillation through attentionHugo Touvron, Matthieu Cord, Matthijs Douze, Francisco Massa et al.ICML 2021 · 8,974 citations
- Deberta: decoding-Enhanced Bert with Disentangled AttentionPengcheng He, Xiaodong Liu, Jianfeng Gao, Weizhu ChenICLR 2021 · 3,729 citations
- Reformer: The Efficient TransformerNikita Kitaev, Lukasz Kaiser, Anselm LevskayaICLR 2020 · 2,878 citations
Related papers
- Long-range Sequence Modeling with Predictable Sparse AttentionYimeng Zhuang, Jing Zhang, Mei TuACL 2022 · 11 citations
- Learnable Fourier Features for Multi-dimensional Spatial Positional EncodingYang Li, Si Si, Gang Li, Cho-Jui Hsieh et al.NeurIPS 2021 · 171 citations
- Toeplitz Neural Network for Sequence ModelingZhen Qin, Xiaodong Han, Weixuan Sun, Bowen He et al.ICLR 2023 · 5 citations
- PermuteFormer: Efficient Relative Position Encoding for Long SequencesPeng ChenEMNLP 2021 · 16 citations
- Relative Positional Encoding for Transformers with Linear ComplexityAntoine Liutkus, Ondrej Cífka, Shih-Lun Wu, Umut Simsekli et al.ICML 2021 · 63 citations
