Instructions to use internlm/internlm2-20b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/internlm2-20b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="internlm/internlm2-20b", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("internlm/internlm2-20b", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use internlm/internlm2-20b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "internlm/internlm2-20b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/internlm2-20b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/internlm/internlm2-20b
- SGLang
How to use internlm/internlm2-20b 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-20b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/internlm2-20b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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-20b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/internlm2-20b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use internlm/internlm2-20b with Docker Model Runner:
docker model run hf.co/internlm/internlm2-20b
x54-729 commited on
Commit ·
fa45716
1
Parent(s): d431f9e
small update
Browse files- modeling_internlm2.py +4 -4
modeling_internlm2.py
CHANGED
|
@@ -1632,10 +1632,10 @@ class InternLM2ForQuestionAnswering(InternLM2PreTrainedModel):
|
|
| 1632 |
self.post_init()
|
| 1633 |
|
| 1634 |
def get_input_embeddings(self):
|
| 1635 |
-
return self.transformer.
|
| 1636 |
|
| 1637 |
def set_input_embeddings(self, value):
|
| 1638 |
-
self.transformer.
|
| 1639 |
|
| 1640 |
@add_start_docstrings_to_model_forward(InternLM2_INPUTS_DOCSTRING)
|
| 1641 |
def forward(
|
|
@@ -1739,10 +1739,10 @@ class InternLM2ForTokenClassification(InternLM2PreTrainedModel):
|
|
| 1739 |
self.post_init()
|
| 1740 |
|
| 1741 |
def get_input_embeddings(self):
|
| 1742 |
-
return self.model.
|
| 1743 |
|
| 1744 |
def set_input_embeddings(self, value):
|
| 1745 |
-
self.model.
|
| 1746 |
|
| 1747 |
@add_start_docstrings_to_model_forward(InternLM2_INPUTS_DOCSTRING)
|
| 1748 |
def forward(
|
|
|
|
| 1632 |
self.post_init()
|
| 1633 |
|
| 1634 |
def get_input_embeddings(self):
|
| 1635 |
+
return self.transformer.tok_embeddings
|
| 1636 |
|
| 1637 |
def set_input_embeddings(self, value):
|
| 1638 |
+
self.transformer.tok_embeddings = value
|
| 1639 |
|
| 1640 |
@add_start_docstrings_to_model_forward(InternLM2_INPUTS_DOCSTRING)
|
| 1641 |
def forward(
|
|
|
|
| 1739 |
self.post_init()
|
| 1740 |
|
| 1741 |
def get_input_embeddings(self):
|
| 1742 |
+
return self.model.tok_embeddings
|
| 1743 |
|
| 1744 |
def set_input_embeddings(self, value):
|
| 1745 |
+
self.model.tok_embeddings = value
|
| 1746 |
|
| 1747 |
@add_start_docstrings_to_model_forward(InternLM2_INPUTS_DOCSTRING)
|
| 1748 |
def forward(
|