
rwkv
Language12,115 ops169.3M params
An attention-free RNN that trains like a GPT and runs with constant memory per token.
Language · 6,060 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
About this model's family
RWKV, short for Receptance Weighted Key Value, is a language model that trains in parallel like a Transformer but runs like a recurrent network. The motivation is the usual trade: Transformers scale quadratically in memory and compute with sequence length, while RNNs scale linearly but have lagged in performance and parallelism. RWKV uses a linear attention mechanism that can be written either as a Transformer or as an RNN, so training is parallel and inference keeps constant compute and memory per token. The paper scales it to 14 billion parameters, which it calls by far the largest dense RNN ever trained, and finds it on par with similarly sized Transformers.
The name comes from the four elements inside every block: Receptance, Weight, Key and Value. The model is a stack of residual blocks, each with a time-mixing sub-block and a channel-mixing sub-block. A small quirk is the token shift: the projections for R, K and V are formed by linear interpolation between the current and previous timestep inputs. The design was inspired by the Attention Free Transformer, with the interaction weights changed so the whole thing can be transformed into an RNN. Each weight is a channelwise time decay multiplied by relative position and traced backward from the current time.
The README puts it plainly: RWKV is an RNN with Transformer-level LLM performance that can be trained like a GPT, and it is 100% attention-free. Parallel training works because the time-decay of each channel is data-independent and trainable. The traced members are the RWKV-4 causal language model from the transformers library at two small configurations. The repository says the name is pronounced RwaKuv.
Key idea. RWKV reformulates attention as a linear, channelwise time-decay recurrence so one model can be trained in parallel like a Transformer and run as an RNN with constant per-token cost, scaling to 14 billion parameters.
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
@misc{peng2023rwkvreinventingrnnstransformer,
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},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2305.13048},
}