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, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- 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 ·
6edb557
1
Parent(s): 9d2060a
fix flash attention import
Browse files- configuration_internlm2.py +9 -2
- modeling_internlm2.py +4 -2
configuration_internlm2.py
CHANGED
|
@@ -169,5 +169,12 @@ class InternLM2Config(PretrainedConfig):
|
|
| 169 |
raise ValueError(
|
| 170 |
f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
|
| 171 |
)
|
| 172 |
-
if
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
raise ValueError(
|
| 170 |
f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
|
| 171 |
)
|
| 172 |
+
if (
|
| 173 |
+
rope_scaling_factor is None
|
| 174 |
+
or not isinstance(rope_scaling_factor, (float, int))
|
| 175 |
+
or rope_scaling_factor < 1.0
|
| 176 |
+
):
|
| 177 |
+
raise ValueError(
|
| 178 |
+
f"`rope_scaling`'s factor field must be a number >= 1, got {rope_scaling_factor} "
|
| 179 |
+
f"of type {type(rope_scaling_factor)}"
|
| 180 |
+
)
|
modeling_internlm2.py
CHANGED
|
@@ -40,7 +40,6 @@ from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS
|
|
| 40 |
from transformers.utils import (
|
| 41 |
add_start_docstrings,
|
| 42 |
add_start_docstrings_to_model_forward,
|
| 43 |
-
is_flash_attn_2_available,
|
| 44 |
is_flash_attn_greater_or_equal_2_10,
|
| 45 |
logging,
|
| 46 |
replace_return_docstrings,
|
|
@@ -53,9 +52,12 @@ except Exception:
|
|
| 53 |
|
| 54 |
from .configuration_internlm2 import InternLM2Config
|
| 55 |
|
| 56 |
-
|
|
|
|
| 57 |
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
| 58 |
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input
|
|
|
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
logger = logging.get_logger(__name__)
|
|
|
|
| 40 |
from transformers.utils import (
|
| 41 |
add_start_docstrings,
|
| 42 |
add_start_docstrings_to_model_forward,
|
|
|
|
| 43 |
is_flash_attn_greater_or_equal_2_10,
|
| 44 |
logging,
|
| 45 |
replace_return_docstrings,
|
|
|
|
| 52 |
|
| 53 |
from .configuration_internlm2 import InternLM2Config
|
| 54 |
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
| 58 |
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input
|
| 59 |
+
except:
|
| 60 |
+
pass
|
| 61 |
|
| 62 |
|
| 63 |
logger = logging.get_logger(__name__)
|