Text Generation
Transformers
Safetensors
English
Chinese
llama
minicpm
minicpm5
long-context
tool-calling
on-device
edge-ai
conversational
text-generation-inference
Instructions to use openbmb/MiniCPM5-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM5-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openbmb/MiniCPM5-2B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openbmb/MiniCPM5-2B") model = AutoModelForCausalLM.from_pretrained("openbmb/MiniCPM5-2B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openbmb/MiniCPM5-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/MiniCPM5-2B" # 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/MiniCPM5-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openbmb/MiniCPM5-2B
- SGLang
How to use openbmb/MiniCPM5-2B 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/MiniCPM5-2B" \ --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/MiniCPM5-2B", "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/MiniCPM5-2B" \ --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/MiniCPM5-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openbmb/MiniCPM5-2B with Docker Model Runner:
docker model run hf.co/openbmb/MiniCPM5-2B
Enhance README with sampling parameter recommendations and Llama.cpp usage examples
Browse files- README-cn.md +26 -0
- README.md +27 -1
README-cn.md
CHANGED
|
@@ -268,6 +268,13 @@ MiniCPM5-2B 的训练过程是 **[UltraData 分级数据管理体系](https://ar
|
|
| 268 |
|
| 269 |
## 快速上手
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
### vLLM
|
| 272 |
|
| 273 |
```bash
|
|
@@ -315,6 +322,25 @@ python -m sglang.launch_server \
|
|
| 315 |
--speculative-dspark-block-size 7 \
|
| 316 |
--port 30000
|
| 317 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
|
| 319 |
### Transformers
|
| 320 |
|
|
|
|
| 268 |
|
| 269 |
## 快速上手
|
| 270 |
|
| 271 |
+
> [!Tip]
|
| 272 |
+
> 我们建议在生成时使用以下采样参数组合:`temperature=1.0, top_p=0.95, min_p=0.0`。
|
| 273 |
+
>
|
| 274 |
+
> 如果遇到重复输出,请尝试:`temperature=1.0, top_p=0.95, min_p=0.0, repetition_penalty=1.05`。
|
| 275 |
+
>
|
| 276 |
+
> 请注意,不同推理框架对采样参数的支持程度有所差异。
|
| 277 |
+
|
| 278 |
### vLLM
|
| 279 |
|
| 280 |
```bash
|
|
|
|
| 322 |
--speculative-dspark-block-size 7 \
|
| 323 |
--port 30000
|
| 324 |
```
|
| 325 |
+
### Llama.cpp
|
| 326 |
+
|
| 327 |
+
```bash
|
| 328 |
+
llama-server -m MiniCPM5-2B-F16.gguf -a MiniCPM5-2B --port 8080 -ngl 99 -c 8192 --jinja
|
| 329 |
+
```
|
| 330 |
+
|
| 331 |
+
在这个例子里 `-c 8192` 设置了上下文长度为 8192,可以根据需要修改上下文长度。
|
| 332 |
+
|
| 333 |
+
```bash
|
| 334 |
+
curl http://localhost:8080/v1/chat/completions \
|
| 335 |
+
-H "Content-Type: application/json" \
|
| 336 |
+
-d '{
|
| 337 |
+
"model": "MiniCPM5-2B",
|
| 338 |
+
"messages": [{"role": "user", "content": "1+1=?"}],
|
| 339 |
+
"temperature": 1.0, "top_p": 0.95, "min_p": 0.0, "max_tokens": 256
|
| 340 |
+
}'
|
| 341 |
+
```
|
| 342 |
+
|
| 343 |
+
llama.cpp 默认设置 `min_p=0.05`,会过滤掉概率低于最高概率 token 5% 的 token。这种过滤反而可能引发重复——它恰恰过滤掉了模型摆脱重复循环所需的那些 token。我们明确将 `min_p` 设为 `0.0` 以禁用该过滤。
|
| 344 |
|
| 345 |
### Transformers
|
| 346 |
|
README.md
CHANGED
|
@@ -279,6 +279,13 @@ During **post-training**, we proceed in three steps: **SFT**, **RL**, and **OPD*
|
|
| 279 |
|
| 280 |
## Quickstart
|
| 281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
### vLLM
|
| 283 |
|
| 284 |
```bash
|
|
@@ -327,6 +334,26 @@ python -m sglang.launch_server \
|
|
| 327 |
--port 30000
|
| 328 |
```
|
| 329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
### Transformers
|
| 331 |
|
| 332 |
```bash
|
|
@@ -355,7 +382,6 @@ outputs = model.generate(**inputs, max_new_tokens=128)
|
|
| 355 |
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
|
| 356 |
```
|
| 357 |
|
| 358 |
-
Recommended sampling params: `temperature=1.0, top_p=0.95`
|
| 359 |
|
| 360 |
## Tool Calling
|
| 361 |
|
|
|
|
| 279 |
|
| 280 |
## Quickstart
|
| 281 |
|
| 282 |
+
> [!Tip]
|
| 283 |
+
> We recommend using the following sets of sampling parameters for generation: `temperature=1.0, top_p=0.95, min_p=0.0`.
|
| 284 |
+
>
|
| 285 |
+
> If you encounter repetitive outputs, try: `temperature=1.0, top_p=0.95, min_p=0.0, repetition_penalty=1.05`.
|
| 286 |
+
>
|
| 287 |
+
> Please note that the support for sampling parameters varies according to inference frameworks.
|
| 288 |
+
|
| 289 |
### vLLM
|
| 290 |
|
| 291 |
```bash
|
|
|
|
| 334 |
--port 30000
|
| 335 |
```
|
| 336 |
|
| 337 |
+
### Llama.cpp
|
| 338 |
+
|
| 339 |
+
```bash
|
| 340 |
+
llama-server -m MiniCPM5-2B-F16.gguf -a MiniCPM5-2B --port 8080 -ngl 99 -c 8192 --jinja
|
| 341 |
+
```
|
| 342 |
+
|
| 343 |
+
`-c 8192` sets the context length. You can adjust this value as needed.
|
| 344 |
+
|
| 345 |
+
```bash
|
| 346 |
+
curl http://localhost:8080/v1/chat/completions \
|
| 347 |
+
-H "Content-Type: application/json" \
|
| 348 |
+
-d '{
|
| 349 |
+
"model": "MiniCPM5-2B",
|
| 350 |
+
"messages": [{"role": "user", "content": "1+1=?"}],
|
| 351 |
+
"temperature": 1.0, "top_p": 0.95, "min_p": 0.0, "max_tokens": 256
|
| 352 |
+
}'
|
| 353 |
+
```
|
| 354 |
+
|
| 355 |
+
In llama.cpp, the default `min_p=0.05` can lead to repetitive output: it filters out tokens whose probability is below 5% of the highest-probability token, potentially discarding the exact tokens needed to break out of a repetition loop. To prevent this, we set `min_p=0.0`.
|
| 356 |
+
|
| 357 |
### Transformers
|
| 358 |
|
| 359 |
```bash
|
|
|
|
| 382 |
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
|
| 383 |
```
|
| 384 |
|
|
|
|
| 385 |
|
| 386 |
## Tool Calling
|
| 387 |
|