Instructions to use internlm/internlm2-chat-1_8b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/internlm2-chat-1_8b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="internlm/internlm2-chat-1_8b", 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", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use internlm/internlm2-chat-1_8b 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" # 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", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/internlm/internlm2-chat-1_8b
- SGLang
How to use internlm/internlm2-chat-1_8b 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" \ --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", "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" \ --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", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use internlm/internlm2-chat-1_8b with Docker Model Runner:
docker model run hf.co/internlm/internlm2-chat-1_8b
Update README.md
#1
by kmno4 - opened
README.md
CHANGED
|
@@ -142,9 +142,9 @@ InternLM2 模型具备以下的技术特点
|
|
| 142 |
```python
|
| 143 |
import torch
|
| 144 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 145 |
-
tokenizer = AutoTokenizer.from_pretrained("internlm/internlm2-chat-1_8b
|
| 146 |
# `torch_dtype=torch.float16` 可以令模型以 float16 精度加载,否则 transformers 会将模型加载为 float32,导致显存不足
|
| 147 |
-
model = AutoModelForCausalLM.from_pretrained("internlm/internlm2-chat-1_8b
|
| 148 |
model = model.eval()
|
| 149 |
response, history = model.chat(tokenizer, "你好", history=[])
|
| 150 |
print(response)
|
|
@@ -159,7 +159,7 @@ print(response)
|
|
| 159 |
import torch
|
| 160 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 161 |
|
| 162 |
-
model_path = "internlm/internlm2-chat-1_8b
|
| 163 |
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dype=torch.float16, trust_remote_code=True).cuda()
|
| 164 |
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 165 |
|
|
|
|
| 142 |
```python
|
| 143 |
import torch
|
| 144 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 145 |
+
tokenizer = AutoTokenizer.from_pretrained("internlm/internlm2-chat-1_8b", trust_remote_code=True)
|
| 146 |
# `torch_dtype=torch.float16` 可以令模型以 float16 精度加载,否则 transformers 会将模型加载为 float32,导致显存不足
|
| 147 |
+
model = AutoModelForCausalLM.from_pretrained("internlm/internlm2-chat-1_8b", torch_dtype=torch.float16, trust_remote_code=True).cuda()
|
| 148 |
model = model.eval()
|
| 149 |
response, history = model.chat(tokenizer, "你好", history=[])
|
| 150 |
print(response)
|
|
|
|
| 159 |
import torch
|
| 160 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 161 |
|
| 162 |
+
model_path = "internlm/internlm2-chat-1_8b"
|
| 163 |
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dype=torch.float16, trust_remote_code=True).cuda()
|
| 164 |
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 165 |
|