Redflashing commited on
Commit
f4231fe
1 Parent(s): 4acd19b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +119 -1
README.md CHANGED
@@ -1,3 +1,121 @@
1
  ---
2
- license: apache-2.0
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - zh
4
+ - en
5
+ pipeline_tag: text-generation
6
+ inference: false
7
+
8
  ---
9
+
10
+ # Baichuan-7B-Instruction
11
+
12
+ ![](./alpachino.png)
13
+
14
+ <!-- Provide a quick summary of what the model is/does. -->
15
+
16
+ ## 介绍
17
+
18
+ Baichuan-7B-Instruction 为 Baichuan-7B 系列模型进行指令微调后的版本,预训练模型可见 [Baichuan-7B-Base](https://huggingface.co/baichuan-inc/Baichuan-7B-Base)。
19
+
20
+
21
+ ## Demo
22
+
23
+ 如下是一个使用 gradio 的模型 demo
24
+
25
+ ```python
26
+ import gradio as gr
27
+ from transformers import AutoTokenizer, AutoModelForCausalLM
28
+
29
+ tokenizer = AutoTokenizer.from_pretrained("AlpachinoNLP/Baichuan-7B-Instruction",trust_remote_code=True,use_fast=False)
30
+ model = AutoModelForCausalLM.from_pretrained("AlpachinoNLP/Baichuan-7B-Instruction",trust_remote_code=True ).half()
31
+ model.cuda()
32
+
33
+ def generate(histories, max_new_tokens=2048, do_sample = True, top_p = 0.95, temperature = 0.35, repetition_penalty=1.1):
34
+ prompt = ""
35
+ for history in histories:
36
+ history_with_identity = "\nHuman:" + history[0] + "\n\nAssistant:" + history[1]
37
+ prompt += history_with_identity
38
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
39
+ outputs = model.generate(
40
+ input_ids = input_ids,
41
+ max_new_tokens=max_new_tokens,
42
+ early_stopping=True,
43
+ do_sample=do_sample,
44
+ top_p=top_p,
45
+ temperature=temperature,
46
+ repetition_penalty=repetition_penalty,
47
+ )
48
+ rets = tokenizer.batch_decode(outputs, skip_special_tokens=True)
49
+ generate_text = rets[0].replace(prompt, "")
50
+ return generate_text
51
+
52
+ with gr.Blocks() as demo:
53
+ chatbot = gr.Chatbot()
54
+ msg = gr.Textbox()
55
+ clear = gr.Button("clear")
56
+
57
+ def user(user_message, history):
58
+ return "", history + [[user_message, ""]]
59
+
60
+ def bot(history):
61
+ print(history)
62
+ bot_message = generate(history)
63
+ history[-1][1] = bot_message
64
+ return history
65
+
66
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
67
+ bot, chatbot, chatbot
68
+ )
69
+ clear.click(lambda: None, None, chatbot, queue=False)
70
+
71
+ if __name__ == "__main__":
72
+ demo.launch(server_name="0.0.0.0")
73
+
74
+
75
+
76
+ ```
77
+
78
+ ## 量化部署
79
+
80
+ Baichuan-7B 支持 int8 和 int4 量化,用户只需在推理代码中简单修改两行即可实现。请注意,如果是为了节省显存而进行量化,应加载原始精度模型到 CPU 后再开始量化;避免在 `from_pretrained` 时添加 `device_map='auto'` 或者其它会导致把原始精度模型直接加载到 GPU 的行为的参数。
81
+
82
+ 使用 int8 量化 (To use int8 quantization):
83
+
84
+ ```python
85
+ model = AutoModelForCausalLM.from_pretrained("AlpachinoNLP/Baichuan-7B-Instruction", torch_dtype=torch.float16, trust_remote_code=True)
86
+ model = model.quantize(8).cuda()
87
+ ```
88
+
89
+ 同样的,如需使用 int4 量化 (Similarly, to use int4 quantization):
90
+
91
+ ```python
92
+ model = AutoModelForCausalLM.from_pretrained("AlpachinoNLP/Baichuan-7B-Instruction", torch_dtype=torch.float16, trust_remote_code=True)
93
+ model = model.quantize(4).cuda()
94
+ ```
95
+
96
+ ## 训练详情
97
+
98
+ 数据集:https://huggingface.co/datasets/shareAI/ShareGPT-Chinese-English-90k。
99
+
100
+ 硬件:8*A40
101
+
102
+ ## 测评结果
103
+
104
+ ## [CMMLU](https://github.com/haonan-li/CMMLU)
105
+
106
+ | Model zero-shot | STEM | Humanities | Social Sciences | Others | China Specific | Average |
107
+ | ------------------------------------------------------------ | :-------: | :--------: | :-------------: | :-------: | :------------: | :-------: |
108
+ | [ChatGLM2-6B](https://huggingface.co/THUDM/chatglm2-6b) | 41.28 | 52.85 | 53.37 | 52.24 | 50.58 | 49.95 |
109
+ | [Baichuan-7B](https://github.com/baichuan-inc/baichuan-7B) | 32.79 | 44.43 | 46.78 | 44.79 | 43.11 | 42.33 |
110
+ | [ChatGLM-6B](https://github.com/THUDM/GLM-130B) | 32.22 | 42.91 | 44.81 | 42.60 | 41.93 | 40.79 |
111
+ | [BatGPT-15B](https://arxiv.org/abs/2307.00360) | 33.72 | 36.53 | 38.07 | 46.94 | 38.32 | 38.51 |
112
+ | [Chinese-LLaMA-7B](https://github.com/ymcui/Chinese-LLaMA-Alpaca) | 26.76 | 26.57 | 27.42 | 28.33 | 26.73 | 27.34 |
113
+ | [MOSS-SFT-16B](https://github.com/OpenLMLab/MOSS) | 25.68 | 26.35 | 27.21 | 27.92 | 26.70 | 26.88 |
114
+ | [Chinese-GLM-10B](https://github.com/THUDM/GLM) | 25.57 | 25.01 | 26.33 | 25.94 | 25.81 | 25.80 |
115
+ | [Baichuan-13B](https://github.com/baichuan-inc/Baichuan-7B) | 42.04 | 60.49 | 59.55 | 56.60 | 55.72 | 54.63 |
116
+ | [Baichuan-13B-Chat](https://github.com/baichuan-inc/Baichuan-7B) | 37.32 | 56.24 | 54.79 | 54.07 | 52.23 | 50.48 |
117
+ | **Baichuan-13B-Instruction** | **42.56** | **62.09** | **60.41** | **58.97** | **56.95** | **55.88** |
118
+ | **Baichuan-7B-Instruction** | **33.94** | **46.31** | **47.73** | **45.84** | **44.88** | **43.53** |
119
+
120
+ > 说明:CMMLU 是一个综合性的中文评估基准,专门用于评估语言模型在中文语境下的知识和推理能力。我们直接使用其官方的[评测脚本](https://github.com/haonan-li/CMMLU)对模型进行评测。Model zero-shot 表格中 [Baichuan-13B-Chat](https://github.com/baichuan-inc/Baichuan-13B) 的得分来自我们直接运行 CMMLU 官方的评测脚本得到,其他模型的的得分来自于 [CMMLU](https://github.com/haonan-li/CMMLU/tree/master) 官方的评测结果.
121
+