haijunlv commited on
Commit
6170223
·
verified ·
1 Parent(s): 790e9de

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +569 -3
README.md CHANGED
@@ -1,3 +1,569 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # InternLM
2
+
3
+
4
+
5
+ <div align="center">
6
+ <img src="https://github.com/InternLM/InternLM/assets/22529082/b9788105-8892-4398-8b47-b513a292378e" width="200"/>
7
+
8
+ <div>&nbsp;</div>
9
+ <div align="center">
10
+ <b><font size="5">InternLM</font></b>
11
+ <sup>
12
+ <a href="https://internlm.intern-ai.org.cn/">
13
+ <i><font size="4">HOT</font></i>
14
+ </a>
15
+ </sup>
16
+ <div>&nbsp;</div>
17
+ </div>
18
+ [![evaluation](https://github.com/InternLM/InternLM/assets/22529082/f80a2a58-5ddf-471a-8da4-32ab65c8fd3b)](https://github.com/internLM/OpenCompass/)
19
+
20
+ [💻Github Repo](https://github.com/InternLM/InternLM) • [🤔Reporting Issues](https://github.com/InternLM/InternLM/issues/new) • [📜Technical Report](https://arxiv.org/abs/2403.17297)
21
+
22
+ </div>
23
+
24
+ <p align="center">
25
+ 👋 join us on <a href="https://discord.gg/xa29JuW87d" target="_blank">Discord</a> and <a href="https://github.com/InternLM/InternLM/assets/25839884/a6aad896-7232-4220-ac84-9e070c2633ce" target="_blank">WeChat</a>
26
+ </p>
27
+
28
+
29
+
30
+ ## Introduction
31
+
32
+ InternLM3 has open-sourced an 8 billion parameter instruction model, InternLM3-8B-Instruct, designed for general-purpose usage and advanced reasoning. This model has the following characteristics:
33
+
34
+ - **Enhanced performance at reduced cost**:
35
+ State-of-the-art performance on reasoning and knowledge-intensive tasks surpass models like Llama3.1-8B and Qwen2.5-7B. Remarkably, InternLM3 is trained on only 4 trillion high-quality tokens, saving more than 75% of the training cost compared to other LLMs of similar scale.
36
+
37
+ - **Deep thinking capability**:
38
+ InternLM3 supports both the deep thinking mode for solving complicated reasoning tasks via the long chain-of-thought and the normal response mode for fluent user interactions.
39
+
40
+ - **Web browser use**:
41
+ InternLM3 is the first general-purpose LLM in the open-source community to support browser usage. Leveraging the deep thinking capability, InternLM3 enables over 20 steps of web navigation for in-depth information retrieval and summary.
42
+
43
+ ## InternLM3-8B-Instruct
44
+
45
+ ### Performance Evaluation
46
+
47
+ We conducted a comprehensive evaluation of InternLM using the open-source evaluation tool [OpenCompass](https://github.com/internLM/OpenCompass/). The evaluation covered five dimensions of capabilities: disciplinary competence, language competence, knowledge competence, inference competence, and comprehension competence. Here are some of the evaluation results, and you can visit the [OpenCompass leaderboard](https://rank.opencompass.org.cn) for more evaluation results.
48
+
49
+ | Benchmark | | InternLM3-8B-Instruct | Qwen2.5-7B-Instruct | Llama3.1-8B-Instruct | GPT-4o-mini(close source) |
50
+ | ------------ | ------------------------------- | --------------------- | ------------------- | -------------------- | ------------------------- |
51
+ | General | CMMLU (0-shot) | **83.1** | 75.8 | 53.9 | 66.0 |
52
+ | | MMLU(0-shot) | 76.6 | **76.8** | 71.8 | 82.7 |
53
+ | | MMLU-Pro(0-shot) | **57.6** | 56.2 | 48.1 | 64.1 |
54
+ | Reasoning | GPQA-Diamond(0-shot) | **37.4** | 33.3 | 24.2 | 42.9 |
55
+ | | DROP(0-shot) | **83.1** | 80.4 | 81.6 | 85.2 |
56
+ | | HellaSwag(10-shot) | **91.2** | 85.3 | 76.7 | 89.5 |
57
+ | | KOR-Bench(0-shot) | **56.4** | 44.6 | 47.7 | 58.2 |
58
+ | MATH | MATH-500(0-shot Thinking Mode) | **83.0** | 72.4 | 48.4 | 74.0 |
59
+ | | AIME2024(0-shot Thinking Mode) | **20.0** | 16.7 | 6.7 | 13.3 |
60
+ | Coding | LiveCodeBench(2407-2409 Pass@1) | **17.8** | 16.8 | 12.9 | 21.8 |
61
+ | | HumanEval(Pass@1) | 82.3 | **85.4** | 72.0 | 86.6 |
62
+ | Instrunction | IFEval(Prompt-Strict) | **79.3** | 71.7 | 75.2 | 79.7 |
63
+ | LongContext | RULER(4-128K Average) | 87.9 | 81.4 | **88.5** | 90.7 |
64
+ | Chat | AlpacaEval 2.0(LC WinRate) | **51.1** | 30.3 | 25.0 | 50.7 |
65
+ | | WildBench(Raw Score) | **33.1** | 23.3 | 1.5 | 40.3 |
66
+ | | MT-Bench-101(Score 1-10) | **8.59** | 8.49 | 8.37 | 8.87 |
67
+ - The evaluation results were obtained from [OpenCompass](https://github.com/internLM/OpenCompass/) (some data marked with *, which means come from the original papers), and evaluation configuration can be found in the configuration files provided by [OpenCompass](https://github.com/internLM/OpenCompass/).
68
+ - The evaluation data may have numerical differences due to the version iteration of [OpenCompass](https://github.com/internLM/OpenCompass/), so please refer to the latest evaluation results of [OpenCompass](https://github.com/internLM/OpenCompass/).
69
+
70
+ **Limitations:** Although we have made efforts to ensure the safety of the model during the training process and to encourage the model to generate text that complies with ethical and legal requirements, the model may still produce unexpected outputs due to its size and probabilistic generation paradigm. For example, the generated responses may contain biases, discrimination, or other harmful content. Please do not propagate such content. We are not responsible for any consequences resulting from the dissemination of harmful information.
71
+
72
+ ### Conersation Mode
73
+
74
+ #### Transformers inference
75
+
76
+ To load the InternLM3 8B Instruct model using Transformers, use the following code:
77
+
78
+ ```python
79
+ import torch
80
+ from transformers import AutoTokenizer, AutoModelForCausalLM
81
+
82
+ model_dir = "internlm/internlm3-8b-instruct"
83
+ tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
84
+ # Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
85
+ # model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.float16)
86
+ # (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes.
87
+ # InternLM3 8B in 4bit will cost nearly 8GB GPU memory.
88
+ # pip install -U bitsandbytes
89
+ # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True)
90
+ # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True)
91
+ model = model.eval()
92
+
93
+ system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
94
+ - InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
95
+ - InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."""
96
+ messages = [
97
+ {"role": "system", "content": system_prompt},
98
+ {"role": "user", "content": "Please tell me five scenic spots in Shanghai"},
99
+ ]
100
+ tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
101
+
102
+ generated_ids = model.generate(tokenized_chat, max_new_tokens=1024, temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8)
103
+
104
+ generated_ids = [
105
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids)
106
+ ]
107
+ response = tokenizer.batch_decode(generated_ids)[0]
108
+ print(response)
109
+ ```
110
+
111
+ #### LMDeploy inference
112
+ LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the MMRazor and MMDeploy teams.
113
+
114
+ ```bash
115
+ pip install lmdeploy
116
+ ```
117
+
118
+ You can run batch inference locally with the following python code:
119
+
120
+ ```python
121
+ import lmdeploy
122
+ model_dir = "internlm/internlm3-8b-instruct"
123
+ pipe = lmdeploy.pipeline(model_dir)
124
+ response = pipe(["Please tell me five scenic spots in Shanghai"])
125
+ print(response)
126
+
127
+ ```
128
+
129
+ Or you can launch an OpenAI compatible server with the following command:
130
+
131
+ ```bash
132
+ lmdeploy serve api_server internlm/internlm3-8b-instruct --model-name internlm3-8b-instruct --server-port 23333
133
+ ```
134
+
135
+ Then you can send a chat request to the server:
136
+
137
+ ```bash
138
+ curl http://localhost:23333/v1/chat/completions \
139
+ -H "Content-Type: application/json" \
140
+ -d '{
141
+ "model": "internlm3-8b-instruct",
142
+ "messages": [
143
+ {"role": "user", "content": "Please tell me five scenic spots in Shanghai"}
144
+ ]
145
+ }'
146
+ ```
147
+
148
+ Find more details in the [LMDeploy documentation](https://lmdeploy.readthedocs.io/en/latest/)
149
+
150
+
151
+
152
+ #### vLLM inference
153
+
154
+ TODO
155
+
156
+
157
+
158
+ ### Thinking Mode
159
+ #### puzzle demo
160
+
161
+ <div align="center">
162
+ <img src="https://github.com/InternLM/InternLM/blob/017ba7446d20ecc3b9ab8e7b66cc034500868ab4/assets/solve_puzzle.png?raw=true" width="400"/>
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+ #### Thinking system prompt
171
+ ```python
172
+ thinking_system_prompt = """You are an expert mathematician with extensive experience in mathematical competitions. You approach problems through systematic thinking and rigorous reasoning. When solving problems, follow these thought processes:
173
+ ## Deep Understanding
174
+ Take time to fully comprehend the problem before attempting a solution. Consider:
175
+ - What is the real question being asked?
176
+ - What are the given conditions and what do they tell us?
177
+ - Are there any special restrictions or assumptions?
178
+ - Which information is crucial and which is supplementary?
179
+ ## Multi-angle Analysis
180
+ Before solving, conduct thorough analysis:
181
+ - What mathematical concepts and properties are involved?
182
+ - Can you recall similar classic problems or solution methods?
183
+ - Would diagrams or tables help visualize the problem?
184
+ - Are there special cases that need separate consideration?
185
+ ## Systematic Thinking
186
+ Plan your solution path:
187
+ - Propose multiple possible approaches
188
+ - Analyze the feasibility and merits of each method
189
+ - Choose the most appropriate method and explain why
190
+ - Break complex problems into smaller, manageable steps
191
+ ## Rigorous Proof
192
+ During the solution process:
193
+ - Provide solid justification for each step
194
+ - Include detailed proofs for key conclusions
195
+ - Pay attention to logical connections
196
+ - Be vigilant about potential oversights
197
+ ## Repeated Verification
198
+ After completing your solution:
199
+ - Verify your results satisfy all conditions
200
+ - Check for overlooked special cases
201
+ - Consider if the solution can be optimized or simplified
202
+ - Review your reasoning process
203
+ Remember:
204
+ 1. Take time to think thoroughly rather than rushing to an answer
205
+ 2. Rigorously prove each key conclusion
206
+ 3. Keep an open mind and try different approaches
207
+ 4. Summarize valuable problem-solving methods
208
+ 5. Maintain healthy skepticism and verify multiple times
209
+ Your response should reflect deep mathematical understanding and precise logical thinking, making your solution path and reasoning clear to others.
210
+ When you're ready, present your complete solution with:
211
+ - Clear problem understanding
212
+ - Detailed solution process
213
+ - Key insights
214
+ - Thorough verification
215
+ Focus on clear, logical progression of ideas and thorough explanation of your mathematical reasoning. Provide answers in the same language as the user asking the question, repeat the final answer using a '\\boxed{}' without any units, you have [[8192]] tokens to complete the answer.
216
+ """
217
+ ```
218
+ #### Transformers inference
219
+ ```python
220
+ import torch
221
+ from transformers import AutoTokenizer, AutoModelForCausalLM
222
+
223
+ model_dir = "internlm/internlm3-8b-instruct"
224
+ tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
225
+ # Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
226
+ model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.float16)
227
+ # (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes.
228
+ # InternLM3 8B in 4bit will cost nearly 8GB GPU memory.
229
+ # pip install -U bitsandbytes
230
+ # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True)
231
+ # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True)
232
+ model = model.eval()
233
+
234
+ messages = [
235
+ {"role": "system", "content": thinking_system_prompt},
236
+ {"role": "user", "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."},
237
+ ]
238
+ tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
239
+
240
+ generated_ids = model.generate(tokenized_chat, max_new_tokens=8192)
241
+
242
+ generated_ids = [
243
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids)
244
+ ]
245
+ response = tokenizer.batch_decode(generated_ids)[0]
246
+ print(response)
247
+ ```
248
+ #### LMDeploy inference
249
+
250
+ LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the MMRazor and MMDeploy teams.
251
+
252
+ ```bash
253
+ pip install lmdeploy
254
+ ```
255
+
256
+ You can run batch inference locally with the following python code:
257
+
258
+ ```python
259
+ from lmdeploy import pipeline, GenerationConfig, ChatTemplateConfig
260
+ model_dir = "internlm/internlm3-8b-instruct"
261
+ chat_template_config = ChatTemplateConfig(model_name='internlm3')
262
+ pipe = pipeline(model_dir, chat_template_config=chat_template_config)
263
+
264
+ messages = [
265
+ {"role": "system", "content": thinking_system_prompt},
266
+ {"role": "user", "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."},
267
+ ]
268
+
269
+ response = pipe(messages, gen_config=GenerationConfig(max_new_tokens=2048))
270
+ print(response)
271
+ ```
272
+
273
+ #### vLLM inference
274
+
275
+ TODO
276
+
277
+
278
+
279
+ ## Open Source License
280
+
281
+ The code is licensed under Apache-2.0, while model weights are fully open for academic research and also allow **free** commercial usage. To apply for a commercial license, please fill in the [application form (English)](https://wj.qq.com/s2/12727483/5dba/)/[申请表(中文)](https://wj.qq.com/s2/12725412/f7c1/). For other questions or collaborations, please contact <internlm@pjlab.org.cn>.
282
+
283
+ ## Citation
284
+
285
+ ```
286
+ @misc{cai2024internlm2,
287
+ title={InternLM2 Technical Report},
288
+ author={Zheng Cai and Maosong Cao and Haojiong Chen and Kai Chen and Keyu Chen and Xin Chen and Xun Chen and Zehui Chen and Zhi Chen and Pei Chu and Xiaoyi Dong and Haodong Duan and Qi Fan and Zhaoye Fei and Yang Gao and Jiaye Ge and Chenya Gu and Yuzhe Gu and Tao Gui and Aijia Guo and Qipeng Guo and Conghui He and Yingfan Hu and Ting Huang and Tao Jiang and Penglong Jiao and Zhenjiang Jin and Zhikai Lei and Jiaxing Li and Jingwen Li and Linyang Li and Shuaibin Li and Wei Li and Yining Li and Hongwei Liu and Jiangning Liu and Jiawei Hong and Kaiwen Liu and Kuikun Liu and Xiaoran Liu and Chengqi Lv and Haijun Lv and Kai Lv and Li Ma and Runyuan Ma and Zerun Ma and Wenchang Ning and Linke Ouyang and Jiantao Qiu and Yuan Qu and Fukai Shang and Yunfan Shao and Demin Song and Zifan Song and Zhihao Sui and Peng Sun and Yu Sun and Huanze Tang and Bin Wang and Guoteng Wang and Jiaqi Wang and Jiayu Wang and Rui Wang and Yudong Wang and Ziyi Wang and Xingjian Wei and Qizhen Weng and Fan Wu and Yingtong Xiong and Chao Xu and Ruiliang Xu and Hang Yan and Yirong Yan and Xiaogui Yang and Haochen Ye and Huaiyuan Ying and Jia Yu and Jing Yu and Yuhang Zang and Chuyu Zhang and Li Zhang and Pan Zhang and Peng Zhang and Ruijie Zhang and Shuo Zhang and Songyang Zhang and Wenjian Zhang and Wenwei Zhang and Xingcheng Zhang and Xinyue Zhang and Hui Zhao and Qian Zhao and Xiaomeng Zhao and Fengzhe Zhou and Zaida Zhou and Jingming Zhuo and Yicheng Zou and Xipeng Qiu and Yu Qiao and Dahua Lin},
289
+ year={2024},
290
+ eprint={2403.17297},
291
+ archivePrefix={arXiv},
292
+ primaryClass={cs.CL}
293
+ }
294
+ ```
295
+
296
+
297
+
298
+ ## 简介
299
+
300
+ ### InternLM3-8B-Instruct
301
+
302
+ InternLM3,即书生·浦语大模型第3代,开源了80亿参数,面向通用使用与高阶推理的指令模型(InternLM3-8B-Instruct)。模型具备以下特点:
303
+
304
+ - **更低的代价取得更高的性能**:
305
+ 在推理、知识类任务上取得同量级最优性能,超过Llama3.1-8B和Qwen2.5-7B. 值得关注的是InternLM3只用了4万亿词元进行训练,对比同级别模型训练成本节省75%以上。
306
+
307
+ - **深度思考能力**:
308
+ InternLM3支持通过长思维链求解复杂推理任务的深度思考模式,同时还兼顾了用户体验更流畅的通用回复模式。
309
+
310
+ - **网页浏览能力**:
311
+ InternLM3是开源社区首个支持浏览器使用的通用对话模型。在深度思考能力的加持下,支持20步以上网页跳转以完成深度信息挖掘与整合。
312
+
313
+ #### 性能评测
314
+
315
+ 我们使用开源评测工具 [OpenCompass](https://github.com/internLM/OpenCompass/) 从学科综合能力、语言能力、知识能力、推理能力、理解能力五大能力维度对InternLM开展全面评测,部分评测结果如下表所示,欢迎访问[ OpenCompass 榜单 ](https://rank.opencompass.org.cn)获取更多的评测结果。
316
+
317
+ | 评测集\模型 | | InternLM3-8B-Instruct | Qwen2.5-7B-Instruct | Llama3.1-8B-Instruct | GPT-4o-mini(close source) |
318
+ | ------------ | ------------------------------- | --------------------- | ------------------- | -------------------- | ------------------------- |
319
+ | General | CMMLU (0-shot) | **83.1** | 75.8 | 53.9 | 66.0 |
320
+ | | MMLU(0-shot) | 76.6 | **76.8** | 71.8 | 82.7 |
321
+ | | MMLU-Pro(0-shot) | **57.6** | 56.2 | 48.1 | 64.1 |
322
+ | Reasoning | GPQA-Diamond(0-shot) | **37.4** | 33.3 | 24.2 | 42.9 |
323
+ | | DROP(0-shot) | **83.1** | 80.4 | 81.6 | 85.2 |
324
+ | | HellaSwag(10-shot) | **91.2** | 85.3 | 76.7 | 89.5 |
325
+ | | KOR-Bench(0-shot) | **56.4** | 44.6 | 47.7 | 58.2 |
326
+ | MATH | MATH-500(0-shot Thinking Mode) | **83.0** | 72.4 | 48.4 | 74.0 |
327
+ | | AIME2024(0-shot Thinking Mode) | **20.0** | 16.7 | 6.7 | 13.3 |
328
+ | Coding | LiveCodeBench(2407-2409 Pass@1) | **17.8** | 16.8 | 12.9 | 21.8 |
329
+ | | HumanEval(Pass@1) | 82.3 | **85.4** | 72.0 | 86.6 |
330
+ | Instrunction | IFEval(Prompt-Strict) | **79.3** | 71.7 | 75.2 | 79.7 |
331
+ | LongContext | RULER(4-128K Average) | 87.9 | 81.4 | **88.5** | 90.7 |
332
+ | Chat | AlpacaEval 2.0(LC WinRate) | **51.1** | 30.3 | 25.0 | 50.7 |
333
+ | | WildBench(Raw Score) | **33.1** | 23.3 | 1.5 | 40.3 |
334
+ | | MT-Bench-101(Score 1-10) | **8.59** | 8.49 | 8.37 | 8.87 |
335
+ - 以上评测结果基于 [OpenCompass](https://github.com/internLM/OpenCompass/) 获得(部分数据标注`*`代表数据来自原始论文),具体测试细节可参见 [OpenCompass](https://github.com/internLM/OpenCompass/) 中提供的配置文件。
336
+ - 评测数据会因 [OpenCompass](https://github.com/internLM/OpenCompass/) 的版本迭代而存在数值差异,请以 [OpenCompass](https://github.com/internLM/OpenCompass/) 最新版的评测结果为主。
337
+
338
+ **局限性:** 尽管在训练过程中我们非常注重模型的安全性,尽力促使模型输出符合伦理和法律要求的文本,但受限于模型大小以及概率生成范式,模型可能会产生各种不符合预期的输出,例如回复内容包含偏见、歧视等有害内容,请勿传播这些内容。由于传播不良信息导致的任何后果,本项目不承担责任。
339
+
340
+ #### 常规对话模式
341
+
342
+ ##### Transformers 推理
343
+
344
+ 通过以下的代码加载 InternLM3 8B Instruct 模型
345
+
346
+ ```python
347
+ import torch
348
+ from transformers import AutoTokenizer, AutoModelForCausalLM
349
+
350
+ model_dir = "internlm/internlm3-8b-instruct"
351
+ tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
352
+ # Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
353
+ # model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.float16)
354
+ # (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes.
355
+ # InternLM3 8B in 4bit will cost nearly 8GB GPU memory.
356
+ # pip install -U bitsandbytes
357
+ # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True)
358
+ # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True)
359
+ model = model.eval()
360
+
361
+ system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
362
+ - InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
363
+ - InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."""
364
+ messages = [
365
+ {"role": "system", "content": system_prompt},
366
+ {"role": "user", "content": "Please tell me five scenic spots in Shanghai"},
367
+ ]
368
+ tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
369
+
370
+ generated_ids = model.generate(tokenized_chat, max_new_tokens=1024, temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8)
371
+
372
+ generated_ids = [
373
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids)
374
+ ]
375
+ response = tokenizer.batch_decode(generated_ids)[0]
376
+ print(response)
377
+ ```
378
+
379
+ ##### LMDeploy 推理
380
+
381
+ LMDeploy 由 MMDeploy 和 MMRazor 团队联合开发,是涵盖了 LLM 任务的全套轻量化、部署和服务解决方案。
382
+
383
+ ```bash
384
+ pip install lmdeploy
385
+ ```
386
+
387
+ 你可以使用以下 python 代码进行本地批量推理:
388
+
389
+ ```python
390
+ import lmdeploy
391
+ model_dir = "internlm/internlm3-8b-instruct"
392
+ pipe = lmdeploy.pipeline(model_dir)
393
+ response = pipe(["Please tell me five scenic spots in Shanghai"])
394
+ print(response)
395
+
396
+ ```
397
+
398
+ 或者你可以使用以下命令启动兼容 OpenAI API 的服务:
399
+
400
+ ```bash
401
+ lmdeploy serve api_server internlm/internlm3-8b-instruct --model-name internlm3-8b-instruct --server-port 23333
402
+ ```
403
+
404
+ 然后你可以向服务端发起一个聊天请求:
405
+
406
+ ```bash
407
+ curl http://localhost:23333/v1/chat/completions \
408
+ -H "Content-Type: application/json" \
409
+ -d '{
410
+ "model": "internlm2_5-7b-chat",
411
+ "messages": [
412
+ {"role": "user", "content": "介绍一下深度学习。"}
413
+ ]
414
+ }'
415
+ ```
416
+
417
+ 更多信息请查看 [LMDeploy 文档](https://lmdeploy.readthedocs.io/en/latest/)
418
+
419
+
420
+
421
+ ##### vLLM 推理
422
+ TODO
423
+
424
+ #### 深度推理模式
425
+
426
+ ##### 解谜 demo
427
+
428
+ <div align="center">
429
+ <img src="https://github.com/InternLM/InternLM/blob/017ba7446d20ecc3b9ab8e7b66cc034500868ab4/assets/solve_puzzle.png?raw=true" width="400"/>
430
+
431
+
432
+
433
+
434
+
435
+ ##### 深度推理 system prompt
436
+
437
+ ```python
438
+ thinking_system_prompt = """You are an expert mathematician with extensive experience in mathematical competitions. You approach problems through systematic thinking and rigorous reasoning. When solving problems, follow these thought processes:
439
+ ## Deep Understanding
440
+ Take time to fully comprehend the problem before attempting a solution. Consider:
441
+ - What is the real question being asked?
442
+ - What are the given conditions and what do they tell us?
443
+ - Are there any special restrictions or assumptions?
444
+ - Which information is crucial and which is supplementary?
445
+ ## Multi-angle Analysis
446
+ Before solving, conduct thorough analysis:
447
+ - What mathematical concepts and properties are involved?
448
+ - Can you recall similar classic problems or solution methods?
449
+ - Would diagrams or tables help visualize the problem?
450
+ - Are there special cases that need separate consideration?
451
+ ## Systematic Thinking
452
+ Plan your solution path:
453
+ - Propose multiple possible approaches
454
+ - Analyze the feasibility and merits of each method
455
+ - Choose the most appropriate method and explain why
456
+ - Break complex problems into smaller, manageable steps
457
+ ## Rigorous Proof
458
+ During the solution process:
459
+ - Provide solid justification for each step
460
+ - Include detailed proofs for key conclusions
461
+ - Pay attention to logical connections
462
+ - Be vigilant about potential oversights
463
+ ## Repeated Verification
464
+ After completing your solution:
465
+ - Verify your results satisfy all conditions
466
+ - Check for overlooked special cases
467
+ - Consider if the solution can be optimized or simplified
468
+ - Review your reasoning process
469
+ Remember:
470
+ 1. Take time to think thoroughly rather than rushing to an answer
471
+ 2. Rigorously prove each key conclusion
472
+ 3. Keep an open mind and try different approaches
473
+ 4. Summarize valuable problem-solving methods
474
+ 5. Maintain healthy skepticism and verify multiple times
475
+ Your response should reflect deep mathematical understanding and precise logical thinking, making your solution path and reasoning clear to others.
476
+ When you're ready, present your complete solution with:
477
+ - Clear problem understanding
478
+ - Detailed solution process
479
+ - Key insights
480
+ - Thorough verification
481
+ Focus on clear, logical progression of ideas and thorough explanation of your mathematical reasoning. Provide answers in the same language as the user asking the question, repeat the final answer using a '\\boxed{}' without any units, you have [[8192]] tokens to complete the answer.
482
+ """
483
+ ```
484
+
485
+ ##### Transformers 推理
486
+
487
+
488
+ ```python
489
+ import torch
490
+ from transformers import AutoTokenizer, AutoModelForCausalLM
491
+
492
+ model_dir = "internlm/internlm3-8b-instruct"
493
+ tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
494
+ # Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
495
+ model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.float16)
496
+ # (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes.
497
+ # InternLM3 8B in 4bit will cost nearly 8GB GPU memory.
498
+ # pip install -U bitsandbytes
499
+ # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True)
500
+ # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True)
501
+ model = model.eval()
502
+
503
+ messages = [
504
+ {"role": "system", "content": thinking_system_prompt},
505
+ {"role": "user", "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."},
506
+ ]
507
+ tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
508
+
509
+ generated_ids = model.generate(tokenized_chat, max_new_tokens=8192)
510
+
511
+ generated_ids = [
512
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids)
513
+ ]
514
+ response = tokenizer.batch_decode(generated_ids)[0]
515
+ print(response)
516
+ ```
517
+ ##### LMDeploy 推理
518
+
519
+ LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the MMRazor and MMDeploy teams.
520
+
521
+ ```bash
522
+ pip install lmdeploy
523
+ ```
524
+
525
+ You can run batch inference locally with the following python code:
526
+
527
+ ```python
528
+ from lmdeploy import pipeline, GenerationConfig, ChatTemplateConfig
529
+ model_dir = "internlm/internlm3-8b-instruct"
530
+ chat_template_config = ChatTemplateConfig(model_name='internlm3')
531
+ pipe = pipeline(model_dir, chat_template_config=chat_template_config)
532
+
533
+ messages = [
534
+ {"role": "system", "content": thinking_system_prompt},
535
+ {"role": "user", "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."},
536
+ ]
537
+
538
+ response = pipe(messages, gen_config=GenerationConfig(max_new_tokens=2048))
539
+ print(response)
540
+ ```
541
+
542
+ ##### vLLM 推理
543
+
544
+ TODO
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+ ## 开源许可证
555
+
556
+ 本仓库的代码依照 Apache-2.0 协议开源。模型权重对学术研究完全开放,也可申请免费的商业使用授权([申请表](https://wj.qq.com/s2/12725412/f7c1/))。其他问题与合作请联系 <internlm@pjlab.org.cn>。
557
+
558
+ ## 引用
559
+
560
+ ```
561
+ @misc{cai2024internlm2,
562
+ title={InternLM2 Technical Report},
563
+ author={Zheng Cai and Maosong Cao and Haojiong Chen and Kai Chen and Keyu Chen and Xin Chen and Xun Chen and Zehui Chen and Zhi Chen and Pei Chu and Xiaoyi Dong and Haodong Duan and Qi Fan and Zhaoye Fei and Yang Gao and Jiaye Ge and Chenya Gu and Yuzhe Gu and Tao Gui and Aijia Guo and Qipeng Guo and Conghui He and Yingfan Hu and Ting Huang and Tao Jiang and Penglong Jiao and Zhenjiang Jin and Zhikai Lei and Jiaxing Li and Jingwen Li and Linyang Li and Shuaibin Li and Wei Li and Yining Li and Hongwei Liu and Jiangning Liu and Jiawei Hong and Kaiwen Liu and Kuikun Liu and Xiaoran Liu and Chengqi Lv and Haijun Lv and Kai Lv and Li Ma and Runyuan Ma and Zerun Ma and Wenchang Ning and Linke Ouyang and Jiantao Qiu and Yuan Qu and Fukai Shang and Yunfan Shao and Demin Song and Zifan Song and Zhihao Sui and Peng Sun and Yu Sun and Huanze Tang and Bin Wang and Guoteng Wang and Jiaqi Wang and Jiayu Wang and Rui Wang and Yudong Wang and Ziyi Wang and Xingjian Wei and Qizhen Weng and Fan Wu and Yingtong Xiong and Chao Xu and Ruiliang Xu and Hang Yan and Yirong Yan and Xiaogui Yang and Haochen Ye and Huaiyuan Ying and Jia Yu and Jing Yu and Yuhang Zang and Chuyu Zhang and Li Zhang and Pan Zhang and Peng Zhang and Ruijie Zhang and Shuo Zhang and Songyang Zhang and Wenjian Zhang and Wenwei Zhang and Xingcheng Zhang and Xinyue Zhang and Hui Zhao and Qian Zhao and Xiaomeng Zhao and Fengzhe Zhou and Zaida Zhou and Jingming Zhuo and Yicheng Zou and Xipeng Qiu and Yu Qiao and Dahua Lin},
564
+ year={2024},
565
+ eprint={2403.17297},
566
+ archivePrefix={arXiv},
567
+ primaryClass={cs.CL}
568
+ }
569
+ ```