pipeline_tag: 文本生成
license: 其他
书生·浦语
👋 加入我们的Discord和微信群
简介
书生·浦语2(InternLM2)开源了面向实用场景的70亿参数基础模型与对话模型。该模型具有以下特征:
-
20万字上下文窗口:在20万字长文本中近乎完美地实现"大海捞针",在LongBench和L-Eval等长文本任务中表现领先。可通过LMDeploy体验20万字上下文推理。
-
卓越综合性能:在推理、数学、代码、对话体验、指令遵循和创意写作等方面显著提升,综合性能达到同规模开源模型的领先水平。部分评测中,InternLM2-Chat-20B可媲美甚至超越ChatGPT(GPT-3.5)。
-
代码解释器与数据分析:配合代码解释器时,InternLM2-Chat-20B在GSM8K和MATH上的表现与GPT-4相当,同时具备数据分析能力。
-
更强的工具调用:基于更优的指令理解、工具选择和结果反思能力,支持构建复杂智能体和多步骤工具调用。详见案例库。
InternLM2-Chat-7B
性能评测
使用OpenCompass开源评测工具从学科能力、语言能力、知识能力、推理能力和理解能力五个维度进行全面评估。部分结果如下,更多结果请访问OpenCompass榜单。
数据集\模型 |
InternLM2-7B |
InternLM2-Chat-7B |
InternLM2-20B |
InternLM2-Chat-20B |
ChatGPT |
GPT-4 |
MMLU |
65.8 |
63.7 |
67.7 |
66.5 |
69.1 |
83.0 |
AGIEval |
49.9 |
47.2 |
53.0 |
50.3 |
39.9 |
55.1 |
BBH |
65.0 |
61.2 |
72.1 |
68.3 |
70.1 |
86.7 |
GSM8K |
70.8 |
70.7 |
76.1 |
79.6 |
78.2 |
91.4 |
MATH |
20.2 |
23.0 |
25.5 |
31.9 |
28.0 |
45.8 |
HumanEval |
43.3 |
59.8 |
48.8 |
67.1 |
73.2 |
74.4 |
MBPP(净版) |
51.8 |
51.4 |
63.0 |
65.8 |
78.9 |
79.0 |
局限性声明:虽然我们致力于提升模型安全性,但由于模型规模与概率生成特性,仍可能产生不符合预期的输出(如偏见/有害内容)。请勿传播此类内容,相关责任由传播者承担。
Transformers调用
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("internlm/internlm2-chat-7b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("internlm/internlm2-chat-7b", torch_dtype=torch.float16, trust_remote_code=True).cuda()
model = model.eval()
response, history = model.chat(tokenizer, "你好", history=[])
print(response)
流式生成示例:
for response, history in model.stream_chat(tokenizer, "你好", history=[]):
print(response[length:], flush=True, end="")
length = len(response)
部署方案
LMDeploy
pip install lmdeploy
python -m lmdeploy.serve.api_server internlm/internlm2-chat-7b --server-port 23333
请求示例:
curl http://localhost:23333/v1/chat/completions -H "Content-Type: application/json" -d '{"model":"internlm2-chat-7b","messages":[{"role":"user","content":"解释深度学习"}]}'
vLLM
pip install vllm>=0.3.2
python -m vllm.entrypoints.openai.api_server --model internlm/internlm2-chat-7b --trust-remote-code
开源许可
代码基于Apache-2.0协议,模型权重学术研究完全开放,商业使用需填写申请表。合作咨询请联系internlm@pjlab.org.cn。
引用文献
@misc{cai2024internlm2,
title={InternLM2技术报告},
author={蔡峥等},
year={2024},
eprint={2403.17297},
archivePrefix={arXiv},
primaryClass={cs.CL}
}