web-rwkv
Library Listed
An implementation of the RWKV language model in pure WebGPU.
- Downloads
- 444
- Dependents
- 3
- Stars
- 360
- Forks
- 36
- Contributors
- 6
- Commits
- 711
- Latest release
- 0.10.20 ·
About


This is an inference engine for the language model of RWKV implemented in pure WebGPU.
Features
- No dependencies on CUDA/Python.
- Support Nvidia/AMD/Intel GPUs, including integrated GPUs.
- Vulkan/Dx12/OpenGL backends.
- WASM support (can run in browser).
- Batched inference.
- Int8 and Float4 quantization.
- Very fast.
- LoRA merging at loading time.
- Support RWKV V4 through V7.
- Hooks to intervene the inference process at any point.
- Model (de)serialization.

Note that web-rwkv is only an inference engine. It only provides the following functionalities:
- A tokenizer.
- Model loading.
- State creation and updating.
- Model implements
runfunction that takes in prompt tokens and returns logits, and asoftmaxfunction that turns logits into predicted next token probabilities. Both of them are executed on GPU. - Model quantization and (de)serialization.
- WASM bindings.
It does not provide the following:
Read the full README
- OpenAI API or APIs of any kind.
- If you would like to deploy an API server, check AI00 RWKV Server which is a fully-functional OpenAI-compatible API server built upon
web-rwkv. - You could also check the
web-rwkv-axumproject if you want some fancy inference pipelines, including Classifier-Free Guidance (CFG), Backus–Naur Form (BNF) guidance, and more.
- If you would like to deploy an API server, check AI00 RWKV Server which is a fully-functional OpenAI-compatible API server built upon
- Samplers, though in the examples a basic nucleus sampler is implemented, this is not included in the library itself.
- State caching or management system.
- Python bindings.
For devs: Check the slides for technique details about the architecture, history and optimizations.
Compile
- Install Rust.
- Download the model from HuggingFace, and convert it using
convert_safetensors.py. Put the.stmodel underassets/models. - Compile
$ cargo build --release --examples
Examples
Performance Test
The test generates 500 tokens and measure the time cost.
$ cargo run --release --example gen
Chat Demo
To chat with the model, run
$ cargo run --release --example chat
In this demo, type + to retry last round's generation; type - to exit.
To specify the location of your safetensors model, use
$ cargo run --release --example chat -- --model /path/to/modelTo load custom prompts for chat, use
$ cargo run --release --example chat -- --prompt /path/to/promptSee
assets/prompt.jsonfor details.To specify layer quantization, use
--quant <LAYERS>or--quant-nf4 <LAYERS>to quantize the first<LAYERS>layers. For example, use$ cargo run --release --example chat -- --quant 32to quantize all 32 layers.
Batched Inference
This demo showcases generation of 4 batches of text with various lengths simultaneously.
$ cargo run --release --example batch
Inspector
The inspector demo is a guide to an advanced usage called hooks. Hooks allow user to inject any tensor ops into the model's inference process, fetching and modifying the contents of the runtime buffer, state, and even the model parameters. Hooks enable certain third-party implementations like dynamic LoRA, control net, and so on.
(De)serialization
All versions of models implements serde::ser::Serialize and serde::de::DeserializeSeed<'de>, which means that one can save quantized or lora-merged model into a file and load it afterwards.
Use in Your Project
To use in your own rust project, simply add web-rwkv = "0.10" as a dependency in your Cargo.toml.
Check examples on how to create the environment, the tokenizer and how to run the model.
Explanations
Inference Runtime
Since v0.7 there is a runtime feature for the crate. When enabled, applications can use infrastructures of the asynchronous runtime API.
In general, a runtime is an asynchronous task that is driven by tokio. It allows CPU and GPU to work in parallel, maximizing the utilization of GPU computing resource.
Check examples starting with rt for more information, and compare the generation speed with their non-rt counterparts.
Batched Inference
Since version v0.2.4, the engine supports batched inference, i.e., inference of a batch of prompts (with different length) in parallel.
This is achieved by a modified WKV kernel.
When building the model, the user specifies token_chunk_size (default: 32, but for powerful GPUs this could be much higher), which is the maximum number of tokens the engine could process in one run call.
After creating the model, the user creates a ModelState with num_batch specified.
This means that there are num_batch slots that could consume the inputs in parallel.
Before calling run(), the user fills each slot with some tokens as prompt.
If a slot is empty, no inference will be run for it.
After calling run(), some (but may not be all) input tokens are consumed, and logits appears in their corresponding returned slots if the inference of that slot is finished during this run.
Since there are only token_chunk_size tokens are processed during each run() call, there may be none of logits appearing in the results.
Hooks
Hooks are a very powerful tool for customizing model inference process.
The library provides with the Model::run_with_hooks function, which takes into a HookMap as a parameter.
- A
HookMapis essentially a hashmap fromModel::Hookto functions. - A
Model::Hookdefines a certain place the hook function can be injected into. A model generally has dozens of hooking points. - A hook function is a function of
Fn(&Frame) -> Result<TensorOp, TensorError>, where you can create tensor ops that reads/writes all the tensors you get here. - A
Framecontains all accessible GPU buffers during the inference, including the state and all runtime buffers.
An example reading out every layer's output during inference:
let info = model.info();
#[derive(Debug, Clone)]
struct Buffer(TensorGpu<f32, ReadWrite>);
// create a buffer to store each layer's output
let buffer = Buffer(context.tensor_init([info.num_emb, info.num_layer, 1, 1]));
let mut hooks = HookMap::default();
for layer in 0..info.num_layer {
// cloning a buffer doesn't actually clone its internal data; use `deep_clone()` to clone to a new buffer
let buffer = buffer.clone();
hooks.insert(
v6::Hook::PostFfn(layer),
Box::new(
move |frame: &v6::Frame<_>| -> Result<TensorOp, TensorError> {
// figure out how many tokens this run has
let shape = frame.buffer.ffn_x.shape();
let num_token = shape[1];
// "steal" the layer's output (activation), and put it into our buffer
TensorOp::blit(
frame.buffer.ffn_x.view(.., num_token - 1, .., ..)?,
buffer.0.view(.., layer, .., ..)?,
)
},
),
);
}
let bundle = v6::Bundle::<f16>::new_with_hooks(model, 1, hooks);
let runtime = TokioRuntime::<Rnn>::new(bundle).await;
let (input, output) = runtime.infer(input).await?;
// now the data is available in `buffer`, we can read it back
let data = buffer.back().await.to_vec();
Convert Models
You must download the model and put in assets/models before running if you are building from source.
You can now download the converted models here.
You may download the official RWKV World series models from HuggingFace, and convert them via the provided convert_safetensors.py.
$ python assets/scripts/convert_safetensors.py --input /path/to/model.pth --output /path/to/model.st
If you don't have python installed or don't want to, there is a pure rust converter.
You can clone that repo and run
$ cd /path/to/web-rwkv-converter
$ cargo run --release --example converter -- --input /path/to/model.pth --output /path/to/model.st
Troubleshoot
"thread 'main' panicked at 'called
Result::unwrap()on anErrvalue: HeaderTooLarge'"Your model is broken, mainly because you cloned the repo but did not set up git-lfs.Please download the model manually and overwrite that one in
assets/models."thread 'main' panicked at 'Error in Queue::submit: parent device is lost'"
Your GPU is not responding. Maybe you are running a model that is just too big for your device. If the model doesn't fit into your VRam, the driver needs to constantly swap and transfer the model parameters, causing it to be 10x slower. Try to quantize your model first.
Debugging Rust on Windows
Source: link.
The default toolchain installed on Windows by Rustup is the x86_64-pc-windows-msvc toolchain. This toolchain does not include Rust-specific formatters for LLDB, as it is assumed that users will primarily use WinDbg or Microsoft Visual Studio's debugger for this target.
If you prefer to use CodeLLDB for debugging, you have two options:
- Use the
x86_64-pc-windows-gnutoolchain to compile your Rust project: This option ensures full LLDB visualization support for Rust types. - Compile with the
x86_64-pc-windows-msvctoolchain but use LLDB formatters fromx86_64-pc-windows-gnu: To use this option, install thex86_64-pc-windows-gnutoolchain viarustup toolchain add x86_64-pc-windows-gnu. Then, configure CodeLLDB to load its formatters by adding the following entry to your workspace configuration:
"lldb.script": { "lang.rust.toolchain": "x86_64-pc-windows-gnu" }
Note that this setup is less ideal due to differences in the debug information layout emitted by the Rust compiler for enum data types when targeting MSVC, which means enums may not be visualized correctly. However, LLDB formatters will work for standard collections like strings and vectors.
Credits
Compatibility
- Runs on
- WebGPU
What shows it
- WebGPU: web-rwkv dependency wgpu
- Native code
- Optional
- Binds native code: tracy-client-sys (feature trace)
- Python bindings
- No Python binding crate found
- License
- Apache-2.0 OR MIT
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
An implementation of the RWKV language model in pure WebGPU. |
444 downloads over 30 days | 3 | 360 | 0.10.20 | WebGPU | Binds native code: tracy-client-sys (feature trace) | Apache-2.0 OR MIT |
|
candle Featured
Minimalist ML framework. Python bindings Also in Run and serve models. |
1,766,495 downloads over 30 days | 692 | 21,287 | 0.11.1 | CUDA, Metal | Binds native code: accelerate-src (feature accelerate), intel-mkl-src (feature mkl), alsa-sys (feature encodec) | Apache-2.0 OR MIT |
|
tch-rs Featured
Rust wrappers for the PyTorch C++ api (libtorch). Python bindings Also in Run and serve models. |
1,190,464 downloads over 30 days | 124 | 5,518 | 0.26.0 | CUDA | Binds native code: tch, torch-sys. Build uses a native toolchain: cc | Apache-2.0 OR MIT |
|
aprender Listed
Next-generation ML framework in pure Rust — `cargo install aprender` for the `apr` CLI Also in Train models. |
15,442 downloads over 30 days | 31 | 140 | 0.72.3 | CUDA, WebGPU | Binds native code: libsqlite3-sys, zstd-sys, tree-sitter (feature full), alsa-sys (feature audio-alsa), nvml-wrapper-sys (feature nvml) and 1 more. Build uses a native toolchain: bindgen (feature bindgen) | MIT |
|
boostr Listed
ML framework on numr for training and inference on CPU, CUDA and WebGPU: attention, quantization, inference scheduling and distributed execution. Models include LLaMA, Mamba2, Qwen3.5, Whisper, Kokoro, VITS, VoxCPM2, Silero VAD, CLAP and super-resolution. Loads SafeTensors and GGUF. Also in Run and serve models. |
1,265 downloads over 30 days | 7 | 20 | 0.11.2 | CUDA, WebGPU | Binds native code: ring (feature distributed) | Apache-2.0 |
|
ruv-fann Listed
A pure Rust implementation of the Fast Artificial Neural Network (FANN) library Python bindings Also in Train models. |
270 downloads over 30 days | 7 | 388 | 0.2.1 | CUDA, WebGPU | Binds native code: libsqlite3-sys, win-sys, torch-sys (feature neural-networks). Build uses a native toolchain: cc | Apache-2.0 OR MIT |
All projects in Run and serve modelsAll projects in Train models
Why ListedNo archive, New or Featured rule places it, so it is Listed.
What it lacks for Featured
- It has 0 active dependents and 0 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 360 stars, 36 forks and 6 contributors. It needs 4,539 stars, 434 forks and 79 contributors together.
What else the check found
- The last activity is on 1 Jun 2026, 161 days ago. The rules expect an update within 450 days. Dormancy rule
- The latest release requires the deprecated dependency instant. RUSTSEC-2024-0384 Rot signals rule
Exact rules: Listed, Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.10.20 base 450: E = 450 daysdormancy: last activity 2026-06-01, 161 days ago, E = 450: activerot: deprecated requirement `instant (RUSTSEC-2024-0384, https://rustsec.org/advisories/RUSTSEC-2024-0384.html)`featured: not featured: active_users 0 < 11 and new_adopters 0 < 9 and repository route stars 360 (needs 4539), forks 36 (needs 434), contributors 6 (needs 79)listed: listed: no archive, new or featured rule applies
Crates2 crates
- web-rwkv Primary
- web-rwkv-derive
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption0 active dependents, 0 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 0 | crates.io database dump | Yes | |
| New dependents (365 days) | 0 | crates.io database dump | Yes | |
| Peak active dependents | 1 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 5 months ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-06-01 | GitHub repository | Yes | |
| Latest release | 2026-03-31 | crates.io database dump | Yes | |
| First release | 2023-07-09 | crates.io database dump | Yes | |
| Latest version | 0.10.20 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 976 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 2 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | instant (RUSTSEC-2024-0384, https://rustsec.org/advisories/RUSTSEC-2024-0384.html) | crates.io database dump | Yes |
Distribution149 releases, 444 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 149 | crates.io database dump | Yes | |
| Downloads over 30 days | 444 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository360 stars, 36 forks, 6 contributors, 711 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 360 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 36 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 6 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 711 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | Apache-2.0 OR MIT | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | WebGPU | crates.io database dump | No | |
| What shows each backend | WebGPU: web-rwkv dependency wgpu | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | Binds native code: tracy-client-sys (feature trace) | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 3 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.