Skip to main content

rwkv-tl

An RWKV7 operator library (built on TileLang) plus ready-to-use stateless models. Import the package, point it at a checkpoint, and generate:

import rwkv_tl

model = rwkv_tl.rwkv7("model-0.4b.pth")          # tilelang on CUDA, torch elsewhere
out = model.generate("Once upon a time", max_tokens=128)
print(out)

Everything is stateless: models never own runtime state. Pass a State in and (optionally) get it back, or let generate create a fresh one.

User API

Build a model from a checkpoint path (or a pre-loaded RWKV7Weight):

model = rwkv_tl.rwkv7("model.pth")                       # backend auto-selected
model = rwkv_tl.rwkv7("model.pth", backend="torch")      # pure-PyTorch reference
model = rwkv_tl.RWKV7TL("model.pth")                     # explicit tilelang class

Text in, text out:

text = model.generate("The meaning of life is",
                      max_new_tokens=64, temperature=0.8, stop="\n\n")

Chat (messages through the packaged chat template):

answer = model.chat([
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is the capital of France?"},
], max_new_tokens=128)

Demo

examples/ holds runnable walk-throughs: basic_load_and_generate.py loads a checkpoint and generates text, chat.py chats through the template:

.venv/bin/python examples/basic_load_and_generate.py /path/to/rwkv7-0.1b.pth
.venv/bin/python examples/chat.py /path/to/rwkv7-0.1b.pth

Operator library

rwkv_tl.kernel is a TileLang operator library for building efficient RWKV implementations. Every factory is weight-bound: it takes the compile-time hyperparameters and the weights at construction and returns a callable that only needs activations/state at call time:

from rwkv_tl.kernel import ln_kernel, gemv_kernel

ln_pre = ln_kernel(C, DTYPE, ln_preW, ln_preB)   # weights captured here
x_ln = ln_pre(x0)                                 # call with activations only

Both granularities are supported:

  • Fine-grained composable operators: ln_kernel, ln_per_row_kernel, gemv_kernel, gemv_batch_kernel.
  • Coarse fused layer kernels: cmix_decode_kernel, cmix_prefill_kernel, tmix_decode_kernel, tmix_prefill_kernel.

The raw @tilelang.jit factories and shared macros (gemv_macro, gemv_main_macro, ...) remain available for custom fused chains. Weights are held by the wrapper, which is the hook for a future quantized-weight path (int8/any4 storage + dequant fused into the kernels).

Layout

src/rwkv_tl/        # published library: models, State, Tokenizer, kernel/
  core/             # low-level/inference modules (model/state/tokenizer/
                    # weight/cuda_graph); no references outside core
  kernel/           # weight-bound tilelang operator factories
  text_model.py     # RWKV7TextModel (exposed): composes a token model
                    # (self.model) + tokenizer; tokenize/generate/chat
  rwkv7_tl.py       # tilelang fused model
  rwkv7_torch.py    # pure-PyTorch reference model
  asset/            # packaged data: vocab + chat template
script/             # chat, benchmark, profiling scripts
examples/           # runnable usage examples
test/               # correctness and API tests
docs/               # benchmark reports and tuning notes (Chinese)

Install and test

cd rwkv-tl
uv sync
.venv/bin/python -m pytest test/ -v

Kernel correctness tests need CUDA and RWKV_CHECKPOINT_PATH:

RWKV_CHECKPOINT_PATH=/path/to/rwkv7-g1d-0.1b.pth .venv/bin/python -m pytest test/ -v

The user-facing text API and the pure-torch backend also run on CPU.

script/check_torch_vs_official.py additionally validates the pure-torch backend against the official RWKV-LM v7 demo (pure-torch path) on the same checkpoint — logits must agree on argmax and top-5 for batched and per-token decode:

.venv/bin/python script/check_torch_vs_official.py /path/to/rwkv7-0.1b.pth \
  --fast-path /path/to/RWKV-LM/RWKV-v7/rwkv_v7_demo.py

Performance

Decode and prefill use fused tilelang kernels with fp16 compute and fp32 accumulation (DPLR state stays fp32), CUDA-Graph accelerated on CUDA by default. Current numbers vs the Albatross reference implementation are in docs/runs/rtx3060.md (RTX 3060, the current target card). script/bench_tl_vs_torch.py measures tl vs pure-torch on CUDA (prefill sweep + decode), and script/bench_tl_vs_fast.py compares tl against the Albatross faster3a_2607 reference implementation.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rwkv_tl-0.2.1.tar.gz (442.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rwkv_tl-0.2.1-py3-none-any.whl (449.7 kB view details)

Uploaded Python 3

File details

Details for the file rwkv_tl-0.2.1.tar.gz.

File metadata

  • Download URL: rwkv_tl-0.2.1.tar.gz
  • Upload date:
  • Size: 442.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for rwkv_tl-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c7ce70fc5b48a6d15c78756324c651ee9e485d4bf3154641a79c5952119b09a0
MD5 18543a4455e4fce7baeae5ffdb1c205a
BLAKE2b-256 bb7a679c2e023136efc04d44456454ba4ae8493646a2db6c754abf804020e17f

See more details on using hashes here.

File details

Details for the file rwkv_tl-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: rwkv_tl-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 449.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for rwkv_tl-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1947357857d9bb18dad27a3b74ca271773c0d258b214c4c01c2df788a0ba68f
MD5 1a7bfa9bc399890aec5c6c42e2a0ad90
BLAKE2b-256 2f1526752333d275a2092be4c5c3f2fc7df9f4b3742022f7bf7ba94d2d3b8afe

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page