Instructions to use internlm/internlm2-chat-1_8b-sft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/internlm2-chat-1_8b-sft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="internlm/internlm2-chat-1_8b-sft", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("internlm/internlm2-chat-1_8b-sft", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use internlm/internlm2-chat-1_8b-sft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "internlm/internlm2-chat-1_8b-sft" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/internlm2-chat-1_8b-sft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/internlm/internlm2-chat-1_8b-sft
- SGLang
How to use internlm/internlm2-chat-1_8b-sft with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "internlm/internlm2-chat-1_8b-sft" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/internlm2-chat-1_8b-sft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "internlm/internlm2-chat-1_8b-sft" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/internlm2-chat-1_8b-sft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use internlm/internlm2-chat-1_8b-sft with Docker Model Runner:
docker model run hf.co/internlm/internlm2-chat-1_8b-sft
InternLM
Introduction
InternLM2-1.8B is the 1.8 billion parameter version of the second generation InternLM series. In order to facilitate user use and research, InternLM2-1.8B has three versions of open-source models. They are:
- InternLM2-1.8B: Foundation models with high quality and high adaptation flexibility, which serve as a good starting point for downstream deep adaptations.
- InternLM2-Chat-1.8B-SFT: Chat model after supervised fine-tuning (SFT) on InternLM2-1.8B.
- InternLM2-Chat-1.8B: Further aligned on top of InternLM2-Chat-1.8B-SFT through online RLHF. InternLM2-Chat-1.8B exhibits better instruction following, chat experience, and function calling, which is recommended for downstream applications.
The InternLM2 has the following technical features:
- Effective support for ultra-long contexts of up to 200,000 characters: The model nearly perfectly achieves "finding a needle in a haystack" in long inputs of 200,000 characters. It also leads among open-source models in performance on long-text tasks such as LongBench and L-Eval.
- Comprehensive performance enhancement: Compared to the previous generation model, it shows significant improvements in various capabilities, including reasoning, mathematics, and coding.
InternLM2-1.8B
Performance Evaluation
We have evaluated InternLM2 on several important benchmarks using the open-source evaluation tool OpenCompass. Some of the evaluation results are shown in the table below. You are welcome to visit the OpenCompass Leaderboard for more evaluation results.
| Dataset\Models | InternLM2-1.8B | InternLM2-Chat-1.8B-SFT | InternLM2-7B | InternLM2-Chat-7B |
|---|---|---|---|---|
| MMLU | 46.9 | 47.1 | 65.8 | 63.7 |
| AGIEval | 33.4 | 38.8 | 49.9 | 47.2 |
| BBH | 37.5 | 35.2 | 65.0 | 61.2 |
| GSM8K | 31.2 | 39.7 | 70.8 | 70.7 |
| MATH | 5.6 | 11.8 | 20.2 | 23.0 |
| HumanEval | 25.0 | 32.9 | 43.3 | 59.8 |
| MBPP(Sanitized) | 22.2 | 23.2 | 51.8 | 51.4 |
- The evaluation results were obtained from OpenCompass , and evaluation configuration can be found in the configuration files provided by OpenCompass.
- The evaluation data may have numerical differences due to the version iteration of OpenCompass, so please refer to the latest evaluation results of OpenCompass.
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.
Import from Transformers
To load the InternLM2 1.8B Chat SFT model using Transformers, use the following code:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("internlm/internlm2-chat-1_8b-sft", trust_remote_code=True)
# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and cause OOM Error.
model = AutoModelForCausalLM.from_pretrained("internlm/internlm2-chat-1_8b-sft", torch_dtype=torch.float16, trust_remote_code=True).cuda()
model = model.eval()
response, history = model.chat(tokenizer, "hello", history=[])
print(response)
# Hello! How can I help you today?
response, history = model.chat(tokenizer, "please provide three suggestions about time management", history=history)
print(response)
The responses can be streamed using stream_chat:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "internlm/internlm2-chat-1_8b-sft"
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, "Hello", history=[]):
print(response[length:], flush=True, end="")
length = len(response)
Deployment
LMDeploy
LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the MMRazor and MMDeploy teams.
pip install lmdeploy
You can run batch inference locally with the following python code:
import lmdeploy
pipe = lmdeploy.pipeline("internlm/internlm2-chat-1_8b-sft")
response = pipe(["Hi, pls intro yourself", "Shanghai is"])
print(response)
Or you can launch an OpenAI compatible server with the following command:
lmdeploy serve api_server internlm/internlm2-chat-1_8b-sft --model-name internlm2-chat-1_8b-sft --server-port 23333
Then you can send a chat request to the server:
curl http://localhost:23333/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "internlm2-chat-1_8b-sft",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Introduce deep learning to me."}
]
}'
Find more details in the LMDeploy documentation
vLLM
Launch OpenAI compatible server with vLLM>=0.3.2:
pip install vllm
python -m vllm.entrypoints.openai.api_server --model internlm/internlm2-chat-1_8b-sft --served-model-name internlm2-chat-1_8b-sft --trust-remote-code
Then you can send a chat request to the server:
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "internlm2-chat-1_8b-sft",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Introduce deep learning to me."}
]
}'
Find more details in the vLLM documentation
Open Source License
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)/็ณ่ฏท่กจ๏ผไธญๆ๏ผ. For other questions or collaborations, please contact internlm@pjlab.org.cn.
Citation
@misc{cai2024internlm2,
title={InternLM2 Technical Report},
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},
year={2024},
eprint={2403.17297},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
็ฎไป
ไนฆ็ยทๆตฆ่ฏญ-1.8B (InternLM2-1.8B) ๆฏ็ฌฌไบไปฃๆตฆ่ฏญๆจกๅ็ณปๅ็18ไบฟๅๆฐ็ๆฌใไธบไบๆนไพฟ็จๆทไฝฟ็จๅ็ ็ฉถ๏ผไนฆ็ยทๆตฆ่ฏญ-1.8B (InternLM2-1.8B) ๅ ฑๆไธไธช็ๆฌ็ๅผๆบๆจกๅ๏ผไปไปฌๅๅซๆฏ๏ผ
- InternLM2-1.8B: ๅ ทๆ้ซ่ดจ้ๅ้ซ้ๅบ็ตๆดปๆง็ๅบ็กๆจกๅ๏ผไธบไธๆธธๆทฑๅบฆ้ๅบๆไพไบ่ฏๅฅฝ็่ตท็นใ
- InternLM2-Chat-1.8B-SFT๏ผๅจ InternLM2-1.8B ไธ่ฟ่ก็็ฃๅพฎ่ฐ (SFT) ๅๅพๅฐ็ๅฏน่ฏๆจกๅใ
- InternLM2-chat-1.8B๏ผ้่ฟๅจ็บฟ RLHF ๅจ InternLM2-Chat-1.8B-SFT ไนไธ่ฟไธๆญฅๅฏน้ฝใ InternLM2-Chat-1.8B ่กจ็ฐๅบๆดๅฅฝ็ๆไปค่ท้ใ่ๅคฉไฝ้ชๅๅฝๆฐ่ฐ็จ๏ผๆจ่ไธๆธธๅบ็จ็จๅบไฝฟ็จใ
InternLM2 ๆจกๅๅ ทๅคไปฅไธ็ๆๆฏ็น็น
- ๆๆๆฏๆ20ไธๅญ่ถ ้ฟไธไธๆ๏ผๆจกๅๅจ20ไธๅญ้ฟ่พๅ ฅไธญๅ ไนๅฎ็พๅฐๅฎ็ฐ้ฟๆโๅคงๆตทๆ้โ๏ผ่ไธๅจ LongBench ๅ L-Eval ็ญ้ฟๆไปปๅกไธญ็่กจ็ฐไน่พพๅฐๅผๆบๆจกๅไธญ็้ขๅ ๆฐดๅนณใ
- ็ปผๅๆง่ฝๅ จ้ขๆๅ๏ผๅ่ฝๅ็ปดๅบฆ็ธๆฏไธไธไปฃๆจกๅๅ จ้ข่ฟๆญฅ๏ผๅจๆจ็ใๆฐๅญฆใไปฃ็ ็ญๆน้ข็่ฝๅๆๅๆพ่ใ
InternLM2-1.8B
ๆง่ฝ่ฏๆต
ๆไปฌไฝฟ็จๅผๆบ่ฏๆตๅทฅๅ ท OpenCompass ๅฏน InternLM2 ๅจๅ ไธช้่ฆ็่ฏๆต้่ฟ่กไบ่ฏๆต ๏ผ้จๅ่ฏๆต็ปๆๅฆไธ่กจๆ็คบ๏ผๆฌข่ฟ่ฎฟ้ฎ OpenCompass ๆฆๅ ่ทๅๆดๅค็่ฏๆต็ปๆใ
| ่ฏๆต้ | InternLM2-1.8B | InternLM2-Chat-1.8B-SFT | InternLM2-7B | InternLM2-Chat-7B |
|---|---|---|---|---|
| MMLU | 46.9 | 47.1 | 65.8 | 63.7 |
| AGIEval | 33.4 | 38.8 | 49.9 | 47.2 |
| BBH | 37.5 | 35.2 | 65.0 | 61.2 |
| GSM8K | 31.2 | 39.7 | 70.8 | 70.7 |
| MATH | 5.6 | 11.8 | 20.2 | 23.0 |
| HumanEval | 25.0 | 32.9 | 43.3 | 59.8 |
| MBPP(Sanitized) | 22.2 | 23.2 | 51.8 | 51.4 |
- ไปฅไธ่ฏๆต็ปๆๅบไบ OpenCompass ่ทๅพ๏ผ้จๅๆฐๆฎๆ ๆณจ
*ไปฃ่กจๆฐๆฎๆฅ่ชๅๅง่ฎบๆ๏ผ๏ผๅ ทไฝๆต่ฏ็ป่ๅฏๅ่ง OpenCompass ไธญๆไพ็้ ็ฝฎๆไปถใ - ่ฏๆตๆฐๆฎไผๅ OpenCompass ็็ๆฌ่ฟญไปฃ่ๅญๅจๆฐๅผๅทฎๅผ๏ผ่ฏทไปฅ OpenCompass ๆๆฐ็็่ฏๆต็ปๆไธบไธปใ
ๅฑ้ๆง๏ผ ๅฐฝ็ฎกๅจ่ฎญ็ป่ฟ็จไธญๆไปฌ้ๅธธๆณจ้ๆจกๅ็ๅฎๅ จๆง๏ผๅฐฝๅไฟไฝฟๆจกๅ่พๅบ็ฌฆๅไผฆ็ๅๆณๅพ่ฆๆฑ็ๆๆฌ๏ผไฝๅ้ไบๆจกๅๅคงๅฐไปฅๅๆฆ็็ๆ่ๅผ๏ผๆจกๅๅฏ่ฝไผไบง็ๅ็งไธ็ฌฆๅ้ขๆ็่พๅบ๏ผไพๅฆๅๅคๅ ๅฎนๅ ๅซๅ่งใๆญง่ง็ญๆๅฎณๅ ๅฎน๏ผ่ฏทๅฟไผ ๆญ่ฟไบๅ ๅฎนใ็ฑไบไผ ๆญไธ่ฏไฟกๆฏๅฏผ่ด็ไปปไฝๅๆ๏ผๆฌ้กน็ฎไธๆฟๆ ่ดฃไปปใ
้่ฟ Transformers ๅ ่ฝฝ
้่ฟไปฅไธ็ไปฃ็ ๅ ่ฝฝ InternLM2 1.8B Chat SFT ๆจกๅ
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("internlm/internlm2-chat-1_8b-sft", trust_remote_code=True)
# `torch_dtype=torch.float16` ๅฏไปฅไปคๆจกๅไปฅ float16 ็ฒพๅบฆๅ ่ฝฝ๏ผๅฆๅ transformers ไผๅฐๆจกๅๅ ่ฝฝไธบ float32๏ผๅฏผ่ดๆพๅญไธ่ถณ
model = AutoModelForCausalLM.from_pretrained("internlm/internlm2-chat-1_8b-sft", 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-chat-1_8b-sft"
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dype=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 ็ฑ MMDeploy ๅ MMRazor ๅข้่ๅๅผๅ๏ผๆฏๆถต็ไบ LLM ไปปๅก็ๅ จๅฅ่ฝป้ๅใ้จ็ฝฒๅๆๅก่งฃๅณๆนๆกใ
pip install lmdeploy
ไฝ ๅฏไปฅไฝฟ็จไปฅไธ python ไปฃ็ ่ฟ่กๆฌๅฐๆน้ๆจ็:
import lmdeploy
pipe = lmdeploy.pipeline("internlm/internlm2-chat-1_8b-sft")
response = pipe(["Hi, pls intro yourself", "Shanghai is"])
print(response)
ๆ่ ไฝ ๅฏไปฅไฝฟ็จไปฅไธๅฝไปคๅฏๅจๅ ผๅฎน OpenAI API ็ๆๅก:
lmdeploy serve api_server internlm/internlm2-chat-1_8b-sft --server-port 23333
็ถๅไฝ ๅฏไปฅๅๆๅก็ซฏๅ่ตทไธไธช่ๅคฉ่ฏทๆฑ:
curl http://localhost:23333/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "internlm2-chat-1_8b-sft",
"messages": [
{"role": "system", "content": "ไฝ ๆฏไธชๅๅ็AIๅฉๆใ"},
{"role": "user", "content": "ไป็ปไธไธๆทฑๅบฆๅญฆไน ใ"}
]
}'
ๆดๅคไฟกๆฏ่ฏทๆฅ็ LMDeploy ๆๆกฃ
vLLM
ไฝฟ็จvLLM>=0.3.2ๅฏๅจๅ
ผๅฎน OpenAI API ็ๆๅก:
pip install vllm
python -m vllm.entrypoints.openai.api_server --model internlm/internlm2-chat-1_8b-sft --trust-remote-code
็ถๅไฝ ๅฏไปฅๅๆๅก็ซฏๅ่ตทไธไธช่ๅคฉ่ฏทๆฑ:
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "internlm2-chat-1_8b-sft",
"messages": [
{"role": "system", "content": "ไฝ ๆฏไธชๅๅ็AIๅฉๆใ"},
{"role": "user", "content": "ไป็ปไธไธๆทฑๅบฆๅญฆไน ใ"}
]
}'
ๆดๅคไฟกๆฏ่ฏทๆฅ็ vLLM ๆๆกฃ
ๅผๆบ่ฎธๅฏ่ฏ
ๆฌไปๅบ็ไปฃ็ ไพ็ ง Apache-2.0 ๅ่ฎฎๅผๆบใๆจกๅๆ้ๅฏนๅญฆๆฏ็ ็ฉถๅฎๅ จๅผๆพ๏ผไนๅฏ็ณ่ฏทๅ ่ดน็ๅไธไฝฟ็จๆๆ๏ผ็ณ่ฏท่กจ๏ผใๅ ถไป้ฎ้ขไธๅไฝ่ฏท่็ณป internlm@pjlab.org.cnใ
ๅผ็จ
@misc{cai2024internlm2,
title={InternLM2 Technical Report},
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},
year={2024},
eprint={2403.17297},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
- Downloads last month
- 127