pipeline_tag: 文本生成
license: 其他
书生·浦语(InternLM)
👋 加入我们的Discord和微信群
模型介绍
InternLM2.5开源了200亿参数的基础模型和面向实际应用场景优化的对话模型。该模型具备以下特点:
- 卓越的推理能力:在数学推理任务上达到同规模模型的最优水平,超越Llama3和Gemma2-27B等模型。
- 强大的工具调用能力:支持从超过100个网页中收集信息进行分析推理,相关实现已发布于MindSearch。InternLM2.5在指令遵循、工具选择和结果反思等方面表现更优,具体示例可参见案例展示。
InternLM2.5-20B-Chat
性能评测
我们使用开源评估工具OpenCompass从学科能力、语言能力、知识掌握、推理能力和理解能力五个维度对InternLM进行全面评估。部分评测结果如下表所示,更多结果请访问OpenCompass榜单。
评测基准 |
InternLM2.5-20B-Chat |
Gemma2-27B-IT |
MMLU (5次测试) |
73.5 |
75.0 |
CMMLU (5次测试) |
79.7 |
63.3 |
BBH (3次链式思考) |
76.3 |
71.5 |
MATH (0次链式思考) |
64.7 |
50.1 |
GPQA (0次测试) |
33.3 |
29.3 |
注意事项: 尽管我们在训练过程中已尽力确保模型安全性,促使其生成符合伦理和法律要求的文本,但由于模型规模和概率生成机制的限制,仍可能产生包含偏见、歧视等有害内容的不当输出。请勿传播此类内容,因传播有害信息导致的后果,本项目不承担责任。
通过Transformers加载
使用以下代码加载InternLM2.5 20B Chat模型:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("internlm/internlm2_5-20b-chat", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("internlm/internlm2_5-20b-chat", torch_dtype=torch.float16, trust_remote_code=True).cuda()
model = model.eval()
response, history = model.chat(tokenizer, "你好", history=[])
print(response)
response, history = model.chat(tokenizer, "请提供三个时间管理建议", history=history)
print(response)
如需流式生成,可使用stream_chat
接口:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "internlm/internlm2_5-20b-chat"
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.float16, trust_remote_code=True).cuda()
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = model.eval()
length = 0
for response, history in model.stream_chat(tokenizer, "你好", history=[]):
print(response[length:], flush=True, end="")
length = len(response)
部署方案
LMDeploy
LMDeploy是MMRazor和MMDeploy团队联合开发的LLM压缩、部署和服务工具包。
pip install lmdeploy
本地批量推理示例:
import lmdeploy
pipe = lmdeploy.pipeline("internlm/internlm2_5-20b-chat")
response = pipe(["你好,请自我介绍", "上海是"])
print(response)
启动兼容OpenAI API的服务:
lmdeploy serve api_server internlm/internlm2_5-20b-chat --model-name internlm2_5-20b-chat --server-port 23333
发送聊天请求:
curl http://localhost:23333/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "internlm2_5-20b-chat",
"messages": [
{"role": "system", "content": "你是一个乐于助人的助手。"},
{"role": "user", "content": "请为我介绍深度学习。"}
]
}'
更多详情请参阅LMDeploy文档
vLLM
使用vLLM>=0.3.2
启动兼容OpenAI API的服务:
pip install vllm
python -m vllm.entrypoints.openai.api_server --model internlm/internlm2_5-20b-chat --served-model-name internlm2_5-20b-chat --trust-remote-code
发送聊天请求:
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "internlm2_5-20b-chat",
"messages": [
{"role": "system", "content": "你是一个乐于助人的助手。"},
{"role": "user", "content": "请为我介绍深度学习。"}
]
}'
更多详情请参阅vLLM文档
开源许可
代码遵循Apache-2.0协议开源,模型权重对学术研究完全开放并允许免费商用。商业授权请填写申请表(中文),其他问题请联系internlm@pjlab.org.cn。
引用文献
@misc{cai2024internlm2,
title={InternLM2技术报告},
author={蔡峥 and 曹茂松 and 陈豪炯 and 陈恺 and 陈科宇 and 陈昕 and 陈洵 and 陈泽辉 and 陈志 and 褚培 and 董晓艺 and 段昊东 and 范麒 and 费昭烨 and 高洋 and 葛佳烨 and 顾晨ya and 顾宇哲 and 桂韬 and 郭爱佳 and 郭启鹏 and 何从辉 and 胡英芳 and 黄婷 and 姜涛 and 焦鹏龙 and 金振疆 and 雷志凯 and 李佳兴 and 李静雯 and 李林阳 and 李帅斌 and 李威 and 李毅宁 and 刘宏伟 and 刘江宁 and 洪佳伟 and 刘凯文 and 刘奎坤 and 刘笑然 and 吕承琪 and 吕海军 and 吕凯 and 马丽 and 马润原 and 马泽润 and 宁文畅 and 欧阳林克 and 邱建涛 and 屈媛 and 尚复凯 and 邵云帆 and 宋德民 and 宋子凡 and 隋志浩 and 孙鹏 and 孙宇 and 唐焕泽 and 王斌 and 王国腾 and 王佳琪 and 王嘉宇 and 王睿 and 王宇栋 and 王子怡 and 魏星剑 and 翁启真 and 吴凡 and 熊应童 and 徐超 and 徐瑞亮 and 严航 and 严一荣 and 杨晓桂 and 叶皓宸 and 应怀原 and 余嘉 and 余婧 and 臧宇航 and 张楚瑜 and 张丽 and 张盼 and 张鹏 and 张瑞杰 and 张硕 and 张松阳 and 张文健 and 张雯玮 and 张星辰 and 张馨月 and 赵辉 and 赵倩 and 赵晓萌 and 周凤哲 and 周载道 and 卓靖明 and 邹宜成 and 邱锡鹏 and 乔宇 and 林达华},
year={2024},
eprint={2403.17297},
archivePrefix={arXiv},
primaryClass={cs.CL}
}