howard-hou/RWKV-X

RWKV-X is a Linear Complexity Hybrid Language Model based on the RWKV architecture, integrating Sparse Attention to improve the model's long sequence processing capabilities.

Python

60

180 commits

updated Mar 31, 2026

See the code

README

RWKV-X πŸš€

RWKV-X is a Linear Complexity Hybrid Language Model based on the RWKV architecture, integrating Sparse Attention to enhance long-sequence processing capabilities. πŸ“šβš‘

🧠 Project Overview

RWKV-X is an extended version of the RWKV-7 language model, introducing several improvements while maintaining RWKV's efficient, RNN-like characteristics. This project includes complete implementations for pre-training, fine-tuning, evaluation, and packaging for pip. πŸ”§πŸ“¦

✨ Key Features

  • 🧡 Long Sequence Support: Innovative architecture supporting context lengths up to 64K
  • 🧠 Sparse Attention Mechanism: Efficient sparse attention to enhance long-text understanding
  • πŸ› οΈ Comprehensive Toolchain: End-to-end workflow from pre-training to fine-tuning to evaluation

πŸ—‚οΈ Project Structure

RWKV-X/
β”œβ”€β”€ sft/                  # Supervised fine-tuning module
β”‚   β”œβ”€β”€ src/              # Fine-tuning source code
β”‚   β”œβ”€β”€ tokenizer/        # Tokenizer
β”‚   β”œβ”€β”€ scripts/          # Fine-tuning scripts
β”‚   └── train.py          # Main fine-tuning script
β”œβ”€β”€ pretrain/             # Pre-training module
β”‚   β”œβ”€β”€ src/              # Pre-training source code
β”‚   β”œβ”€β”€ tokenizer/        # Tokenizer
β”‚   └── train.py          # Main pre-training script
β”œβ”€β”€ package/              # Python package module
β”‚   β”œβ”€β”€ src/              
β”‚   └── rwkv_x/           # Core implementation of RWKV-X
β”œβ”€β”€ evaluation/           # Evaluation module
β”‚   β”œβ”€β”€ src/              # Evaluation source code
β”‚   β”œβ”€β”€ lm_eval/          # Language model evaluation
β”‚   └── postprocess/      # Post-processing tools
└── tree.py               # Directory structure generation script

βš™οΈ Usage

πŸ“¦ Installation

# Install from PyPI
pip install rwkv-x

# Or install from source
cd RWKV-X/package
pip install -e .

πŸ§ͺ Inference Example

# !!! set these before import RWKV !!!
import os
os.environ["RWKV_CUDA_ON"] = '0' # '1' to compile CUDA kernel (10x faster), requires c++ compiler & cuda libraries
from rwkv_x.model import RWKV_X
from rwkv_x.utils import PIPELINE, PIPELINE_ARGS

# Load model
# You can get the model weights from: https://huggingface.co/howard-hou/RWKV-X/
model = RWKV_X(model_path='RWKV-X-0.2B-64k-Base.pth', strategy='cuda fp16')
pipeline = PIPELINE(model)

# Set generation parameters
args = PIPELINE_ARGS(
    temperature=1.0,
    top_p=0.7,
    top_k=100,
    alpha_frequency=0.25,
    alpha_presence=0.25,
    token_ban=[],
    token_stop=[],
    chunk_len=256
)

# Generate text
ctx = "This is a sample prompt."
output = pipeline.generate(ctx, token_count=200, args=args)
print(output)

πŸ”§ Fine-tuning the Model

cd RWKV-X/sft
python train.py --load_model ../RWKV-x070-World-1.5B-v3-20250127-ctx4096.pth \
    --wandb "rwkv1b5-sft" --proj_dir out/rwkv1b5-sft \
    --data_file ../data.json \
    --data_type "json" --vocab_size 65536 \
    --ctx_len 2048 --epoch_steps 1000 --epoch_count 10 \
    --micro_bsz 32 --accumulate_grad_batches 4 \
    --lr_init 6e-5 --lr_final 1.5e-5 \
    --accelerator gpu --devices 2 --precision bf16

πŸ“Š Model Evaluation

cd RWKV-X/evaluation
python lm_eval_rwkvx_pip.py path/to/model.pth --task_group english

πŸ“ˆ Performance Benchmarks

RWKV-X delivers outstanding results on multiple standard benchmarks:

  • πŸ† Classification & Reading: MMLU, LAMBADA, HellaSwag
  • 🧾 Long Text Understanding: RULER, LongBench
  • 🌍 Multilingual Tasks

πŸ“„ License

RWKV-X is released under the MIT License. See the LICENSE file for details. βœ…

language-model
rwkv
rwkv7

Contributors

howard-hou

178 commits

hzy0607

2 commits

howard-hou/RWKV-X

RWKV-X is a Linear Complexity Hybrid Language Model based on the RWKV architecture, integrating Sparse Attention to improve the model's long sequence processing capabilities.

Python

60

180 commits

updated Mar 31, 2026

See the code

README

RWKV-X πŸš€

RWKV-X is a Linear Complexity Hybrid Language Model based on the RWKV architecture, integrating Sparse Attention to enhance long-sequence processing capabilities. πŸ“šβš‘

🧠 Project Overview

RWKV-X is an extended version of the RWKV-7 language model, introducing several improvements while maintaining RWKV's efficient, RNN-like characteristics. This project includes complete implementations for pre-training, fine-tuning, evaluation, and packaging for pip. πŸ”§πŸ“¦

✨ Key Features

  • 🧡 Long Sequence Support: Innovative architecture supporting context lengths up to 64K
  • 🧠 Sparse Attention Mechanism: Efficient sparse attention to enhance long-text understanding
  • πŸ› οΈ Comprehensive Toolchain: End-to-end workflow from pre-training to fine-tuning to evaluation

πŸ—‚οΈ Project Structure

RWKV-X/
β”œβ”€β”€ sft/                  # Supervised fine-tuning module
β”‚   β”œβ”€β”€ src/              # Fine-tuning source code
β”‚   β”œβ”€β”€ tokenizer/        # Tokenizer
β”‚   β”œβ”€β”€ scripts/          # Fine-tuning scripts
β”‚   └── train.py          # Main fine-tuning script
β”œβ”€β”€ pretrain/             # Pre-training module
β”‚   β”œβ”€β”€ src/              # Pre-training source code
β”‚   β”œβ”€β”€ tokenizer/        # Tokenizer
β”‚   └── train.py          # Main pre-training script
β”œβ”€β”€ package/              # Python package module
β”‚   β”œβ”€β”€ src/              
β”‚   └── rwkv_x/           # Core implementation of RWKV-X
β”œβ”€β”€ evaluation/           # Evaluation module
β”‚   β”œβ”€β”€ src/              # Evaluation source code
β”‚   β”œβ”€β”€ lm_eval/          # Language model evaluation
β”‚   └── postprocess/      # Post-processing tools
└── tree.py               # Directory structure generation script

βš™οΈ Usage

πŸ“¦ Installation

# Install from PyPI
pip install rwkv-x

# Or install from source
cd RWKV-X/package
pip install -e .

πŸ§ͺ Inference Example

# !!! set these before import RWKV !!!
import os
os.environ["RWKV_CUDA_ON"] = '0' # '1' to compile CUDA kernel (10x faster), requires c++ compiler & cuda libraries
from rwkv_x.model import RWKV_X
from rwkv_x.utils import PIPELINE, PIPELINE_ARGS

# Load model
# You can get the model weights from: https://huggingface.co/howard-hou/RWKV-X/
model = RWKV_X(model_path='RWKV-X-0.2B-64k-Base.pth', strategy='cuda fp16')
pipeline = PIPELINE(model)

# Set generation parameters
args = PIPELINE_ARGS(
    temperature=1.0,
    top_p=0.7,
    top_k=100,
    alpha_frequency=0.25,
    alpha_presence=0.25,
    token_ban=[],
    token_stop=[],
    chunk_len=256
)

# Generate text
ctx = "This is a sample prompt."
output = pipeline.generate(ctx, token_count=200, args=args)
print(output)

πŸ”§ Fine-tuning the Model

cd RWKV-X/sft
python train.py --load_model ../RWKV-x070-World-1.5B-v3-20250127-ctx4096.pth \
    --wandb "rwkv1b5-sft" --proj_dir out/rwkv1b5-sft \
    --data_file ../data.json \
    --data_type "json" --vocab_size 65536 \
    --ctx_len 2048 --epoch_steps 1000 --epoch_count 10 \
    --micro_bsz 32 --accumulate_grad_batches 4 \
    --lr_init 6e-5 --lr_final 1.5e-5 \
    --accelerator gpu --devices 2 --precision bf16

πŸ“Š Model Evaluation

cd RWKV-X/evaluation
python lm_eval_rwkvx_pip.py path/to/model.pth --task_group english

πŸ“ˆ Performance Benchmarks

RWKV-X delivers outstanding results on multiple standard benchmarks:

  • πŸ† Classification & Reading: MMLU, LAMBADA, HellaSwag
  • 🧾 Long Text Understanding: RULER, LongBench
  • 🌍 Multilingual Tasks

πŸ“„ License

RWKV-X is released under the MIT License. See the LICENSE file for details. βœ…

language-model
rwkv
rwkv7

Contributors

howard-hou

178 commits

hzy0607

2 commits

Languages

Python

97.3%

Cuda

1.2%