Instructions to use internlm/internlm2-chat-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/internlm2-chat-7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="internlm/internlm2-chat-7b", 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-7b", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use internlm/internlm2-chat-7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "internlm/internlm2-chat-7b" # 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-7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/internlm/internlm2-chat-7b
- SGLang
How to use internlm/internlm2-chat-7b 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-7b" \ --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-7b", "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-7b" \ --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-7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use internlm/internlm2-chat-7b with Docker Model Runner:
docker model run hf.co/internlm/internlm2-chat-7b
x54-729 commited on
Commit ·
c2ba644
1
Parent(s): e7c2e16
replace get_max_length
Browse files- modeling_internlm2.py +3 -3
modeling_internlm2.py
CHANGED
|
@@ -1081,7 +1081,7 @@ class InternLM2Model(InternLM2PreTrainedModel):
|
|
| 1081 |
min_dtype = torch.finfo(dtype).min
|
| 1082 |
sequence_length = input_tensor.shape[1]
|
| 1083 |
if using_static_cache:
|
| 1084 |
-
target_length = past_key_values.
|
| 1085 |
else:
|
| 1086 |
target_length = (
|
| 1087 |
attention_mask.shape[-1]
|
|
@@ -1274,8 +1274,8 @@ class InternLM2ForCausalLM(InternLM2PreTrainedModel):
|
|
| 1274 |
if isinstance(past_key_values, Cache):
|
| 1275 |
past_length = cache_position[0] if cache_position is not None else past_key_values.get_seq_length()
|
| 1276 |
max_cache_length = (
|
| 1277 |
-
torch.tensor(past_key_values.
|
| 1278 |
-
if past_key_values.
|
| 1279 |
else None
|
| 1280 |
)
|
| 1281 |
cache_length = past_length if max_cache_length is None else torch.min(max_cache_length, past_length)
|
|
|
|
| 1081 |
min_dtype = torch.finfo(dtype).min
|
| 1082 |
sequence_length = input_tensor.shape[1]
|
| 1083 |
if using_static_cache:
|
| 1084 |
+
target_length = past_key_values.get_max_cache_shape()
|
| 1085 |
else:
|
| 1086 |
target_length = (
|
| 1087 |
attention_mask.shape[-1]
|
|
|
|
| 1274 |
if isinstance(past_key_values, Cache):
|
| 1275 |
past_length = cache_position[0] if cache_position is not None else past_key_values.get_seq_length()
|
| 1276 |
max_cache_length = (
|
| 1277 |
+
torch.tensor(past_key_values.get_max_cache_shape(), device=input_ids.device)
|
| 1278 |
+
if past_key_values.get_max_cache_shape() is not None
|
| 1279 |
else None
|
| 1280 |
)
|
| 1281 |
cache_length = past_length if max_cache_length is None else torch.min(max_cache_length, past_length)
|