This checkpoint is a states tuning file from RWKV-6-7B. Please download the base model from
https://huggingface.co/BlinkDL/rwkv-6-world/tree/main . It will give a judgement about the type of the sentence.
Usage:
1from rwkv.model import RWKV
2from rwkv.utils import PIPELINE, PIPELINE_ARGS
3import torch
4
5# download models: https://huggingface.co/BlinkDL
6model = RWKV(model='/media/yueyulin/KINGSTON/models/rwkv6/RWKV-x060-World-7B-v2.1-20240507-ctx4096.pth', strategy='cuda fp16')
7print(model.args)
8pipeline = PIPELINE(model, "rwkv_vocab_v20230424") # 20B_tokenizer.json is in https://github.com/BlinkDL/ChatRWKV
9# use pipeline = PIPELINE(model, "rwkv_vocab_v20230424") for rwkv "world" models
10states_file = '/media/yueyulin/data_4t/models/states_tuning/custom_trainer/epoch_2/RWKV-x060-World-7B-v2.1-20240507-ctx4096.pth.pth'
11states = torch.load(states_file)
12states_value = []
13device = 'cuda'
14n_head = model.args.n_head
15head_size = model.args.n_embd//model.args.n_head
16for i in range(model.args.n_layer):
17 key = f'blocks.{i}.att.time_state'
18 value = states[key]
19 prev_x = torch.zeros(model.args.n_embd,device=device,dtype=torch.float16)
20 prev_states = value.clone().detach().to(device=device,dtype=torch.float16).transpose(1,2)
21 prev_ffn = torch.zeros(model.args.n_embd,device=device,dtype=torch.float16)
22 states_value.append(prev_x)
23 states_value.append(prev_states)
24 states_value.append(prev_ffn)
1cat_char = '🐱'
2bot_char = '🤖'
3instruction ='你是一个图谱实体知识结构化专家。请从input中抽取出符合schema定义的实体实例和其属性,不存在的属性不输出,属性存在多值就返回列表。请按照JSON字符串的格式回答。'
4schema = schemas['人物']
5input_text = "个人简介姓名:拉塞·维比 所属球队:布伦特福德 国籍:丹麦、法国、荷兰、法属圭亚那 出生日期:1987-02-22 身高:181cm 体重:73kg 场上位置:前锋 球衣号码:21 丹麦射手拉塞-维比,获得了2014赛季瑞超联赛金靴"
6input_text = {'input': input_text, 'schema': schema}
7input_text = json.dumps(input_text).decode('UTF-8')
8ctx = f'{cat_char}:{instruction}\n{input_text}\n{bot_char}:'
9print(ctx)
10
11def my_print(s):
12 print(s, end='', flush=True)
13
14# For alpha_frequency and alpha_presence, see "Frequency and presence penalties":
15# https://platform.openai.com/docs/api-reference/parameter-details
16
17args = PIPELINE_ARGS(temperature = 1.0, top_p = 0, top_k = 0, # top_k = 0 then ignore
18 alpha_frequency = 0.25,
19 alpha_presence = 0.25,
20 alpha_decay = 0.996, # gradually decay the penalty
21 token_ban = [0], # ban the generation of some tokens
22 token_stop = [0,1], # stop generation whenever you see any token here
23 chunk_len = 256) # split input into chunks to save VRAM (shorter -> slower)
24
25pipeline.generate(ctx, token_count=200, args=args, callback=my_print,state=states_value)
26print('\n')