RWKV: Reinventing RNNs for the Transformer Era

Bo Peng, Eric Alcaide, Quentin Anthony, Alon Albalak, Samuel Arcadinho, Stella Biderman, Huanqi Cao, et al.

2023 · EMNLP Findings

RWKV: Reinventing RNNs for the Transformer Era

Problem

Framing

Transformers train well but pay O(T2)O(T^2) memory and compute during inference over long contexts. RWKV closes this gap with a recurrent reformulation of attention-like mixing that stays parallel during training and linear at inference, while remaining competitive with similarly sized LMs on Pile-trained zero-shot benchmarks.

Currently Used Methods

Foundational

Proposed Method

Architecture

RWKV stacks pre-norm residual blocks with two sublayers: Time Mixing and Channel Mixing. Time Mixing computes receptance, key, value, and a decayed weighted key-value aggregation; Channel Mixing is a gated feed-forward block with token shift.

RWKV residual block with LayerNorm, Time Mixing, Channel Mixing, and a final LM head with Softmax.

Loss / Objective

The model trains with standard next-token cross-entropy.

L=t=1Tlogpθ(xtx<t)\mathcal{L} = - \sum_{t=1}^{T} \log p_\theta(x_t \mid x_{<t})

Sampling Rule / Algorithm

Autoregressive inference updates a recurrent WKV state and emits the next-token distribution from the LM head.

WKVt=i=1te(ti)w+kivii=1te(ti)w+ki,ot=σ(rt)WKVt\operatorname{WKV}_t = \frac{\sum_{i=1}^{t} e^{-(t-i)\mathbf{w} + \mathbf{k}_i} \odot \mathbf{v}_i}{\sum_{i=1}^{t} e^{-(t-i)\mathbf{w} + \mathbf{k}_i}}, \qquad \mathbf{o}_t = \sigma(\mathbf{r}_t) \odot \operatorname{WKV}_t

Training Procedure

Evaluation

Datasets

Metrics

Headline results

Ablations

Method Strengths and Weaknesses

Strengths

Weaknesses

Suggestions from the authors

Links

Prior Papers

Further Papers