Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: openrail
|
3 |
+
pipeline_tag: text-generation
|
4 |
+
library_name: transformers
|
5 |
+
language:
|
6 |
+
- zh
|
7 |
+
---
|
8 |
+
|
9 |
+
|
10 |
+
## Original model card
|
11 |
+
|
12 |
+
Buy me a coffee if you like this project ;)
|
13 |
+
<a href="https://www.buymeacoffee.com/s3nh"><img src="https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-1.svg" alt=""></a>
|
14 |
+
|
15 |
+
#### Description
|
16 |
+
|
17 |
+
GGML Format model files for [This project](https://huggingface.co/AlpachinoNLP/Baichuan-7B-Instruction).
|
18 |
+
|
19 |
+
|
20 |
+
### inference
|
21 |
+
|
22 |
+
|
23 |
+
```python
|
24 |
+
|
25 |
+
import ctransformers
|
26 |
+
|
27 |
+
from ctransformers import AutoModelForCausalLM
|
28 |
+
|
29 |
+
model = AutoModelForCausalLM.from_pretrained(output_dir, ggml_file,
|
30 |
+
gpu_layers=32, model_type="llama")
|
31 |
+
|
32 |
+
manual_input: str = "Tell me about your last dream, please."
|
33 |
+
|
34 |
+
|
35 |
+
llm(manual_input,
|
36 |
+
max_new_tokens=256,
|
37 |
+
temperature=0.9,
|
38 |
+
top_p= 0.7)
|
39 |
+
|
40 |
+
```
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
# Original model card
|
45 |
+
|
46 |
+
|
47 |
+
# Baichuan-7B-Instruction
|
48 |
+
|
49 |
+
![](./alpachino.png)
|
50 |
+
|
51 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
52 |
+
|
53 |
+
## 介绍
|
54 |
+
|
55 |
+
Baichuan-7B-Instruction 为 Baichuan-7B 系列模型进行指令微调后的版本,预训练模型可见 [Baichuan-7B](https://huggingface.co/baichuan-inc/Baichuan-7B)。
|
56 |
+
|
57 |
+
|
58 |
+
## Demo
|
59 |
+
|
60 |
+
如下是一个使用 gradio 的模型 demo
|
61 |
+
|
62 |
+
```python
|
63 |
+
import gradio as gr
|
64 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
65 |
+
|
66 |
+
tokenizer = AutoTokenizer.from_pretrained("AlpachinoNLP/Baichuan-7B-Instruction",trust_remote_code=True,use_fast=False)
|
67 |
+
model = AutoModelForCausalLM.from_pretrained("AlpachinoNLP/Baichuan-7B-Instruction",trust_remote_code=True ).half()
|
68 |
+
model.cuda()
|
69 |
+
|
70 |
+
def generate(histories, max_new_tokens=2048, do_sample = True, top_p = 0.95, temperature = 0.35, repetition_penalty=1.1):
|
71 |
+
prompt = ""
|
72 |
+
for history in histories:
|
73 |
+
history_with_identity = "\nHuman:" + history[0] + "\n\nAssistant:" + history[1]
|
74 |
+
prompt += history_with_identity
|
75 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
|
76 |
+
outputs = model.generate(
|
77 |
+
input_ids = input_ids,
|
78 |
+
max_new_tokens=max_new_tokens,
|
79 |
+
early_stopping=True,
|
80 |
+
do_sample=do_sample,
|
81 |
+
top_p=top_p,
|
82 |
+
temperature=temperature,
|
83 |
+
repetition_penalty=repetition_penalty,
|
84 |
+
)
|
85 |
+
rets = tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
86 |
+
generate_text = rets[0].replace(prompt, "")
|
87 |
+
return generate_text
|
88 |
+
|
89 |
+
with gr.Blocks() as demo:
|
90 |
+
chatbot = gr.Chatbot()
|
91 |
+
msg = gr.Textbox()
|
92 |
+
clear = gr.Button("clear")
|
93 |
+
|
94 |
+
def user(user_message, history):
|
95 |
+
return "", history + [[user_message, ""]]
|
96 |
+
|
97 |
+
def bot(history):
|
98 |
+
print(history)
|
99 |
+
bot_message = generate(history)
|
100 |
+
history[-1][1] = bot_message
|
101 |
+
return history
|
102 |
+
|
103 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
104 |
+
bot, chatbot, chatbot
|
105 |
+
)
|
106 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
107 |
+
|
108 |
+
if __name__ == "__main__":
|
109 |
+
demo.launch(server_name="0.0.0.0")
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
```
|
114 |
+
|
115 |
+
## 量化部署
|
116 |
+
|
117 |
+
Baichuan-7B 支持 int8 和 int4 量化,用户只需在推理代码中简单修改两行即可实现。请注意,如果是为了节省显存而进行量化,应加载原始精度模型到 CPU 后再开始量化;避免在 `from_pretrained` 时添加 `device_map='auto'` 或者其它会导致把原始精度模型直接加载到 GPU 的行为的参数。
|
118 |
+
|
119 |
+
使用 int8 量化 (To use int8 quantization):
|
120 |
+
|
121 |
+
```python
|
122 |
+
model = AutoModelForCausalLM.from_pretrained("AlpachinoNLP/Baichuan-7B-Instruction", torch_dtype=torch.float16, trust_remote_code=True)
|
123 |
+
model = model.quantize(8).cuda()
|
124 |
+
```
|
125 |
+
|
126 |
+
同样的,如需使用 int4 量化 (Similarly, to use int4 quantization):
|
127 |
+
|
128 |
+
```python
|
129 |
+
model = AutoModelForCausalLM.from_pretrained("AlpachinoNLP/Baichuan-7B-Instruction", torch_dtype=torch.float16, trust_remote_code=True)
|
130 |
+
model = model.quantize(4).cuda()
|
131 |
+
```
|
132 |
+
|
133 |
+
## 训练详情
|
134 |
+
|
135 |
+
数据集:https://huggingface.co/datasets/shareAI/ShareGPT-Chinese-English-90k。
|
136 |
+
|
137 |
+
硬件:8*A40
|
138 |
+
|
139 |
+
## 测评结果
|
140 |
+
|
141 |
+
## [CMMLU](https://github.com/haonan-li/CMMLU)
|
142 |
+
|
143 |
+
| Model 5-shot | STEM | Humanities | Social Sciences | Others | China Specific | Average |
|
144 |
+
| ---------------------------------------------------------- | :-------: | :--------: | :-------------: | :------: | :------------: | :------: |
|
145 |
+
| Baichuan-7B | 34.4 | 47.5 | 47.6 | 46.6 | 44.3 | 44.0 |
|
146 |
+
| Vicuna-13B | 31.8 | 36.2 | 37.6 | 39.5 | 34.3 | 36.3 |
|
147 |
+
| Chinese-Alpaca-Plus-13B | 29.8 | 33.4 | 33.2 | 37.9 | 32.1 | 33.4 |
|
148 |
+
| Chinese-LLaMA-Plus-13B | 28.1 | 33.1 | 35.4 | 35.1 | 33.5 | 33.0 |
|
149 |
+
| Ziya-LLaMA-13B-Pretrain | 29.0 | 30.7 | 33.8 | 34.4 | 31.9 | 32.1 |
|
150 |
+
| LLaMA-13B | 29.2 | 30.8 | 31.6 | 33.0 | 30.5 | 31.2 |
|
151 |
+
| moss-moon-003-base (16B) | 27.2 | 30.4 | 28.8 | 32.6 | 28.7 | 29.6 |
|
152 |
+
| Baichuan-13B-Base | 41.7 | 61.1 | 59.8 | 59.0 | 56.4 | 55.3 |
|
153 |
+
| Baichuan-13B-Chat | 42.8 | 62.6 | 59.7 | 59.0 | 56.1 | 55.8 |
|
154 |
+
| Baichuan-13B-Instruction | 44.50 | 61.16 | 59.07 | 58.34 | 55.55 | 55.61 |
|
155 |
+
| **Baichuan-7B-Instruction** | **34.68** | **47.38** | **47.13** | **45.11** | **44.51** | **43.57** |
|
156 |
+
|
157 |
+
| Model zero-shot | STEM | Humanities | Social Sciences | Others | China Specific | Average |
|
158 |
+
| ------------------------------------------------------------ | :-------: | :--------: | :-------------: | :-------: | :------------: | :-------: |
|
159 |
+
| [ChatGLM2-6B](https://huggingface.co/THUDM/chatglm2-6b) | 41.28 | 52.85 | 53.37 | 52.24 | 50.58 | 49.95 |
|
160 |
+
| [Baichuan-7B](https://github.com/baichuan-inc/baichuan-7B) | 32.79 | 44.43 | 46.78 | 44.79 | 43.11 | 42.33 |
|
161 |
+
| [ChatGLM-6B](https://github.com/THUDM/GLM-130B) | 32.22 | 42.91 | 44.81 | 42.60 | 41.93 | 40.79 |
|
162 |
+
| [BatGPT-15B](https://arxiv.org/abs/2307.00360) | 33.72 | 36.53 | 38.07 | 46.94 | 38.32 | 38.51 |
|
163 |
+
| [Chinese-LLaMA-7B](https://github.com/ymcui/Chinese-LLaMA-Alpaca) | 26.76 | 26.57 | 27.42 | 28.33 | 26.73 | 27.34 |
|
164 |
+
| [MOSS-SFT-16B](https://github.com/OpenLMLab/MOSS) | 25.68 | 26.35 | 27.21 | 27.92 | 26.70 | 26.88 |
|
165 |
+
| [Chinese-GLM-10B](https://github.com/THUDM/GLM) | 25.57 | 25.01 | 26.33 | 25.94 | 25.81 | 25.80 |
|
166 |
+
| [Baichuan-13B](https://github.com/baichuan-inc/Baichuan-7B) | 42.04 | 60.49 | 59.55 | 56.60 | 55.72 | 54.63 |
|
167 |
+
| [Baichuan-13B-Chat](https://github.com/baichuan-inc/Baichuan-7B) | 37.32 | 56.24 | 54.79 | 54.07 | 52.23 | 50.48 |
|
168 |
+
| Baichuan-13B-Instruction | 42.56 | 62.09 | 60.41 | 58.97 | 56.95 | 55.88 |
|
169 |
+
| **Baichuan-7B-Instruction** | **33.94** | **46.31** | **47.73** | **45.84** | **44.88** | **43.53** |
|
170 |
+
|
171 |
+
> 说明: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) 官方的评测结果.
|
172 |
+
|
173 |
+
### 英文能力评测
|
174 |
+
除了中文榜单的测试,我们同样测试了模型在英文榜单 MMLU 上的能力。
|
175 |
+
|
176 |
+
#### MMLU
|
177 |
+
|
178 |
+
[MMLU](https://arxiv.org/abs/2009.03300) 是一个包含了57种任务的英文评测数据集。
|
179 |
+
我们采用了开源的[评测方案]((https://github.com/hendrycks/test)) , 评测结果如下:
|
180 |
+
|
181 |
+
| Model | Humanities | Social Sciences | STEM | Other | Average |
|
182 |
+
|----------------------------------------|-----------:|:---------------:|:----:|:-----:|:-------:|
|
183 |
+
| LLaMA-7B<sup>2</sup> | 34.0 | 38.3 | 30.5 | 38.1 | 35.1 |
|
184 |
+
| Falcon-7B<sup>1</sup> | - | - | - | - | 35.0 |
|
185 |
+
| mpt-7B<sup>1</sup> | - | - | - | - | 35.6 |
|
186 |
+
| ChatGLM-6B<sup>0</sup> | 35.4 | 41.0 | 31.3 | 40.5 | 36.9 |
|
187 |
+
| BLOOM 7B<sup>0</sup> | 25.0 | 24.4 | 26.5 | 26.4 | 25.5 |
|
188 |
+
| BLOOMZ 7B<sup>0</sup> | 31.3 | 42.1 | 34.4 | 39.0 | 36.1 |
|
189 |
+
| moss-moon-003-base (16B)<sup>0</sup> | 24.2 | 22.8 | 22.4 | 24.4 | 23.6 |
|
190 |
+
| moss-moon-003-sft (16B)<sup>0</sup> | 30.5 | 33.8 | 29.3 | 34.4 | 31.9 |
|
191 |
+
| Baichuan-7B<sup>0</sup> | 38.4 | 48.9 | 35.6 | 48.1 | 42.3 |
|
192 |
+
| **Baichuan-7B-Instruction(5-shot)** | **38.9** | **49.0** | **35.3** | **48.8** | **42.6** |
|
193 |
+
| **Baichuan-7B-Instruction(0-shot)** | **38.7** | **47.9** | **34.5** | **48.2** | **42.0** |
|
194 |
+
|
195 |
+
|