LongNet: Scaling Transformers to 1,000,000,000 Tokens

Jiayu Ding, Shuming Ma, Li Dong, Xingxing Zhang, Shaohan Huang +3 more
7/5/2023
cs.CLcs.LG

Official code: microsoft/unilm (22,168 stars, MIT, last commit 2026-01-23). 3 more implementations below.

Abstract

Scaling sequence length has become a critical demand in the era of large language models. However, existing methods struggle with either computational complexity or model expressivity, rendering the maximum sequence length restricted. To address this issue, we introduce LongNet, a Transformer variant that can scale sequence length to more than 1 billion tokens, without sacrificing the performance on shorter sequences. Specifically, we propose dilated attention, which expands the attentive field exponentially as the distance grows. LongNet has significant advantages: 1) it has a linear computation complexity and a logarithm dependency between any two tokens in a sequence; 2) it can be served as a distributed trainer for extremely long sequences; 3) its dilated attention is a drop-in replacement for standard attention, which can be seamlessly integrated with the existing Transformer-based optimization. Experiments results demonstrate that LongNet yields strong performance on both long-sequence modeling and general language tasks. Our work opens up new possibilities for modeling very long sequences, e.g., treating a whole corpus or even the entire Internet as a sequence.

View on arXivView PDF

Code Implementations(4)

microsoft/unilmOfficial100%
MIT

Large-scale Self-supervised Pre-training Across Tasks, Languages, and Modalities

22,1682,703C, C++Jul 23, 20199 months agoMIT
beitbeit-3bitnetdeepnetdocument-ai+15 more
kyegomez/LongNetCommunity68%
Apache-2.0

Implementation of plug in and play Attention from "LongNet: Scaling Transformers to 1,000,000,000 Tokens"

72261PythonJul 6, 20232 years agoApache-2.0
artificial-intelligenceattentionattention-is-all-you-needattention-mechanismschatgpt+5 more
MIT

(Unofficial) Implementation of dilated attention from "LongNet: Scaling Transformers to 1,000,000,000 Tokens" (https://arxiv.org/abs/2307.02486)

528PythonJul 9, 20233 years agoMIT
MIT

Implementation of the dilated self attention as described in "LongNet: Scaling Transformers to 1,000,000,000 Tokens"

130PythonJul 9, 20233 years agoMIT

Similar Papers

Cite this paper

@article{ding2023longnet,
  title  = {LongNet: Scaling Transformers to 1,000,000,000 Tokens},
  author = {Jiayu Ding and Shuming Ma and Li Dong and Xingxing Zhang and Shaohan Huang and Wenhui Wang and Nanning Zheng and Furu Wei},
  year   = {2023},
  eprint = {2307.02486},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2307.02486v2}
}

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/2307.02486.svg)](https://codeofpaper.com/paper/2307.02486)

Discussion