Views
No views yet
13B models in this project.opendata-chinese-llama2-sft, a instructions finetune version based on Llama-2 13B baseopendata-chinese-llama2-reward, a reward model trained from the above sft modelopendata-chinese-llama2-chat, a ppo model based on the above sft model and reward modelHuman,USER,[HM] and Assistant prefix from Assistant,AI,[AI], and we add bos token and eos token for each turns.| Model Name | Type | Training Data | Download Link |
|---|---|---|---|
| opendata-chinese-llama2-sft-13B | sft Model | 5M Instructions | [HuggingFace] |
| opendata-chinese-llama2-reward-13B | reward Model | 160k rankingPairs | [HuggingFace] |
| opendata-chinese-llama2-chat-13B | chat Model | 50k prompts | [HuggingFace] |
1from transformers import AutoConfig, AutoModelForCausalLM, LlamaTokenizer
2
3def load_model(model_path):
4 model_config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
5 model = AutoModelForCausalLM.from_pretrained(
6 model_path,
7 config=model_config,
8 trust_remote_code=True)
9 model = model.eval().cuda()
10 tokenizer = LlamaTokenizer.from_pretrained(model_path, fast_tokenizer=True)
11 return model, tokenizer
12model, tokenizer = load_model("pandaExplosion/opendata-chinese-llama2-chat-13B")
13
14prefix_human = "Human"
15prefix_bot = "AI"
16query = "给出10个暴富的建议"
17text = f"<s>{prefix_human}\n{query}</s><s>{prefix_bot}\n"
18input_ids = tokenizer(text, return_tensors="pt", add_special_tokens=False).input_ids
19with torch.no_grad():
20 outputs = model.generate(
21 input_ids,
22 do_sample = False,
23 max_new_tokens = 512,
24 eos_token_id= tokenizer.eos_token_id,
25 pad_token_id= tokenizer.pad_token_id,
26 num_return_sequences = 1,
27 return_dict_in_generate=True,
28 repetition_penalty=1.1,
29 top_p=0.95)
30 out = outputs.sequences[:, input_ids.shape[-1]:]
31 out_text = tokenizer.batch_decode(out, skip_special_tokens=True)
32print(out_text)
331from transformers import LlamaTokenizer
2from reward_model import create_critic_model # modified from deepspeedChat
3
4def load_reward_model(model_path):
5 tokenizer = LlamaTokenizer.from_pretrained(model_path, fast_tokenizer=True)
6 model = create_critic_model(model_path, tokenizer)
7 model = model.eval().cuda()
8 return model, tokenizer
9model, tokenizer = load_reward_model("pandaExplosion/opendata-chinese-llama2-reward-13B")
10
11prefix_human = "Human"
12prefix_bot = "AI"
13query = "给出10个暴富的建议"
14response = "不给"
15prompt = f"<s>{prefix_human}\n{query}</s>" + "\n" + f"<s>{prefix_bot}\n"
16text = f"<s>{prefix_human}\n{query}</s>" + "\n" + f"<s>{prefix_bot}\n{response}</s>"
17prompt_len = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).input_ids.shape[-1]
18inputs = tokenizer(text, return_tensors="pt", add_special_tokens=False)
19with torch.no_grad():
20 reward = model.forward_value(
21 inputs['input_ids'].cuda(),
22 attention_mask = inputs['attention_mask'].cuda(),
23 prompt_length=prompt_len)
24 print(reward['chosen_end_scores']) # [-2.5229]
25| Model | Valid (5-shot) | TestAvg (5-shot) | TestAvgHard (5-shot) |
|---|---|---|---|
| LLaMA-2-13B* | 37.3 | 36.6 | 31.7 |
| LLaMA-2-chat-13B* | 38.6 | 37.2 | 30.0 |
| opendata-chinese-llama2-sft-13B | 39.5 | 40.2 | 30.1 |
| opendata-chinese-llama2-chat-13B | 40.3 | 40.5 | 29.8 |