RWKV-4
本页介绍如何在 LangChain 中使用 RWKV-4
包装器。它分为两个部分:安装和设置,以及使用示例。
安装和设置
- 使用
pip install rwkv
安装 Python 包 - 使用
pip install tokenizer
安装 tokenizer Python 包 - 下载 RWKV 模型 并将其放在您想要的目录中
- 下载 tokens 文件
使用方法
RWKV
要使用 RWKV 包装器,您需要提供预训练模型文件和 tokenizer 配置的路径。
from langchain_community.llms import RWKV
# Test the model
```python
def generate_prompt(instruction, input=None):
if input:
return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
# Instruction:
{instruction}
# Input:
{input}
# Response:
"""
else:
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
# Instruction:
{instruction}
# Response:
"""
model = RWKV(model="./models/RWKV-4-Raven-3B-v7-Eng-20230404-ctx4096.pth", strategy="cpu fp32", tokens_path="./rwkv/20B_tokenizer.json")
response = model.invoke(generate_prompt("Once upon a time, "))
API 参考:RWKV
模型文件
您可以在 RWKV-4-Raven 仓库找到模型文件下载链接。
Rwkv-4 模型 -> 建议 VRAM
RWKV VRAM
Model | 8bit | bf16/fp16 | fp32
14B | 16GB | 28GB | >50GB
7B | 8GB | 14GB | 28GB
3B | 2.8GB| 6GB | 12GB
1b5 | 1.3GB| 3GB | 6GB
有关策略的更多信息,包括流式传输和 CUDA 支持,请参阅 rwkv pip 页面。