RanchiZhao commited on
Commit
e5048ea
·
verified ·
1 Parent(s): a646dd8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +294 -3
README.md CHANGED
@@ -1,3 +1,294 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+ <div align="center">
5
+ <img src="https://github.com/OpenBMB/MiniCPM/tree/main/assets/minicpm_logo.png" width="500em" ></img>
6
+ </div>
7
+
8
+ <p align="center">
9
+ <a href="https://github.com/OpenBMB/MiniCPM/" target="_blank">MiniCPM Repo</a> |
10
+ <a href="https://arxiv.org/abs/2404.06395" target="_blank">MiniCPM Paper</a> |
11
+ <a href="https://github.com/OpenBMB/MiniCPM-V/" target="_blank">MiniCPM-V Repo</a> |
12
+ Join us in <a href="https://discord.gg/3cGQn9b3YM" target="_blank">Discord</a> and <a href="https://github.com/OpenBMB/MiniCPM/blob/main/assets/wechat.jpg" target="_blank">WeChat</a>
13
+
14
+ </p>
15
+
16
+ ## Introduction
17
+ MiniCPM3-4B is the 3rd generation of MiniCPM series. The overall performance of MiniCPM3-4B surpasses Phi-3.5-mini-Instruct and GPT-3.5-Turbo-0125, being comparable with many recent 7B~9B models.
18
+
19
+ Compared to MiniCPM1.0/MiniCPM2.0, MiniCPM3-4B has a more powerful and versatile skill set to enable more general usage. MiniCPM3-4B supports function call, along with code interpreter. Please refer to [Advanced Features](https://github.com/zh-zheng/minicpm?tab=readme-ov-file#%E8%BF%9B%E9%98%B6%E5%8A%9F%E8%83%BD) for usage guidelines.
20
+
21
+ MiniCPM3-4B has a 32k context window. Equipped with LLMxMapReduce, MiniCPM3-4B can handle infinite context theoretically, without requiring huge amount of memory.
22
+
23
+ ## Usage
24
+ ### Inference with Transformers
25
+ ```python
26
+ from transformers import AutoModelForCausalLM, AutoTokenizer
27
+ import torch
28
+
29
+ path = "openbmb/MiniCPM3-4B-GPTQ-int4"
30
+ device = "cuda"
31
+
32
+ tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
33
+ model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)
34
+
35
+ messages = [
36
+ {"role": "user", "content": "推荐5个北京的景点。"},
37
+ ]
38
+ model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(device)
39
+
40
+ model_outputs = model.generate(
41
+ model_inputs,
42
+ max_new_tokens=1024,
43
+ top_p=0.7,
44
+ temperature=0.7,
45
+ repetition_penalty=1.02
46
+ )
47
+
48
+ output_token_ids = [
49
+ model_outputs[i][len(model_inputs[i]):] for i in range(len(model_inputs))
50
+ ]
51
+
52
+ responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0]
53
+ print(responses)
54
+ ```
55
+
56
+ ### Inference with [vLLM](https://github.com/vllm-project/vllm)
57
+ ```python
58
+ from transformers import AutoTokenizer
59
+ from vllm import LLM, SamplingParams
60
+
61
+ model_name = "openbmb/MiniCPM3-4B-GPTQ-int4"
62
+ prompt = [{"role": "user", "content": "推荐5个北京的景点。"}]
63
+
64
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
65
+ input_text = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
66
+
67
+ llm = LLM(
68
+ model=model_name,
69
+ trust_remote_code=True,
70
+ tensor_parallel_size=1,
71
+ quantization='gptq'
72
+ )
73
+ sampling_params = SamplingParams(top_p=0.7, temperature=0.7, max_tokens=1024, repetition_penalty=1.02)
74
+
75
+ outputs = llm.generate(prompts=input_text, sampling_params=sampling_params)
76
+
77
+ print(outputs[0].outputs[0].text)
78
+ ```
79
+
80
+ ## Evaluation Results
81
+
82
+ <table>
83
+ <tr>
84
+ <td>Benchmark</td>
85
+ <td>Qwen2-7B-Instruct</td>
86
+ <td>GLM-4-9B-Chat</td>
87
+ <td>Gemma2-9B-it</td>
88
+ <td>Llama3.1-8B-Instruct</td>
89
+ <td>GPT-3.5-Turbo-0125</td>
90
+ <td>Phi-3.5-mini-Instruct(3.8B)</td>
91
+ <td>MiniCPM3-4B </td>
92
+ </tr>
93
+ <tr>
94
+ <td colspan="15" align="left"><strong>English</strong></td>
95
+ </tr>
96
+ <tr>
97
+ <td>MMLU</td>
98
+ <td>70.5</td>
99
+ <td>72.4</td>
100
+ <td>72.6</td>
101
+ <td>69.4</td>
102
+ <td>69.2</td>
103
+ <td>68.4</td>
104
+ <td>67.2 </td>
105
+ </tr>
106
+ <tr>
107
+ <td>BBH</td>
108
+ <td>64.9</td>
109
+ <td>76.3</td>
110
+ <td>65.2</td>
111
+ <td>67.8</td>
112
+ <td>70.3</td>
113
+ <td>68.6</td>
114
+ <td>70.2 </td>
115
+ </tr>
116
+ <tr>
117
+ <td>MT-Bench</td>
118
+ <td>8.41</td>
119
+ <td>8.35</td>
120
+ <td>7.88</td>
121
+ <td>8.28</td>
122
+ <td>8.17</td>
123
+ <td>8.60</td>
124
+ <td>8.41 </td>
125
+ </tr>
126
+ <tr>
127
+ <td>IFEVAL (Prompt Strict-Acc.)</td>
128
+ <td>51.0</td>
129
+ <td>64.5</td>
130
+ <td>71.9</td>
131
+ <td>71.5</td>
132
+ <td>58.8</td>
133
+ <td>49.4</td>
134
+ <td>68.4 </td>
135
+ </tr>
136
+ <tr>
137
+ <td colspan="15" align="left"><strong>Chinese</strong></td>
138
+ </tr>
139
+ <tr>
140
+ <td>CMMLU</td>
141
+ <td>80.9</td>
142
+ <td>71.5</td>
143
+ <td>59.5</td>
144
+ <td>55.8</td>
145
+ <td>54.5</td>
146
+ <td>46.9</td>
147
+ <td>73.3 </td>
148
+ </tr>
149
+ <tr>
150
+ <td>CEVAL</td>
151
+ <td>77.2</td>
152
+ <td>75.6</td>
153
+ <td>56.7</td>
154
+ <td>55.2</td>
155
+ <td>52.8</td>
156
+ <td>46.1</td>
157
+ <td>73.6 </td>
158
+ </tr>
159
+ <tr>
160
+ <td>AlignBench v1.1</td>
161
+ <td>7.10</td>
162
+ <td>6.61</td>
163
+ <td>7.10</td>
164
+ <td>5.68</td>
165
+ <td>5.82</td>
166
+ <td>5.73</td>
167
+ <td>6.74 </td>
168
+ </tr>
169
+ <tr>
170
+ <td>FollowBench-zh (SSR)</td>
171
+ <td>63.0</td>
172
+ <td>56.4</td>
173
+ <td>57.0</td>
174
+ <td>50.6</td>
175
+ <td>64.6</td>
176
+ <td>58.1</td>
177
+ <td>66.8 </td>
178
+ </tr>
179
+ <tr>
180
+ <td colspan="15" align="left"><strong>Math</strong></td>
181
+ </tr>
182
+ <tr>
183
+ <td>MATH</td>
184
+ <td>49.6</td>
185
+ <td>50.6</td>
186
+ <td>46.0</td>
187
+ <td>51.9</td>
188
+ <td>41.8</td>
189
+ <td>46.4</td>
190
+ <td>46.6 </td>
191
+ </tr>
192
+ <tr>
193
+ <td>GSM8K</td>
194
+ <td>82.3</td>
195
+ <td>79.6</td>
196
+ <td>79.7</td>
197
+ <td>84.5</td>
198
+ <td>76.4</td>
199
+ <td>82.7</td>
200
+ <td>81.1 </td>
201
+ </tr>
202
+ <tr>
203
+ <td>MathBench</td>
204
+ <td>63.4</td>
205
+ <td>59.4</td>
206
+ <td>45.8</td>
207
+ <td>54.3</td>
208
+ <td>48.9</td>
209
+ <td>54.9</td>
210
+ <td>65.6 </td>
211
+ </tr>
212
+ <tr>
213
+ <td colspan="15" align="left"><strong>Code</strong></td>
214
+ </tr>
215
+ <tr>
216
+ <td>HumanEval+</td>
217
+ <td>70.1</td>
218
+ <td>67.1</td>
219
+ <td>61.6</td>
220
+ <td>62.8</td>
221
+ <td>66.5</td>
222
+ <td>68.9</td>
223
+ <td>68.3 </td>
224
+ </tr>
225
+ <tr>
226
+ <td>MBPP+</td>
227
+ <td>57.1</td>
228
+ <td>62.2</td>
229
+ <td>64.3</td>
230
+ <td>55.3</td>
231
+ <td>71.4</td>
232
+ <td>55.8</td>
233
+ <td>63.2 </td>
234
+ </tr>
235
+ <tr>
236
+ <td>LiveCodeBench</td>
237
+ <td>22.2</td>
238
+ <td>20.2</td>
239
+ <td>19.2</td>
240
+ <td>20.4</td>
241
+ <td>24.0</td>
242
+ <td>19.6</td>
243
+ <td>22.6 </td>
244
+ </tr>
245
+ <tr>
246
+ <td colspan="15" align="left"><strong>Function Call</strong></td>
247
+ </tr>
248
+ <tr>
249
+ <td>BFCL</td>
250
+ <td>71.6</td>
251
+ <td>70.1</td>
252
+ <td>19.2</td>
253
+ <td>73.3</td>
254
+ <td>75.4</td>
255
+ <td>48.4</td>
256
+ <td>76.0 </td>
257
+ </tr>
258
+ <tr>
259
+ <td colspan="15" align="left"><strong>Overall</strong></td>
260
+ </tr>
261
+ <tr>
262
+ <td>Average</td>
263
+ <td>65.3</td>
264
+ <td>65.0</td>
265
+ <td>57.9</td>
266
+ <td>60.8</td>
267
+ <td>61.0</td>
268
+ <td>57.2</td>
269
+ <td><strong>66.3</strong></td>
270
+ </tr>
271
+ </table>
272
+
273
+
274
+ ## Statement
275
+ * As a language model, MiniCPM3-4B generates content by learning from a vast amount of text.
276
+ * However, it does not possess the ability to comprehend or express personal opinions or value judgments.
277
+ * Any content generated by MiniCPM3-4B does not represent the viewpoints or positions of the model developers.
278
+ * Therefore, when using content generated by MiniCPM3-4B, users should take full responsibility for evaluating and verifying it on their own.
279
+
280
+ ## LICENSE
281
+ * This repository is released under the [Apache-2.0](https://github.com/OpenBMB/MiniCPM/blob/main/LICENSE) License.
282
+ * The usage of MiniCPM3-4B model weights must strictly follow [MiniCPM Model License.md](https://github.com/OpenBMB/MiniCPM/blob/main/MiniCPM%20Model%20License.md).
283
+ * The models and weights of MiniCPM3-4B are completely free for academic research. after filling out a ["questionnaire"](https://modelbest.feishu.cn/share/base/form/shrcnpV5ZT9EJ6xYjh3Kx0J6v8g) for registration, are also available for free commercial use.
284
+
285
+ ## Citation
286
+
287
+ ```
288
+ @article{hu2024minicpm,
289
+ title={MiniCPM: Unveiling the Potential of Small Language Models with Scalable Training Strategies},
290
+ author={Hu, Shengding and Tu, Yuge and Han, Xu and He, Chaoqun and Cui, Ganqu and Long, Xiang and Zheng, Zhi and Fang, Yewei and Huang, Yuxiang and Zhao, Weilin and others},
291
+ journal={arXiv preprint arXiv:2404.06395},
292
+ year={2024}
293
+ }
294
+ ```