Instructions to use openbmb/MiniCPM3-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM3-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openbmb/MiniCPM3-4B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("openbmb/MiniCPM3-4B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openbmb/MiniCPM3-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/MiniCPM3-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/MiniCPM3-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openbmb/MiniCPM3-4B
- SGLang
How to use openbmb/MiniCPM3-4B 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 "openbmb/MiniCPM3-4B" \ --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": "openbmb/MiniCPM3-4B", "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 "openbmb/MiniCPM3-4B" \ --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": "openbmb/MiniCPM3-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openbmb/MiniCPM3-4B with Docker Model Runner:
docker model run hf.co/openbmb/MiniCPM3-4B
FrankC0st1e commited on
Commit ·
43b498b
1
Parent(s): a4f2dcb
fix: empty system prompt
Browse files- tokenization_minicpm.py +3 -2
tokenization_minicpm.py
CHANGED
|
@@ -4,6 +4,7 @@ import keyword
|
|
| 4 |
import traceback
|
| 5 |
import uuid
|
| 6 |
from collections import deque
|
|
|
|
| 7 |
from logging import getLogger
|
| 8 |
from typing import Any, Dict, List, Optional, Union
|
| 9 |
|
|
@@ -324,6 +325,8 @@ def input_format(messages: List[Dict], tools: List[Dict], add_to_system=True):
|
|
| 324 |
the tools list you can use
|
| 325 |
For example:
|
| 326 |
"""
|
|
|
|
|
|
|
| 327 |
if tools is not None and len(tools) > 0:
|
| 328 |
header = (
|
| 329 |
"from enum import Enum\nfrom typing import List, Dict, Optional\nfrom pydantic import BaseModel, Field\n\n"
|
|
@@ -363,8 +366,6 @@ func2(params)
|
|
| 363 |
tools_string = ""
|
| 364 |
|
| 365 |
if add_to_system:
|
| 366 |
-
if len(messages) > 0 and messages[0]["role"] != "system":
|
| 367 |
-
messages.insert(0, {"role": "system", "content": ""})
|
| 368 |
return [message_format(msg, system_suffix=tools_string, user_prefix="") for msg in messages]
|
| 369 |
else:
|
| 370 |
return [message_format(msg, system_suffix="", user_prefix=tools_string) for msg in messages]
|
|
|
|
| 4 |
import traceback
|
| 5 |
import uuid
|
| 6 |
from collections import deque
|
| 7 |
+
from copy import deepcopy
|
| 8 |
from logging import getLogger
|
| 9 |
from typing import Any, Dict, List, Optional, Union
|
| 10 |
|
|
|
|
| 325 |
the tools list you can use
|
| 326 |
For example:
|
| 327 |
"""
|
| 328 |
+
messages = deepcopy(messages)
|
| 329 |
+
tools = deepcopy(tools)
|
| 330 |
if tools is not None and len(tools) > 0:
|
| 331 |
header = (
|
| 332 |
"from enum import Enum\nfrom typing import List, Dict, Optional\nfrom pydantic import BaseModel, Field\n\n"
|
|
|
|
| 366 |
tools_string = ""
|
| 367 |
|
| 368 |
if add_to_system:
|
|
|
|
|
|
|
| 369 |
return [message_format(msg, system_suffix=tools_string, user_prefix="") for msg in messages]
|
| 370 |
else:
|
| 371 |
return [message_format(msg, system_suffix="", user_prefix=tools_string) for msg in messages]
|