Skip to content

[Model] Add minimal native RWKV7 serving support#48686

Draft
shiroko98 wants to merge 12 commits into
vllm-project:mainfrom
TimeMobius:rwkv7-upstream-prep
Draft

[Model] Add minimal native RWKV7 serving support#48686
shiroko98 wants to merge 12 commits into
vllm-project:mainfrom
TimeMobius:rwkv7-upstream-prep

Conversation

@shiroko98

Copy link
Copy Markdown

Summary

This PR adds minimal native vLLM serving support for non-hybrid, linear-recurrent RWKV7 causal-LM checkpoints.

  • Adds RWKV7Config and RWKV7ForCausalLM to the native config and model registries.
  • Integrates RWKV7's three recurrent runtime states with existing Mamba state-cache plumbing: attention shift state, recurrent WKV state, and FFN shift state. This is not Transformer K/V history.
  • Keeps model weights and pipeline-parallel intermediate activations at the requested model dtype. Only runtime recurrent state is fp32.
  • Adds registry coverage, dummy-weight initialization coverage, unit/CUDA tests, optional external-reference parity tests, and supported-model documentation.

Why reconsider native in-tree support

I understand that #46269 was closed because the checkpoint subset in the fla-hub/rwkv7 collection appeared to have only a few hundred downloads per model. I respectfully ask that this PR be evaluated against the broader current RWKV ecosystem rather than that subset alone.

Usage signals

  • fla-hub/rwkv7-0.4B-g1 reports 1,574 downloads in the last month. This model belongs directly to the FLA-format family cited in the closure rationale.
  • BlinkDL/rwkv7-g1, from the model developer's primary Hugging Face model repository, is listed with 5.41k downloads in Hugging Face's RWKV library index.
  • mollysama/rwkv-mobile-models is listed with 5.03k downloads, showing demand for mobile and deployment-oriented variants.
  • Earlier official RWKV distributions remain materially used, including RWKV/v5-Eagle-7B-HF at 6.72k downloads and RWKV/rwkv-4-169m-pile at 3.84k downloads in the Hugging Face RWKV index.

These figures are not summed as unique users: they cover different revisions, formats, and deployment channels. They do show that the fla-hub collection alone is too narrow a proxy for RWKV demand, especially for a serving project whose users may consume official, converted, mobile, or quantized variants.

Engineering ecosystem

  • BlinkDL/RWKV-LM, the primary project, has 14.6k GitHub stars, approximately 1k forks, and active RWKV-v7 source.
  • BlinkDL/ChatRWKV has 9.5k stars and approximately 682 forks.
  • RWKV/rwkv.cpp has 1.6k stars and explicitly supports RWKV-v7, demonstrating an independent CPU and quantized inference ecosystem.
  • ggml-org/llama.cpp lists RWKV-7 among its supported text-only model families, so RWKV7 is also maintained in a widely used C/C++ inference runtime.
  • Hugging Face Transformers added native RWKV v4 model support on May 9, 2023. This is not itself RWKV7 support, but it shows that RWKV has long been a recognized model family in the standard Hugging Face ecosystem.

Research maturity

Review and maintenance boundary

This is intentionally a minimum complete serving PR, not a feature-complete RWKV7 optimization effort. Its purpose is to make a non-hybrid, linear-recurrent RWKV7 HF checkpoint load and serve through a native vLLM model/config/registry path with correct recurrent-state handling.

The small boundary makes the change reviewable, testable, and maintainable. It does not introduce a copied kernel subtree, a new external runtime dependency, a new attention backend, a scheduler-specific cache policy, an environment-variable dispatch matrix, or a performance claim beyond correct eager-mode serving.

If maintainers and users demonstrate a need after this baseline is accepted, additional capabilities can be proposed as separate, independently reviewable PRs with their own design, correctness tests, benchmarks, and maintenance justification. Possible follow-ups include kernel or fusion optimization, broader checkpoint variants, and prefix-cache behavior; none is required by or bundled into this PR.

Related work and duplicate-work check

The required duplicate-work review was performed on July 15, 2026. Issue #3583 is the relevant closed RWKV feature request. Searches for open PRs containing RWKV7 or RWKV found no matching implementation; the sole open PR mentioning #3583 is an unrelated reasoning-mode change.

#41060 and #46269 are closed RWKV7 attempts. This PR acknowledges this related prior work rather than claiming an independent implementation. Its distinction is a new, deliberately review-focused integration for the current vLLM architecture, not an algorithmic RWKV innovation.

  • [Model] Add RWKV-7 (Goose) inference support #41060 added a bespoke RWKV mixer/custom op, a dedicated RWKV7 attention backend, vendored Triton kernels, and a prefix-caching contract. This PR instead reuses the existing MambaBase state-cache interfaces and LinearAttentionMetadata without adding a new attention backend.
  • [Model][Kernel] Add RWKV7 Albatross support #46269 targeted raw Albatross/faster3a .pth checkpoints and also added custom CUDA build wiring, rapid sampling, RWKV-specific tokenizer/prompt and tool-parser behavior, stop handling, and benchmarks. This PR targets the standardized Hugging Face checkpoint path only and does not change vLLM sampling, tokenizer, prompt rendering, or tool-calling behavior.
  • This implementation makes the precision boundary explicit: attention shift state, recurrent WKV state, and FFN shift state remain fp32, while model weights and pipeline-parallel intermediate activations remain at the requested model dtype. Dedicated tests cover this behavior.

The purpose of this submission is to request reconsideration based on the broader usage evidence above and this smaller maintenance boundary.

Validation

Environment: Python 3.12.13, PyTorch 2.11.0 / CUDA 13.0, single RTX 4090 D. The worktree was synced with vllm-project/vllm main at 6e073440b1753c6739c5e9a37b180e0d226a60bf before final validation.

CUDA_VISIBLE_DEVICES=0 \
VLLM_RWKV7_TEST_FLA_PATH=<path-to-flash-linear-attention> \
VLLM_RWKV7_TEST_MODEL_PATH=<path-to-RWKV7-reference-checkpoint> \
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 \
python -m pytest -v tests/model_executor/test_rwkv7.py

Result: 16 passed. This covers CPU/runtime-state behavior, CUDA batched decode, prefill, fp32 state dtype, and full-forward plus prefill/decode parity against an external FLA reference checkpoint.

CUDA_VISIBLE_DEVICES=0 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 \
python -m pytest -v tests/models/test_registry.py -k RWKV7ForCausalLM

CUDA_VISIBLE_DEVICES=0 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 \
python -m pytest -v tests/models/test_initialization.py -k RWKV7ForCausalLM

Result: 1 passed for native model registry import and 1 passed for vLLM dummy-weight initialization.

pre-commit run --files docs/models/supported_models.md \
  tests/model_executor/test_rwkv7.py tests/models/registry.py \
  vllm/config/compilation.py vllm/model_executor/models/config.py \
  vllm/model_executor/models/registry.py vllm/model_executor/models/rwkv7.py \
  vllm/transformers_utils/config.py \
  vllm/transformers_utils/configs/__init__.py \
  vllm/transformers_utils/configs/rwkv7.py

pre-commit run mypy-3.12 --files ... --hook-stage manual

DISABLE_MKDOCS_2_WARNING=true API_AUTONAV_EXCLUDE=vllm mkdocs build

Result: passed. The pre-commit run covers applicable Ruff, typos, markdownlint, actionlint, mypy-3.10, SPDX, forbidden-import, config, and attention-backend-doc hooks. The manual mypy-3.12 hook and MkDocs build also passed.

vllm serve <path-to-RWKV-STEP-13.3B-HF-checkpoint> \
  --dtype bfloat16 --enforce-eager --trust-remote-code

Result: the real 13.3B serve smoke resolved RWKV7ForCausalLM, started successfully, returned /health and /v1/models, and returned the deterministic completion , World!\"\n for prompt="Hello", max_tokens=4, and temperature=0.

The tested checkpoint still needs --trust-remote-code because of its Hugging Face checkpoint/tokenizer assets. The model forward path used by vLLM is the native vLLM RWKV7ForCausalLM implementation in this PR.

AI assistance

This change was developed with AI assistance. The human submitter has reviewed the changed lines and is prepared to defend the design and test results end-to-end.

Co-authored-by: OpenAI Codex

Signed-off-by: shiroko98 <512815652@qq.com>
Tests: PYTHONPATH=/mnt/data/Codes/RWKV/vllm/vllm_rwkv7/vllm-upstream:/tmp PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 .venv/bin/python -m pytest -v tests/model_executor/test_rwkv7.py::test_rwkv7_mamba_state_copy_function_types tests/model_executor/test_rwkv7.py::test_rwkv7_uses_base_mamba_model_config tests/model_executor/test_rwkv7.py::test_rwkv7_does_not_declare_mamba_prefix_caching_support tests/model_executor/test_rwkv7.py::test_rwkv7_block_forward_without_metadata tests/model_executor/test_rwkv7.py::test_rwkv7_block_registers_static_forward_context tests/model_executor/test_rwkv7.py::test_rwkv7_block_updates_cached_states tests/model_executor/test_rwkv7.py::test_rwkv7_block_batches_decode_tokens_without_changing_results tests/model_executor/test_rwkv7.py::test_rwkv7_block_batches_prefill_tokens_without_changing_results tests/model_executor/test_rwkv7.py::test_rwkv7_block_uses_fp32_runtime_state_dtype tests/model_executor/test_rwkv7.py::test_rwkv7_block_cache_all_prefill_writes_aligned_states tests/model_executor/test_rwkv7.py::test_rwkv7_block_cache_all_prefill_batches_multiple_sequences tests/model_executor/test_rwkv7.py::test_rwkv7_block_cache_all_decode_writes_next_block_slot

Assisted-by: Codex

Signed-off-by: shiroko98 <512815652@qq.com>
Signed-off-by: shiroko98 <512815652@qq.com>
Signed-off-by: shiroko98 <512815652@qq.com>
Document RWKV7 support, keep model weights and PP buffers in model dtype, and make external flash-linear-attention usage explicit as a reference-test-only dependency.

Co-authored-by: OpenAI Codex <codex@openai.com>

Signed-off-by: shiroko98 <512815652@qq.com>
- register rwkv reasoning/tool parsers
- remove private fused env toggles in favor of capability checks
- declare and test RWKV7 mamba prefix caching support
- register RWKV7 CUDA wrapper custom ops explicitly on CUDA

Assisted-by: OpenAI Codex

Signed-off-by: shiroko98 <512815652@qq.com>
Co-authored-by: OpenAI Codex <codex@openai.com>

Signed-off-by: shiroko98 <512815652@qq.com>
- remove RWKV7-specific parser and linear-attention extras from the first PR scope\n- switch RWKV7 block execution/tests to the minimal core runtime path\n- keep only the model/config/registry surface needed for vllm serve\n\nCo-authored-by: OpenAI Codex <codex@openai.com>

Signed-off-by: shiroko98 <512815652@qq.com>
Keep the minimal RWKV7 PR1 surface on top of latest upstream, including the latest Mamba backend enum wiring and test-only optional FLA parity coverage.

Co-authored-by: OpenAI Codex <codex@openai.com>

Signed-off-by: shiroko98 <512815652@qq.com>
Assisted-by: Codex

Signed-off-by: shiroko98 <512815652@qq.com>
Assisted-by: Codex

Signed-off-by: shiroko98 <512815652@qq.com>
@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Documentation preview: https://vllm--48686.org.readthedocs.build/en/48686/

@mergify mergify Bot added documentation Improvements or additions to documentation new-model Requests to new models labels Jul 15, 2026
@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

PRs do not trigger a full CI run by default. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

@shiroko98 shiroko98 force-pushed the rwkv7-upstream-prep branch from 1b05312 to 064c0dd Compare July 15, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation new-model Requests to new models

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant