Instructions to use internlm/internlm-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/internlm-7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="internlm/internlm-7b", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("internlm/internlm-7b", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use internlm/internlm-7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "internlm/internlm-7b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/internlm-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/internlm/internlm-7b
- SGLang
How to use internlm/internlm-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/internlm-7b" \ --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/internlm-7b", "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/internlm-7b" \ --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/internlm-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use internlm/internlm-7b with Docker Model Runner:
docker model run hf.co/internlm/internlm-7b
Update modeling_internlm.py
Browse files- modeling_internlm.py +4 -0
modeling_internlm.py
CHANGED
|
@@ -784,6 +784,7 @@ class InternLMForCausalLM(InternLMPreTrainedModel):
|
|
| 784 |
do_sample: bool = True,
|
| 785 |
temperature: float = 0.8,
|
| 786 |
top_p: float = 0.8,
|
|
|
|
| 787 |
**kwargs):
|
| 788 |
inputs = self.build_inputs(tokenizer, query, history)
|
| 789 |
inputs = {k: v.to(self.device) for k, v in inputs.items() if torch.is_tensor(v)}
|
|
@@ -793,6 +794,7 @@ class InternLMForCausalLM(InternLMPreTrainedModel):
|
|
| 793 |
do_sample=do_sample,
|
| 794 |
temperature=temperature,
|
| 795 |
top_p=top_p,
|
|
|
|
| 796 |
**kwargs)
|
| 797 |
outputs = outputs[0].cpu().tolist()[len(inputs["input_ids"][0]):]
|
| 798 |
response = tokenizer.decode(outputs, skip_special_tokens=True)
|
|
@@ -809,6 +811,7 @@ class InternLMForCausalLM(InternLMPreTrainedModel):
|
|
| 809 |
do_sample: bool = True,
|
| 810 |
temperature: float = 0.8,
|
| 811 |
top_p: float = 0.8,
|
|
|
|
| 812 |
**kwargs):
|
| 813 |
class ChatStreamer(BaseStreamer):
|
| 814 |
def __init__(self, tokenizer) -> None:
|
|
@@ -836,6 +839,7 @@ class InternLMForCausalLM(InternLMPreTrainedModel):
|
|
| 836 |
do_sample=do_sample,
|
| 837 |
temperature=temperature,
|
| 838 |
top_p=top_p,
|
|
|
|
| 839 |
**kwargs
|
| 840 |
)
|
| 841 |
|
|
|
|
| 784 |
do_sample: bool = True,
|
| 785 |
temperature: float = 0.8,
|
| 786 |
top_p: float = 0.8,
|
| 787 |
+
eos_token_id = (2, 103028),
|
| 788 |
**kwargs):
|
| 789 |
inputs = self.build_inputs(tokenizer, query, history)
|
| 790 |
inputs = {k: v.to(self.device) for k, v in inputs.items() if torch.is_tensor(v)}
|
|
|
|
| 794 |
do_sample=do_sample,
|
| 795 |
temperature=temperature,
|
| 796 |
top_p=top_p,
|
| 797 |
+
eos_token_id=list(eos_token_id),
|
| 798 |
**kwargs)
|
| 799 |
outputs = outputs[0].cpu().tolist()[len(inputs["input_ids"][0]):]
|
| 800 |
response = tokenizer.decode(outputs, skip_special_tokens=True)
|
|
|
|
| 811 |
do_sample: bool = True,
|
| 812 |
temperature: float = 0.8,
|
| 813 |
top_p: float = 0.8,
|
| 814 |
+
eos_token_id = (2, 103028),
|
| 815 |
**kwargs):
|
| 816 |
class ChatStreamer(BaseStreamer):
|
| 817 |
def __init__(self, tokenizer) -> None:
|
|
|
|
| 839 |
do_sample=do_sample,
|
| 840 |
temperature=temperature,
|
| 841 |
top_p=top_p,
|
| 842 |
+
eos_token_id=eos_token_id,
|
| 843 |
**kwargs
|
| 844 |
)
|
| 845 |
|