Luna: Linear Unified Nested Attention

Xuezhe Ma, Xiang Kong, Sinong Wang, Chunting Zhou, Jonathan May +2 more
6/3/2021
150 citations
cs.LGcs.CL
transformer-attention

Official code: XuezheMax/fairseq-apollo (113 stars, Python, MIT, last commit 2023-12-20).

Abstract

The quadratic computational and memory complexities of the Transformer's attention mechanism have limited its scalability for modeling long sequences. In this paper, we propose Luna, a linear unified nested attention mechanism that approximates softmax attention with two nested linear attention functions, yielding only linear (as opposed to quadratic) time and space complexity.

Show full abstract

Specifically, with the first attention function, Luna packs the input sequence into a sequence of fixed length. Then, the packed sequence is unpacked using the second attention function. As compared to a more traditional attention mechanism, Luna introduces an additional sequence with a fixed length as input and an additional corresponding output, which allows Luna to perform attention operation linearly, while also storing adequate contextual information. We perform extensive evaluations on three benchmarks of sequence modeling tasks: long-context sequence modeling, neural machine translation and masked language modeling for large-scale pretraining. Competitive or even better experimental results demonstrate both the effectiveness and efficiency of Luna compared to a variety

View on arXivView PDF

Code Implementations(1)

MIT

FairSeq repo with Apollo optimizer

11315Python, CudaAug 19, 20202 years agoMIT

Similar Papers

Cite this paper

@article{ma2021luna,
  title  = {Luna: Linear Unified Nested Attention},
  author = {Xuezhe Ma and Xiang Kong and Sinong Wang and Chunting Zhou and Jonathan May and Hao Ma and Luke Zettlemoyer},
  year   = {2021},
  eprint = {2106.01540},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2106.01540}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2106.01540.svg)](https://codeofpaper.com/paper/2106.01540)

Discussion