RWKV: Reinventing RNNs for the Transformer Era

Bo Peng, Eric Alcaide, Quentin Anthony, Alon Albalak, Samuel Arcadinho +29 more
5/22/2023
cs.CLcs.AI

No official code found. Best implementation: BlinkDL/RWKV-LM (14,742 stars, Apache-2.0, PyTorch, last commit 2026-04-28). 1 more below.

Abstract

Transformers have revolutionized almost all natural language processing (NLP) tasks but suffer from memory and computational complexity that scales quadratically with sequence length. In contrast, recurrent neural networks (RNNs) exhibit linear scaling in memory and computational requirements but struggle to match the same performance as Transformers due to limitations in parallelization and scalability. We propose a novel model architecture, Receptance Weighted Key Value (RWKV), that combines the efficient parallelizable training of transformers with the efficient inference of RNNs. Our approach leverages a linear attention mechanism and allows us to formulate the model as either a Transformer or an RNN, thus parallelizing computations during training and maintains constant computational and memory complexity during inference. We scale our models as large as 14 billion parameters, by far the largest dense RNN ever trained, and find RWKV performs on par with similarly sized Transformers, suggesting future work can leverage this architecture to create more efficient models. This work presents a significant step towards reconciling trade-offs between computational efficiency and model performance in sequence processing tasks.

View on arXivView PDF

Code Implementations(2)

BlinkDL/RWKV-LMCommunity100%
PyTorchApache-2.0

RWKV (pronounced RwaKuv) is an RNN with great LLM performance, which can also be directly trained like a GPT transformer (parallelizable). We are at RWKV-7 "Goose". So it's combining the best of RNN and transformer - great performance, linear time, constant space (no kv-cache), fast training, infinite ctx_len, and free sentence embedding.

14,7421,022C++, CudaAug 8, 20215 months agoApache-2.0
attention-mechanismchatgptdeep-learninggptgpt-2+9 more
BlinkDL/ChatRWKVCommunity100%
PyTorchApache-2.0

ChatRWKV is like ChatGPT but powered by RWKV (100% RNN) language model, and open source.

9,494685C++, CudaJan 13, 20238 months agoApache-2.0
chatbotchatgptlanguage-modelpytorchrnn+1 more

Similar Papers

Cite this paper

@article{peng2023rwkv,
  title  = {RWKV: Reinventing RNNs for the Transformer Era},
  author = {Bo Peng and Eric Alcaide and Quentin Anthony and Alon Albalak and Samuel Arcadinho and Stella Biderman and Huanqi Cao and Xin Cheng and Michael Chung and Matteo Grella and Kranthi Kiran GV and Xuzheng He and Haowen Hou and Jiaju Lin and Przemyslaw Kazienko and Jan Kocon and Jiaming Kong and Bartlomiej Koptyra and Hayden Lau and Krishna Sri Ipsit Mantri and Ferdinand Mom and Atsushi Saito and Guangyu Song and Xiangru Tang and Bolun Wang and Johan S. Wind and Stanislaw Wozniak and Ruichong Zhang and Zhenyuan Zhang and Qihang Zhao and Peng Zhou and Qinghua Zhou and Jian Zhu and Rui-Jie Zhu},
  year   = {2023},
  eprint = {2305.13048},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2305.13048v2}
}

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

Discussion