Commit
·
ad471b3
1
Parent(s):
32884d4
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,35 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
+
RWKV-4-World-1.5B的Hugface格式,因新版World的tokenizer较之前Raven\Pile版本有较大变化,因而需要进行新版HF适配
|
5 |
+
ringrwkv兼容了原生rwkv库和transformers的rwkv库,同时新添入World版本的配置及代码(默认1.5B),并修复了原HF的RWKV在
|
6 |
+
Forward RWKVOutput时的细微问题,主要是引入和明确last_hidden_state。以下是轻量级使用代码,比较方便:<br>
|
7 |
+
|
8 |
+
import torch<br>
|
9 |
+
from ringrwkv.configuration_rwkv_world import RwkvConfig<br>
|
10 |
+
from ringrwkv.rwkv_tokenizer import TRIE_TOKENIZER<br>
|
11 |
+
from ringrwkv.modehf_world import RwkvForCausalLM<br>
|
12 |
+
|
13 |
+
|
14 |
+
model = RwkvForCausalLM.from_pretrained("StarRing2022/RWKV-4-World-1.5B")<br> #或将本模型下载至本地文件夹
|
15 |
+
tokenizer = TRIE_TOKENIZER('./ringrwkv/rwkv_vocab_v20230424.txt')<br>
|
16 |
+
|
17 |
+
text = "你叫什么名字?"<br>
|
18 |
+
|
19 |
+
question = f'Question: {text.strip()}\n\nAnswer:'<br>
|
20 |
+
|
21 |
+
input_ids = tokenizer.encode(question)<br>
|
22 |
+
input_ids = torch.tensor(input_ids).unsqueeze(0)<br>
|
23 |
+
|
24 |
+
out = model.generate(input_ids,max_new_tokens=40)<br><br>
|
25 |
+
|
26 |
+
|
27 |
+
outlist = out[0].tolist()<br>
|
28 |
+
|
29 |
+
for i in outlist:<br>
|
30 |
+
if i==0:<br> #要删除tokenid为0的元素
|
31 |
+
outlist.remove(i)<br>
|
32 |
+
|
33 |
+
answer = tokenizer.decode(outlist)<br>
|
34 |
+
|
35 |
+
print(answer)<br>
|