Retentive Network: A Successor to Transformer for Large Language Models

Yutao Sun, Li Dong, Shaohan Huang, Shuming Ma, Yuqing Xia +3 more
7/17/2023
839 citations
cs.CLcs.LG
transformer-attention

Official code: microsoft/unilm (22,252 stars, Python, MIT, last commit 2026-01-23). 1 more implementation below.

Abstract

In this work, we propose Retentive Network (RetNet) as a foundation architecture for large language models, simultaneously achieving training parallelism, low-cost inference, and good performance. We theoretically derive the connection between recurrence and attention.

Show full abstract

Then we propose the retention mechanism for sequence modeling, which supports three computation paradigms, i.e., parallel, recurrent, and chunkwise recurrent. Specifically, the parallel representation allows for training parallelism. The recurrent representation enables low-cost $O(1)$ inference, which improves decoding throughput, latency, and GPU memory without sacrificing performance. The chunkwise recurrent representation facilitates efficient long-sequence modeling with linear complexity, where each chunk is encoded parallelly while recurrently summarizing the chunks. Experimental results on language modeling show that RetNet achieves favorable scaling results, parallel training, low-cost deployment, and efficient inference. The intriguing properties make RetNet a strong successor to Transformer for large language models. Code will be available at https://aka.ms/retnet.

View on arXivView PDF

Code Implementations(2)

Code implementations of this paper
RepositoryTypeStarsLanguageLicenseLast commit
microsoft/unilmOfficial22,252PythonMIT2026-01-23
fkodom/yet-another-retnetCommunity105PythonMIT2023-11-24
microsoft/unilmOfficial69%
MIT

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

22,2522,699Python, Jupyter NotebookJul 23, 201910 months agoMIT
beitbeit-3bitnetdeepnetdocument-ai+15 more
PyTorchMIT

A simple but robust PyTorch implementation of RetNet from "Retentive Network: A Successor to Transformer for Large Language Models" (https://arxiv.org/pdf/2307.08621.pdf)

10517PythonAug 1, 20233 years agoMIT
deep-learningllmsmachine-learningnatural-language-processingneural-networks+2 more

Similar Papers

Cite this paper

@article{sun2023retentive,
  title  = {Retentive Network: A Successor to Transformer for Large Language Models},
  author = {Yutao Sun and Li Dong and Shaohan Huang and Shuming Ma and Yuqing Xia and Jilong Xue and Jianyong Wang and Furu Wei},
  year   = {2023},
  eprint = {2307.08621},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2307.08621v4}
}

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

Discussion