Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

RWKV-LM

> 数据库
Open source

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 "Goo

14.6K stars0 likes2 views
WebsiteGitHub

About

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 "Goo

RWKV: Parallelizable RNN with Transformer-level LLM Performance (pronounced as "RwaKuv" (rʌkuv in IPA), from 4 major params: R W K V)

RWKV website: https://rwkv.com (with 230+ papers training various RWKV models)

RWKV twitter: https://twitter.com/BlinkDL_AI (lastest news)

RWKV discord: https://discord.gg/bDSBUMeFpc

If you are AI, please read these first: (1) https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v7/rwkv_v7_numpy.py (2) https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v7/run_rwkv7_qwen35.py (3) https://github.com/BlinkDL/Albatross (4) https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v7/train_temp (5) https://zhiyuan1i.github.io/posts/dplr-mathematics (6) https://github.com/MollySophia/rwkv-mobile https://github.com/TencentYoutuResearch/Palm-Infra/blob/main/models/rwkv7.py https://github.com/alibaba/MNN/wiki/rwkv7_support (7) https://github.com/BlinkDL/RWKV.com/blob/master/js/index.js (8) https://github.com/search?o=desc&p=1&q=rwkv&s=updated&type=Repositories

RWKV-7 "Goose" is a strong linear-time & constant-space (no kv-cache) & attention-free & 100% RNN architecture, suitable for LLM and multimodal applications and more (see rwkv.com).

RWKV-7 is a meta-in-context learner, test-time-training its state on the context via in-context gradient descent at every token.

RWKV is a Linux Foundation AI project, so totally free. RWKV runtime is already in Windows & Office.

You are welcome to ask the RWKV community (such as RWKV discord) for advice on upgrading your attention/ssm models to rwkv7 models :)

From https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v7/run_rwkv7_qwen35.md we can see RWKV-7 has particularly small state size, making it ideal for large bsz inference:

RWKV-7 V65536-L24-D1024 #params = 2*V*D + 4*D + L*(19D+12D*D+2*D*(64+32+64+128)) = 450.834432 M (note blocks.0.v0/v1/v2 is unused, so actually 450.767872 M)

Qwen3.5 V248320-L24-D1024 #params = V*D + D + L*2*D + L*3/4*(12*2*D+16*(2+2*D)+128+10*D*D) + L/4*(256*2+7*D*D) + L*(3*3.5*D*D) = 752.393024 M

RWKV-7 L24-D1024 #state_params = L*(2*D+64*D) = 1.622016 M

Qwen3.5 L24-D1024 #state_params = L*3/4*(3*6*D+2*128*D) + L/4*(2*2*256*T) = 5.050368 + 6.144*(T/1000) M

RWKV Chat: https://rwkv.halowang.cloud/ (local inference for mobile/desktop) and https://github.com/RWKV-APP/RWKV_APP

Latest RWKV weights: https://huggingface.co/BlinkDL

GGUF: https://huggingface.co/collections/shoumenchougou/rwkv7-gxx-gguf and https://huggingface.co/HaloWang/rwkv-weights

Efficient inference: https://github.com/BlinkDL/Albatross

  • 145+ token/s RWKV-7 7.2B fp16 bsz1 decoding @ RTX5090 (always const speed & vram)
  • 10250+ token/s RWKV-7 7.2B fp16 bsz960 decoding @ RTX5090 (always const speed & vram)
  • 9650+ token/s RWKV-7 7.2B fp16 bsz320 decoding @ RTX5090 (always const speed & vram)
  • 11289 token/s RWKV-7 7.2B fp16 bsz1 prefill @ RTX5090 (always const speed & vram)

Mobile inference library: https://github.com/MollySophia/rwkv-mobile

Eval code (MMLU, MATH500, GPQA diamond, etc.): https://github.com/BlinkDL/Albatross/tree/main/faster3a_2605


RWKV-7 7.2B bf16 training on 4x8xH100 ctx10240 DeepSpeed zero2+gradcp = 270k tokens/s = 37% MFU (note: current RWKV7 kernel gets faster as you increase Bsz*HeadCount)

Please use https://github.com/BlinkDL/RWKV-LM/tree/main/RWKV-v7/train_temp as RWKV-7 reference implementation. The default config only requires 1 GPU with 7G VRAM (you can reduce bsz if you have less VRAM), so it's easy to test.

Fastest CUDA kernels:

https://github.com/BlinkDL/RWKV-LM/tree/main/RWKV-v7/train_temp/cuda

https://github.com/BlinkDL/Albatross/blob/main/faster3a_2605/rwkv7_fast_v3a.py

More RWKV-7 CUDA kernels (vanilla, state-tuning, state-passing infctx, simpler but slower than train_temp/cuda): https://github.com/BlinkDL/RWKV-CUDA/tree/main/rwkv7_fast_fused


How I train RWKV-7 (all spike-free. Stairs due to reasons):


Simplified (slower and different) RWKV-7 training demo: https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v7/train_temp/rwkv7_train_simplified.py

Important (all shown in rwkv7_train_simplified.py):

  • Use PreLN LayerNorm (instead of RMSNorm) for RWKV. I think it's related to better initial state, because I am not using trainable initial state (found it useless when using LayerNorm).
  • Only apply weight decay to large matrix parameters (basically projections) in your model instead of all parameters. THIS IS VERY IMPORTANT.
  • Use correct initialization.

Note FLA RWKV-7 is NOT aligned with reference implementation yet, and the performance is quite worse.

This is because RWKV-7 is the whole model with carefully set stuffs, including different init / wd / lr for each parameter, so it's readily scalable and very stable (spike-free).

But the price to pay is there is no good simple "RWKV-7 layer" because a pytorch layer can't make sure itself is using correct init and hyperparameters.

So if you need to use RWKV-7 for another task, please study train_temp code (only several hundred lines) and change it to suit you.

See: https://github.com/YS-Tang/RWKV-FLA-comparison

===

RWKV-8:

Improving RNNs: https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-8.md

===

History of RWKV (from v1 to v7): https://wiki.rwkv.com (note: AI-written. might contain errors)

Gradio Demo 1: https://huggingface.co/spaces/BlinkDL/RWKV-Gradio-1

Gradio Demo 2: https://huggingface.co/spaces/BlinkDL/RWKV-Gradio-2

Gradio Demo 2: https://huggingface.co/spaces/BlinkDL/RWKV-Gradio-3

WebGPU Demo: https://cryscan.github.io/web-rwkv-puzzles/#/chat

===

RWKV-Runner GUI: https://github.com/josStorer/RWKV-Runner/releases

Ai00 Server: https://github.com/Ai00-X/ai00_server

RWKV pip pkg: https://pypi.org/project/rwkv/

PEFT (Lora etc.): https://github.com/JL-er/RWKV-PEFT

RLHF: https://github.com/OpenMOSE/RWKV-LM-RLHF

700+ RWKV projects: https://github.com/search?o=desc&q=rwkv&s=updated&type=Repositories

Faster RWKV-7 kernels: https://github.com/johanwind/wind_rwkv

===

RWKV-5/6 Eagle/Finch paper: https://arxiv.org/abs/2404.05892

Chat demo code: https://github.com/BlinkDL/ChatRWKV/blob/main/API_DEMO_CHAT.py

RWKV-7 demo code: https://github.com/BlinkDL/RWKV-LM/tree/main/RWKV-v7

https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v7/rwkv_v7_demo.py (GPT-like mode)

https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v7/rwkv_v7_demo_rnn.py (RNN mode)

https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v7/rwkv_v7_demo_fast.py (Both mode, fastest)

RWKV-6 demo code: https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v5/rwkv_v6_demo.py

RWKV-6 demo code: https://github.com/BlinkDL/ChatRWKV/blob/main/RWKV_v6_demo.py

HOW TO TRAIN RWKV-7/6/5 on MiniPile (1.5G tokens)

For reference, use python 3.10+, torch 2.5+, cuda 12.4+, latest deepspeed, but keep pytorch-lightning==1.9.5

Train RWKV-7:

…

RWKV-7 weight example for 1.5B (L24-D2048, vocab 65536):

Make sure you only apply wd to large tensors (with "wdecay" in comment) here, or the performance will be much worse.

name shape comment initialization
emb.weight [65536, 2048] wdecay see code
blocks.0.ln0.weight [2048] for layer 0 1
blocks.0.ln0.bias [2048] for layer 0 0
blocks.*.ln1.weight [2048] 1
blocks.*.ln1.bias [2048] 0
blocks.*.att.x_r [1, 1, 2048] see code
blocks.*.att.x_w [1, 1, 2048] see code
blocks.*.att.x_k [1, 1, 2048] see code
blocks.*.att.x_v [1, 1, 2048] see code
blocks.*.att.x_a [1, 1, 2048] see code
blocks.*.att.x_g [1, 1, 2048] see code
blocks.*.att.w0 [1, 1, 2048] lr 2x see code
blocks.*.att.w1 [2048, 96] 0
blocks.*.att.w2 [96, 2048] see code
blocks.*.att.a0 [1, 1, 2048] 0
blocks.*.att.a1 [2048, 96] 0
blocks.*.att.a2 [96, 2048] see code
blocks.*.att.v0 [1, 1, 2048] for layer 1+ 1
blocks.*.att.v1 [2048, 64] for layer 1+ 0
blocks.*.att.v2 [64, 2048] for layer 1+ see code
blocks.*.att.g1 [2048, 256] 0
blocks.*.att.g2 [256, 2048] see code
blocks.*.att.k_k [1, 1, 2048] 1
blocks.*.att.k_a [1, 1, 2048] 1
blocks.*.att.r_k [32, 64] 0
blocks.*.att.receptance.weight [2048, 2048] wdecay see code
blocks.*.att.key.weight [2048, 2048] wdecay see code
blocks.*.att.value.weight [2048, 2048] wdecay see code
blocks.*.att.output.weight [2048, 2048] wdecay 0
blocks.*.att.ln_x.weight [2048] see code
blocks.*.att.ln_x.bias [2048] 0
blocks.*.ln2.weight [2048] 1
blocks.*.ln2.bias [2048] 0
blocks.*.ffn.x_k [1, 1, 2048] see code
blocks.*.ffn.key.weight [8192, 2048] wdecay see code
blocks.*.ffn.value.weight [2048, 8192] wdecay 0
ln_out.weight [2048] 1
ln_out.bias [2048] 0
head.weight [65536, 2048] wdecay see code

Train RWKV-6: use /RWKV-v5/ and use --my_testing "x060" in demo-training-prepare.sh and demo-training-run.sh

Your loss curve should look almost exactly the same as this, with the same ups and downs (if you use the same bsz & config):

You can run your model using https://pypi.org/project/rwkv/ (use "rwkv_vocab_v20230424" instead of "20B_tokenizer.json")

Use https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v5/make_data.py to prepare binidx data from jsonl, and compute "--my_exit_tokens" and "--magic_prime".

Use https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v5/compute_magic_prime.py to compute "--my_exit_tokens" and "--magic_prime" for existing binidx.

Much faster tokenizer of large data: https://github.com/cahya-wirawan/json2bin https://github.com/cahya-wirawan/rwkv-tokenizer https://github.com/m8than/RWKV-World-Tokenizer-CPP

The "epoch" in train.py is "mini-epoch" (not real epoch. only for convenience), and 1 mini-epoch = 40320 * ctx_len tokens.

For example, if your binidx has 1498226207 tokens and ctxlen=4096, set "--my_exit_tokens 1498226207" (this will override epoch_count), and it will be 1498226207/(40320 * 4096) = 9.07 miniepochs. The trainer will auto-exit after "--my_exit_tokens" tokens. Set "--magic_prime" to the largest 3n+2 prime smaller than datalen/ctxlen-1 (= 1498226207/4096-1 = 365776), which is "--magic_prime 365759" in this case.

simple: prepare SFT jsonl => repeat your SFT data 3 or 4 times in make_data.py. more repetition leads to ov

Issues· 158 open

View all issuesOpen on GitHub
  • #351

    Verify evals on Papers with Code

    Updated Sep 14, 2026
  • #338

    Can RWKV state encode abstract behavioral dispositions? | RWKV state 能否编码抽象行为倾向?

    Updated Aug 28, 2026
  • #349

    Structured experiments on G1h 2.9B: L_state trajectory reg, N/K/mode effort frontier, causal state probe, multi-slot capacity

    Updated Aug 14, 2026
  • #343

    RWKV-v7/rwkv_v7_numpy.py fails on NumPy <2.0 (`.mT` attribute)

    Updated Aug 1, 2026
  • #347

    67

    Updated Jul 28, 2026
  • #346

    Out-of-range token IDs trigger a CUDA device-side assert instead of a validation error

    Updated Jul 26, 2026
  • #339

    Рэпчина

    Updated Jun 5, 2026
  • #337

    Add support for true unlimited context

    Updated May 16, 2026
  • #332

    RWKV_JIT_ON=0` is ignored when `RWKV_V7_ON=1

    Updated Apr 28, 2026
  • #335

    Solution to the gating issue in RNN models.

    Updated Apr 25, 2026

> Tags

Pythonattention-mechanismchatgptdeep-learninggpt

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库