Instructions to use internlm/internlm2-math-base-20b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/internlm2-math-base-20b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="internlm/internlm2-math-base-20b", 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-math-base-20b", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use internlm/internlm2-math-base-20b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "internlm/internlm2-math-base-20b" # 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-math-base-20b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/internlm/internlm2-math-base-20b
- SGLang
How to use internlm/internlm2-math-base-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-math-base-20b" \ --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-math-base-20b", "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-math-base-20b" \ --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-math-base-20b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use internlm/internlm2-math-base-20b with Docker Model Runner:
docker model run hf.co/internlm/internlm2-math-base-20b
Update README.md
Browse files
README.md
CHANGED
|
@@ -87,18 +87,8 @@ We suggest using [LMDeploy](https://github.com/InternLM/LMDeploy)(>=0.2.1) for i
|
|
| 87 |
from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
|
| 88 |
|
| 89 |
backend_config = TurbomindEngineConfig(model_name='internlm2-chat-7b', tp=1, cache_max_entry_count=0.3)
|
| 90 |
-
chat_template = ChatTemplateConfig(model_name='internlm2-chat-7b',
|
| 91 |
-
|
| 92 |
-
eosys='',
|
| 93 |
-
meta_instruction='',
|
| 94 |
-
user='<|im_start|>user\n',
|
| 95 |
-
assistant='<|im_start|>assistant\n',
|
| 96 |
-
eoh='<|im_end|>\n',
|
| 97 |
-
eoa='<|im_end|>\n',
|
| 98 |
-
stop_words=['<|im_end|>', '<|action_end|>'])
|
| 99 |
-
pipe = pipeline(model_path='internlm/internlm2-math-7b',
|
| 100 |
-
chat_template_config=chat_template,
|
| 101 |
-
backend_config=backend_config)
|
| 102 |
|
| 103 |
problem = '1+1='
|
| 104 |
result = pipe([problem], request_output_len=1024, top_k=1)
|
|
@@ -112,7 +102,7 @@ tokenizer = AutoTokenizer.from_pretrained("internlm/internlm2-math-7b", trust_re
|
|
| 112 |
# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
|
| 113 |
model = AutoModelForCausalLM.from_pretrained("internlm/internlm2-math-7b", trust_remote_code=True, torch_dtype=torch.float16).cuda()
|
| 114 |
model = model.eval()
|
| 115 |
-
response, history = model.chat(tokenizer, "1+1=", history=[])
|
| 116 |
print(response)
|
| 117 |
```
|
| 118 |
|
|
|
|
| 87 |
from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
|
| 88 |
|
| 89 |
backend_config = TurbomindEngineConfig(model_name='internlm2-chat-7b', tp=1, cache_max_entry_count=0.3)
|
| 90 |
+
chat_template = ChatTemplateConfig(model_name='internlm2-chat-7b', system='', eosys='', meta_instruction='')
|
| 91 |
+
pipe = pipeline(model_path='internlm/internlm2-math-7b', chat_template_config=chat_template, backend_config=backend_config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
problem = '1+1='
|
| 94 |
result = pipe([problem], request_output_len=1024, top_k=1)
|
|
|
|
| 102 |
# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
|
| 103 |
model = AutoModelForCausalLM.from_pretrained("internlm/internlm2-math-7b", trust_remote_code=True, torch_dtype=torch.float16).cuda()
|
| 104 |
model = model.eval()
|
| 105 |
+
response, history = model.chat(tokenizer, "1+1=", history=[], meta_instruction="")
|
| 106 |
print(response)
|
| 107 |
```
|
| 108 |
|