Lune

NeurIPS2021Top-tier venue

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 O(nlog⁡n)\mathcal{O}(n\log n) 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 Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

22 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Deberta: decoding-Enhanced Bert with Disentangled Attention cites Reformer: The Efficient Transformer
  • Functional Interpolation for Relative Positions improves Long Context Transformers cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Functional Interpolation for Relative Positions improves Long Context Transformers cites Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
  • Functional Interpolation for Relative Positions improves Long Context Transformers cites Your Transformer May Not be as Powerful as You Expect
  • Functional Interpolation for Relative Positions improves Long Context Transformers cites KERPLE: Kernelized Relative Positional Embedding for Length Extrapolation
  • Swin Transformer: Hierarchical Vision Transformer using Shifted Windows cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Swin Transformer: Hierarchical Vision Transformer using Shifted Windows cites Training data-efficient image transformers & distillation through attention
  • ESSAformer: Efficient Transformer for Hyperspectral Image Super-resolution cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • ESSAformer: Efficient Transformer for Hyperspectral Image Super-resolution cites Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
  • Your Transformer May Not be as Powerful as You Expect cites Deberta: decoding-Enhanced Bert with Disentangled Attention
  • Your Transformer May Not be as Powerful as You Expect cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Your Transformer May Not be as Powerful as You Expect cites Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
  • Training data-efficient image transformers & distillation through attention cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Hungry Hungry Hippos: Towards Language Modeling with State Space Models cites Reformer: The Efficient Transformer
  • KERPLE: Kernelized Relative Positional Embedding for Length Extrapolation cites Deberta: decoding-Enhanced Bert with Disentangled Attention
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers22

  1. 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
  2. KERPLE: Kernelized Relative Positional Embedding for Length ExtrapolationTa-Chung Chi, Ting-Han Fan, Peter J. Ramadge, Alexander RudnickyNeurIPS 2022 · 112 citations
  3. ESSAformer: Efficient Transformer for Hyperspectral Image Super-resolutionMingjin Zhang, Chi Zhang, Qiming Zhang, Jie Guo et al.ICCV 2023 · 73 citations
  4. Your Transformer May Not be as Powerful as You ExpectShengjie Luo, Shanda Li, Shuxin Zheng, Tie-Yan Liu et al.NeurIPS 2022 · 69 citations
  5. Functional Interpolation for Relative Positions improves Long Context TransformersShanda Li, Chong You, Guru Guruganesh, Joshua Ainslie et al.ICLR 2024 · 66 citations

Builds on16

  1. Swin Transformer: Hierarchical Vision Transformer using Shifted WindowsZe Liu, Yutong Lin, Yue Cao, Han Hu et al.ICCV 2021 · 31,683 citations
  2. 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
  3. Training data-efficient image transformers & distillation through attentionHugo Touvron, Matthieu Cord, Matthijs Douze, Francisco Massa et al.ICML 2021 · 8,974 citations
  4. Deberta: decoding-Enhanced Bert with Disentangled AttentionPengcheng He, Xiaodong Liu, Jianfeng Gao, Weizhu ChenICLR 2021 · 3,729 citations
  5. Reformer: The Efficient TransformerNikita Kitaev, Lukasz Kaiser, Anselm LevskayaICLR 2020 · 2,878 citations

Related papers

  1. Conv-Basis: A New Paradigm for Efficient Attention Inference and Gradient Computation in TransformersYingyu Liang, Heshan Liu, Zhenmei Shi, Zhao Song et al.EMNLP Findings 2025
  2. Long-range Sequence Modeling with Predictable Sparse AttentionYimeng Zhuang, Jing Zhang, Mei TuACL 2022 · 11 citations
  3. Learnable Fourier Features for Multi-dimensional Spatial Positional EncodingYang Li, Si Si, Gang Li, Cho-Jui Hsieh et al.NeurIPS 2021 · 171 citations
  4. Toeplitz Neural Network for Sequence ModelingZhen Qin, Xiaodong Han, Weixuan Sun, Bowen He et al.ICLR 2023 · 5 citations
  5. Fourier Transformer: Fast Long Range Modeling by Removing Sequence Redundancy with FFT OperatorZiwei He, Meng Yang, Minwei Feng, Jingcheng Yin et al.ACL Findings 2023 · 13 citations
Dusk over the sea between two cliffs drawn in fine vertical lines