2 Star 4 Fork 1

InternLM / InternLM

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

InternLM

👋 加入我们的 Discord微信社区

简介

InternLM 是一个开源的轻量级训练框架,旨在支持大模型训练而无需大量的依赖。通过单一的代码库,它支持在拥有数千个 GPU 的大型集群上进行预训练,并在单个 GPU 上进行微调,同时实现了卓越的性能优化。在1024个 GPU 上训练时,InternLM 可以实现近90%的加速效率。

基于InternLM训练框架,我们已经发布了两个开源的预训练模型:InternLM-7B 和 InternLM-20B。

更新

[20230920] InternLM-20B 已发布,包括基础版和对话版。
[20230822] InternLM-7B-Chat v1.1 已发布,增加了代码解释器和函数调用能力。您可以使用 Lagent 进行尝试。

Model Zoo

我们的模型在三个平台上发布:Transformers、ModelScope 和 OpenXLab。

Model Transformers ModelScope OpenXLab 发布日期
InternLM Chat 20B 🤗internlm/internlm-chat-20b Shanghai_AI_Laboratory/internlm-chat-20b Open in OpenXLab 2023-09-20
InternLM 20B 🤗internlm/internlm-20b Shanghai_AI_Laboratory/internlm-20b Open in OpenXLab 2023-09-20
InternLM Chat 7B v1.1 🤗internlm/internlm-chat-7b-v1.1 Shanghai_AI_Laboratory/internlm-chat-7b-v1_1 Open in OpenXLab 2023-08-22
InternLM 7B 🤗internlm/internlm-7b Shanghai_AI_Laboratory/internlm-7b Open in OpenXLab 2023-07-06
InternLM Chat 7B 🤗internlm/internlm-chat-7b Shanghai_AI_Laboratory/internlm-chat-7b Open in OpenXLab 2023-07-06
InternLM Chat 7B 8k 🤗internlm/internlm-chat-7b-8k Shanghai_AI_Laboratory/internlm-chat-7b-8k Open in OpenXLab 2023-07-06
InternLM-20B

简介

InternLM-20B 在超过 2.3T Tokens 包含高质量英文、中文和代码的数据上进行预训练,其中 Chat 版本还经过了 SFT 和 RLHF 训练,使其能够更好、更安全地满足用户的需求。

InternLM 20B 在模型结构上选择了深结构,InternLM-20B 的层数设定为60层,超过常规7B和13B模型所使用的32层或者40层。在参数受限的情况下,提高层数有利于提高模型的综合能力。此外,相较于InternLM-7B,InternLM-20B使用的预训练数据经过了更高质量的清洗,并补充了高知识密度和用于强化理解和推理能力的训练数据。因此,它在理解能力、推理能力、数学能力、编程能力等考验语言模型技术水平的方面都得到了显著提升。总体而言,InternLM-20B具有以下的特点:

  • 优异的综合性能
  • 很强的工具调用功能
  • 支持16k语境长度(通过推理时外推)
  • 更好的价值对齐

性能对比

在OpenCompass提出的5个能力维度上,InternLM-20B都取得很好的效果(粗体为13B-33B这个量级范围内,各项最佳成绩)

能力维度 Llama-13B Llama2-13B Baichuan2-13B InternLM-20B Llama-33B Llama-65B Llama2-70B
语言 42.5 47 47.5 55 44.6 47.1 51.6
知识 58.2 58.3 48.9 60.1 64 66 67.7
理解 45.5 50.9 58.1 67.3 50.6 54.2 60.8
推理 42.7 43.6 44.2 54.9 46.4 49.8 55
学科 37.3 45.2 51.8 62.5 47.4 49.7 57.3
总平均 43.8 47.3 49.4 59.2 48.9 51.9 57.4

下表在一些有重要影响力的典型数据集上比较了主流开源模型的表现

评测集 Llama-13B Llama2-13B Baichuan2-13B InternLM-20B Llama-33B Llama-65B Llama2-70B
学科 MMLU 47.73 54.99 59.55 62.05 58.73 63.71 69.75
C-Eval (val) 31.83 41.4 59.01 58.8 37.47 40.36 50.13
AGI-Eval 22.03 30.93 37.37 44.58 33.53 33.92 40.02
知识 BoolQ 78.75 82.42 67 87.46 84.43 86.61 87.74
TriviaQA 52.47 59.36 46.61 57.26 66.24 69.79 70.71
NaturalQuestions 20.17 24.85 16.32 25.15 30.89 33.41 34.16
理解 CMRC 9.26 31.59 29.85 68.78 14.17 34.73 43.74
CSL 55 58.75 63.12 65.62 57.5 59.38 60
RACE (middle) 53.41 63.02 68.94 86.35 64.55 72.35 81.55
RACE (high) 47.63 58.86 67.18 83.28 62.61 68.01 79.93
XSum 20.37 23.37 25.23 35.54 20.55 19.91 25.38
推理 WinoGrande 64.64 64.01 67.32 69.38 66.85 69.38 69.77
BBH 37.93 45.62 48.98 52.51 49.98 58.38 64.91
GSM8K 20.32 29.57 52.62 52.62 42.3 54.44 63.31
PIQA 79.71 79.76 78.07 80.25 81.34 82.15 82.54
编程 HumanEval 14.02 18.9 17.07 25.61 17.68 18.9 26.22
MBPP 20.6 26.8 30.8 35.6 28.4 33.6 39.6

总体而言,InternLM-20B 在综合能力上全面领先于13B量级的开源模型,同时在推理评测集上接近甚至超越Llama-65B的性能。

InternLM-7B

模型更新

[20230822] 通过使用更丰富的SFT类型数据,InternLM-7B-Chat v1.1模型支持代码解释和函数调用。模型结构与代码没有任何变化,因此可以使用与InternLM-7B-Chat完全一样的方式使用更强大的InternLM-7B-Chat v1.1。

简介

InternLM-7B 包含了一个拥有70亿参数的基础模型和一个为实际场景量身定制的对话模型。该模型具有以下特点:

  • 它利用数万亿的高质量令牌进行训练,建立了一个强大的知识库。
  • 它支持8k的上下文窗口长度,使得输入序列更长并增强了推理能力。
  • 它为用户提供了一个多功能的工具集,使用户能够灵活地构建自己的工作流程。

性能对比

我们使用开源评测工具 OpenCompass 从学科综合能力、语言能力、知识能力、推理能力、理解能力五大能力维度对InternLM开展全面评测,部分评测结果如下表所示,欢迎访问OpenCompass 榜单获取更多的评测结果。

数据集\模型 InternLM-Chat-7B InternLM-7B LLaMA-7B Baichuan-7B ChatGLM2-6B Alpaca-7B Vicuna-7B
C-Eval(Val) 53.2 53.4 24.2 42.7 50.9 28.9 31.2
MMLU 50.8 51.0 35.2* 41.5 46.0 39.7 47.3
AGIEval 42.5 37.6 20.8 24.6 39.0 24.1 26.4
CommonSenseQA 75.2 59.5 65.0 58.8 60.0 68.7 66.7
BUSTM 74.3 50.6 48.5 51.3 55.0 48.8 62.5
CLUEWSC 78.6 59.1 50.3 52.8 59.8 50.3 52.2
MATH 6.4 7.1 2.8 3.0 6.6 2.2 2.8
GSM8K 34.5 31.2 10.1 9.7 29.2 6.0 15.3
HumanEval 14.0 10.4 14.0 9.2 9.2 9.2 11.0
RACE(High) 76.3 57.4 46.9* 28.1 66.3 40.7 54.0
  • 以上评测结果基于 OpenCompass 20230706 获得(部分数据标注*代表数据来自原始论文),具体测试细节可参见 OpenCompass 中提供的配置文件。
  • 评测数据会因 OpenCompass 的版本迭代而存在数值差异,请以 OpenCompass 最新版的评测结果为主。

局限性: 尽管在训练过程中我们非常注重模型的安全性,尽力促使模型输出符合伦理和法律要求的文本,但受限于模型大小以及概率生成范式,模型可能会产生各种不符合预期的输出,例如回复内容包含偏见、歧视等有害内容,请勿传播这些内容。由于传播不良信息导致的任何后果,本项目不承担责任。

使用案例

通过 Transformers 加载

通过以下的代码从 Transformers 加载 InternLM 模型 (可修改模型名称替换不同的模型)

>>> from transformers import AutoTokenizer, AutoModelForCausalLM
>>> tokenizer = AutoTokenizer.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True)
>>> model = AutoModelForCausalLM.from_pretrained("internlm/internlm-chat-7b", 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)
当然可以以下是三个管理时间的建议
1. 制定计划制定一个详细的计划包括每天要完成的任务和活动这将有助于您更好地组织时间并确保您能够按时完成任务
2. 优先级将任务按照优先级排序先完成最重要的任务这将确保您能够在最短的时间内完成最重要的任务从而节省时间
3. 集中注意力避免分心集中注意力完成任务关闭社交媒体和电子邮件通知专注于任务这将帮助您更快地完成任务并减少错误的可能性

通过 ModelScope 加载

通过以下的代码从 ModelScope 加载 InternLM 模型 (可修改模型名称替换不同的模型)

from modelscope import snapshot_download, AutoTokenizer, AutoModelForCausalLM
import torch
model_dir = snapshot_download('Shanghai_AI_Laboratory/internlm-chat-7b-v1_1', revision='v1.0.0')
tokenizer = AutoTokenizer.from_pretrained(model_dir, device_map="auto", trust_remote_code=True,torch_dtype=torch.float16)
model = AutoModelForCausalLM.from_pretrained(model_dir,device_map="auto",  trust_remote_code=True,torch_dtype=torch.float16)
model = model.eval()
response, history = model.chat(tokenizer, "hello", history=[])
print(response)
response, history = model.chat(tokenizer, "please provide three suggestions about time management", history=history)
print(response)

通过前端网页对话

可以通过以下代码启动一个前端的界面来与 InternLM Chat 7B 模型进行交互

pip install streamlit==1.24.0
pip install transformers==4.30.2
streamlit run web_demo.py

效果如下

效果

基于InternLM高性能部署

我们使用 LMDeploy 完成 InternLM 的一键部署。

  1. 首先安装 LMDeploy:
python3 -m pip install lmdeploy
  1. 快速的部署命令如下:
python3 -m lmdeploy.serve.turbomind.deploy InternLM-7B /path/to/internlm-7b/model hf
  1. 在导出模型后,你可以直接通过如下命令启动服务一个服务并和部署后的模型对话
python3 -m lmdeploy.serve.client {server_ip_addresss}:33337

LMDeploy 支持了 InternLM 部署的完整流程,请参考 部署教程 了解 InternLM 的更多部署细节。

微调&训练

预训练与微调使用教程

请参考使用教程开始InternLM的安装、数据处理、预训练与微调。

转换为 Transformers 格式使用

通过 InternLM 进行训练的模型可以很轻松地转换为 HuggingFace Transformers 格式,方便与社区各种开源项目无缝对接。借助 tools/transformers/convert2hf.py 可以将训练保存的权重一键转换为 transformers 格式

python tools/transformers/convert2hf.py --src_folder origin_ckpt/ --tgt_folder hf_ckpt/ --tokenizer ./tools/V7_sft.model

转换之后可以通过以下的代码加载为 transformers

>>> from transformers import AutoTokenizer, AutoModel
>>> model = AutoModel.from_pretrained("hf_ckpt/", trust_remote_code=True).cuda()

训练系统

系统结构

请参考系统结构文档进一步了解。

训练性能

InternLM 深度整合了 Flash-Attention, Apex 等高性能模型算子,提高了训练效率。通过构建 Hybrid Zero 技术,实现计算和通信的高效重叠,大幅降低了训练过程中的跨节点通信流量。InternLM 支持 7B 模型从 8 卡扩展到 1024 卡,千卡规模下加速效率可高达 90%,训练吞吐超过 180TFLOPS,平均单卡每秒处理的 token 数量超过3600。下表为 InternLM 在不同配置下的扩展性测试数据:

GPU Number 8 16 32 64 128 256 512 1024
TGS 4078 3939 3919 3944 3928 3920 3835 3625
TFLOPS 193 191 188 188 187 185 186 184

TGS 代表平均每GPU每秒可以处理的 Token 数量。更多的性能测试数据可参考训练性能文档进一步了解。

贡献

我们感谢所有的贡献者为改进和提升 InternLM 所作出的努力。非常欢迎社区用户能参与进项目中来。请参考贡献指南来了解参与项目贡献的相关指引。

致谢

InternLM 代码库是一款由上海人工智能实验室和来自不同高校、企业的研发人员共同参与贡献的开源项目。我们感谢所有为项目提供新功能支持的贡献者,以及提供宝贵反馈的用户。 我们希望这个工具箱和基准测试可以为社区提供灵活高效的代码工具,供用户微调 InternLM 并开发自己的新模型,从而不断为开源社区提供贡献。特别鸣谢flash-attentionColossalAI 两项开源项目。

开源许可证

本仓库的代码依照 Apache-2.0 协议开源。模型权重对学术研究完全开放,也可申请免费的商业使用授权(申请表)。其他问题与合作请联系 internlm@pjlab.org.cn

引用

@misc{2023internlm,
    title={InternLM: A Multilingual Language Model with Progressively Enhanced Capabilities},
    author={InternLM Team},
    howpublished = {\url{https://github.com/InternLM/InternLM}},
    year={2023}
}
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ## Some of InternLM's code is derived from others projects, which is subject to the following copyright notice: Copyright 2021- HPC-AI Technology Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ---------------- LICENSE FOR Flash Attention ---------------- BSD 3-Clause License Copyright (c) 2022, the respective contributors, as shown by the AUTHORS file. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

InternLM 是一个开源的轻量级训练框架,旨在支持大模型训练而无需大量的依赖。通过单一的代码库,它支持在拥有数千个 GPU 的大型集群上进行预训练,并在单个 GPU 上进行微调,同时实现了卓越的性能优化。在1024个 GPU 上训练时,InternLM 可以实现近90%的加速效率。 展开 收起
Python 等 3 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/internlm/InternLM.git
git@gitee.com:internlm/InternLM.git
internlm
InternLM
InternLM
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891