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.

Metadata

Release files for rwkv-tl 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rwkv-tl 0.2.1
File Size Uploaded Provenance Actions
rwkv_tl-0.2.1.tar.gz 442.9 kB Without provenance Details for rwkv_tl-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rwkv-tl 0.2.1
File Interpreter ABI Platform Actions
rwkv_tl-0.2.1-py3-none-any.whl Python 3 none any Details for rwkv_tl-0.2.1-py3-none-any.whl

Total release size: 892.6 kB

Release files / rwkv_tl-0.2.1.tar.gz

Download URL rwkv_tl-0.2.1.tar.gz
Size 442.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c7ce70fc5b48a6d15c78756324c651ee9e485d4bf3154641a79c5952119b09a0
BLAKE2b-256 checksum
How to use checksums
bb7a679c2e023136efc04d44456454ba4ae8493646a2db6c754abf804020e17f
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / rwkv_tl-0.2.1-py3-none-any.whl

Download URL rwkv_tl-0.2.1-py3-none-any.whl
Size 449.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1947357857d9bb18dad27a3b74ca271773c0d258b214c4c01c2df788a0ba68f
BLAKE2b-256 checksum
How to use checksums
2f1526752333d275a2092be4c5c3f2fc7df9f4b3742022f7bf7ba94d2d3b8afe
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for rwkv-tl 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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