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
請參閱 rwkv pip 頁面,以取得關於策略的更多資訊,包括串流和 cuda 支援。