Skip to content

feat: add RWKV-7-World model support on cuda device.#1918

Open
Dragonliu2018 wants to merge 1 commit into
xLLM-AI:mainfrom
Dragonliu2018:lzl/feat/rwkv7-world-model-support
Open

feat: add RWKV-7-World model support on cuda device.#1918
Dragonliu2018 wants to merge 1 commit into
xLLM-AI:mainfrom
Dragonliu2018:lzl/feat/rwkv7-world-model-support

Conversation

@Dragonliu2018

@Dragonliu2018 Dragonliu2018 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds RWKV-7-World CUDA inference support to xLLM. Official checkpoints ship as native .pth files; this PR provides a conversion script to produce HuggingFace-style model directories and wires the model into xLLM’s linear-attention KV cache and serving stack.

Changes

  • Model: New rwkv7 causal LM (embedding + RWKV-7 blocks + lm_head), registered as model_type=rwkv7
  • Decoder layer: RWKV-7 time-mix / channel-mix implementation, using linear-attention KV cache for W-matrix and token-shift state
  • Tokenizer: Native RWKV trie tokenizer (rwkv_vocab_v20230424.txt), registered as tokenizer_type=rwkv
  • Conversion tool: tools/convert_rwkv7_world.py — converts ModelScope/BlinkDL .pth to config.json + model.safetensors + tokenizer files
  • Tests: rwkv_tokenizer_test, rwkv7_decoder_layer_test, hf_model_loader_test (rwkv7 args)

The test program and the generated text are as follows.

Convert model:

python tools/convert_rwkv7_world.py \
  --src /root/models2/rwkv-7-world \
  --dst /root/models2 \
  --sizes all

Serve:

./build/xllm/core/server/xllm --model=/mnt/data2/models2/rwkv-7-world-2.9b-xllm --port=9977 --device_id=0

Test program:

#!/usr/bin/env python3
"""Smoke test for RWKV-7 World xLLM service (converted HF-style directory).
"""

import os
import sys

import requests

BASE_URL = os.environ.get("XLLM_BASE_URL", "http://127.0.0.1:9977")
PROMPT_TEXT = os.environ.get("PROMPT_TEXT", "The capital of France is")
MAX_TOKENS = int(os.environ.get("MAX_TOKENS", "10"))
TEMPERATURE = float(os.environ.get("TEMPERATURE", "0"))
TOP_K = int(os.environ.get("TOP_K", "1"))


def main() -> int:
    model_id = requests.get(f"{BASE_URL}/v1/models", timeout=10).json()["data"][0]["id"]
    print(f"model: {model_id}")
    print(f"prompt: {PROMPT_TEXT!r}")
    print(f"generation: max_tokens={MAX_TOKENS} temperature={TEMPERATURE} top_k={TOP_K}")

    response = requests.post(
        f"{BASE_URL}/v1/completions",
        json={
            "model": model_id,
            "prompt": PROMPT_TEXT,
            "max_tokens": MAX_TOKENS,
            "temperature": TEMPERATURE,
            "top_k": TOP_K,
            "stream": False,
        },
        timeout=180,
    )
    if response.status_code != 200:
        print(f"HTTP {response.status_code}: {response.text}", file=sys.stderr)
        return 1

    payload = response.json()
    choice = payload["choices"][0]
    text = choice.get("text", "")
    print(f"completion text: {text!r}")

    usage = payload.get("usage")
    if usage:
        print(
            "usage: "
            f"prompt_tokens={usage.get('prompt_tokens')} "
            f"generated_tokens={usage.get('completion_tokens', usage.get('generated_tokens'))}"
        )

    if PROMPT_TEXT == "The capital of France is" and not text.lstrip().startswith("Paris"):
        print(
            "warning: expected completion to start with 'Paris' for the default prompt",
            file=sys.stderr,
        )
        return 1

    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Output:

(xllm) ➜  xllm git:(lzl/feat/rwkv7-world-model-support) ✗ python examples/test_rwkv7_world.py
model: rwkv-7-world-2.9b-xllm
prompt: 'The capital of France is'
generation: max_tokens=10 temperature=0.0 top_k=1
completion text: ' Paris.\nThe capital of France is Paris.'
usage: prompt_tokens=5 generated_tokens=10

Related Issues

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactor
  • Documentation
  • Test
  • Build or CI

Pull Request Checklist

Thank you for contributing to xLLM. Before requesting review, please make sure the following items are complete.

PR Title and Commit Messages

  • The PR title and each commit message follow the xLLM commit format: <type>: <subject>.

Allowed types: feat, bugfix, docs, test, refactor, chore, style, revert, perf, model, build, release.
The subject should use clear English, start with a verb, include at least 4 words, and end with ..

Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit or an equivalent command.
  • I have installed the hooks with pre-commit install.
  • I have run pre-commit run --all-files and fixed any reported issues.

If you are unsure how to set up pre-commit, see the pre-commit documentation.

Self Review

  • I have self-reviewed the code according to .agents/skills/code-review/references/custom-code-style.md, especially code written or assisted by AI.
  • I have rebased this PR onto the latest main branch.

Build and Test Coverage

  • Tests have been added or updated as needed.
  • CUDA: python setup.py build test has passed on a CUDA machine.
  • NPU: python setup.py build test has passed on an NPU machine.
  • MLU: python setup.py build test has passed on an MLU machine.

Reviewer Notes

Comment thread xllm/core/framework/parallel_state/cuda_process_group.h Outdated
@XuZhang99 XuZhang99 changed the title feat: add RWKV-7-World model support for CUDA inference feat: add RWKV-7-World model support on cuda device. Jul 10, 2026
@Dragonliu2018
Dragonliu2018 force-pushed the lzl/feat/rwkv7-world-model-support branch from df42f19 to 63b5418 Compare July 10, 2026 16:05
@Dragonliu2018

Copy link
Copy Markdown
Collaborator Author

@Dragonliu2018
Dragonliu2018 requested a review from XuZhang99 July 16, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants