Update README.md
Browse files
README.md
CHANGED
|
@@ -1,16 +1,57 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
```
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This is a state for rwkv6_7b_v2.1 that generates entity_types given domain, expert role in this domain and specific tasks that this export can do that are generated from persona_domain agent.
|
| 2 |
+
|
| 3 |
+
* The input is solely the context that you want this model to analyze
|
| 4 |
+
* The output are domain, expert role in this domain and specific tasks that this export can do in a jsonl format.
|
| 5 |
+
|
| 6 |
+
# Please refer to the following demo as test code:
|
| 7 |
+
```python
|
| 8 |
+
from rwkv.model import RWKV
|
| 9 |
+
from rwkv.utils import PIPELINE, PIPELINE_ARGS
|
| 10 |
+
import torch
|
| 11 |
+
|
| 12 |
+
# download models: https://huggingface.co/BlinkDL
|
| 13 |
+
model = RWKV(model='/home/rwkv/Peter/model/base/RWKV-x060-World-7B-v2.1-20240507-ctx4096.pth', strategy='cuda fp16')
|
| 14 |
+
print(model.args)
|
| 15 |
+
pipeline = PIPELINE(model, "rwkv_vocab_v20230424") # 20B_tokenizer.json is in https://github.com/BlinkDL/ChatRWKV
|
| 16 |
+
# use pipeline = PIPELINE(model, "rwkv_vocab_v20230424") for rwkv "world" models
|
| 17 |
+
states_file = '/home/rwkv/Peter/rwkv_graphrag/agents/persona_domain_states/RWKV-x060-World-7B-v2.1-20240507-ctx4096.pth.pth'
|
| 18 |
+
states = torch.load(states_file)
|
| 19 |
+
states_value = []
|
| 20 |
+
device = 'cuda'
|
| 21 |
+
n_head = model.args.n_head
|
| 22 |
+
head_size = model.args.n_embd//model.args.n_head
|
| 23 |
+
for i in range(model.args.n_layer):
|
| 24 |
+
key = f'blocks.{i}.att.time_state'
|
| 25 |
+
value = states[key]
|
| 26 |
+
prev_x = torch.zeros(model.args.n_embd,device=device,dtype=torch.float16)
|
| 27 |
+
prev_states = value.clone().detach().to(device=device,dtype=torch.float16).transpose(1,2)
|
| 28 |
+
prev_ffn = torch.zeros(model.args.n_embd,device=device,dtype=torch.float16)
|
| 29 |
+
states_value.append(prev_x)
|
| 30 |
+
states_value.append(prev_states)
|
| 31 |
+
states_value.append(prev_ffn)
|
| 32 |
+
|
| 33 |
+
cat_char = '🐱'
|
| 34 |
+
bot_char = '🤖'
|
| 35 |
+
instruction ='根据input中的领域和任务,协助用户识别input文本中存在的实体类型。 实体类型必须与用户任务相关。 避免使用诸如“其他”或“未知”的通用实体类型。 非常重要的是:不要生成冗余或重叠的实体类型。用JSON格式输出。'
|
| 36 |
+
input_text = '{"领域": "文学与神话", "专家": "文学史学者/神话学家", "任务": ["分析《石头记》的历史背景和影响", "研究《红楼梦》与《金陵��二钗》之间的关系", "探讨东鲁孔梅溪对《石头记》的改编过程", "解析吴玉峰在《红楼梦》中的角色和贡献", "评估曹雪芹在《悼红轩中披阅十五间》中的写作技巧"]}'
|
| 37 |
+
ctx = f'{cat_char}:{instruction}\n{input_text}\n{bot_char}:'
|
| 38 |
+
print(ctx)
|
| 39 |
+
|
| 40 |
+
def my_print(s):
|
| 41 |
+
print(s, end='', flush=True)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
args = PIPELINE_ARGS(temperature = 1, top_p = 0.2, top_k = 0, # top_k = 0 then ignore
|
| 46 |
+
alpha_frequency = 0.5,
|
| 47 |
+
alpha_presence = 0.5,
|
| 48 |
+
alpha_decay = 0.998, # gradually decay the penalty
|
| 49 |
+
token_ban = [0], # ban the generation of some tokens
|
| 50 |
+
token_stop = [0,1], # stop generation whenever you see any token here
|
| 51 |
+
chunk_len = 256) # split input into chunks to save VRAM (shorter -> slower)
|
| 52 |
+
|
| 53 |
+
pipeline.generate(ctx, token_count=1000, args=args, callback=my_print,state=states_value)
|
| 54 |
+
print('\n')
|
| 55 |
+
```
|
| 56 |
+
# The final printed input and output:
|
| 57 |
+

|