跳到主要内容

MiniCPM5-2B

MiniCPM 文本系列

MiniCPM5-2B 是 MiniCPM5 系列的第二个模型,将 MiniCPM5-1B 的训练方案扩展至 2B 参数规模,面向本地助手、Coding Agent、工具调用流程以及需要紧凑模型的推理场景。模型在保持较小部署体积与原生长上下文能力的同时,进一步增强代码、数学、长文本、工具调用和 Agent 任务能力,达到同尺寸开源模型 SOTA 水平,综合表现可与部分 4B 级模型竞争。

按部署工具选择对应权重格式,或按训练需求查看 Base、Midtrain 与 SFT 等版本。不同训练阶段的权重用途不同,请先阅读相应模型卡。

模型下载​

当前主推版本:MiniCPM5-2B(BF16 / GGUF / MLX / GPTQ):

快速上手​

对三种最常用的推理路径,可以按下面方式启动服务或本地推理。 MiniCPM5-2B 推荐使用 temperature=1.0, top_p=0.95。

vLLM(OpenAI 兼容服务,NVIDIA GPU)​

Bash
pip install "vllm>=0.21"
vllm serve openbmb/MiniCPM5-2B --port 8000

测试请求:

Bash
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "openbmb/MiniCPM5-2B",
"messages": [{"role": "user", "content": "你是谁?可以简单介绍一下自己吗?"}],
"max_tokens": 128,
"temperature": 1.0,
"top_p": 0.95
}'

SGLang(OpenAI 兼容服务,NVIDIA GPU)​

Bash
pip install "sglang[srt]>=0.5.16"
python -m sglang.launch_server --model-path openbmb/MiniCPM5-2B --port 30000

测试请求:

Bash
curl http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "openbmb/MiniCPM5-2B",
"messages": [{"role": "user", "content": "你是谁?可以简单介绍一下自己吗?"}],
"max_tokens": 128,
"temperature": 1.0,
"top_p": 0.95
}'

DSpark 投机解码​

我们同步发布了为 MiniCPM5-2B 训练的 MiniCPM5-2B-DSpark 草稿模型。在 SGLang 中启用后可加速解码,同时保持目标模型输出不变。

Bash
python -m sglang.launch_server \
--model-path openbmb/MiniCPM5-2B \
--trust-remote-code \
--speculative-algorithm DSPARK \
--speculative-draft-model-path openbmb/MiniCPM5-2B-DSpark \
--speculative-dspark-block-size 7 \
--port 30000

Transformers(Python 本地推理,CPU 或 GPU)​

Bash
pip install -U "transformers>=5.6" accelerate torch

本地推理测试:

Python
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "openbmb/MiniCPM5-2B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype="auto",
device_map="auto",
)

messages = [{"role": "user", "content": "你是谁?可以简单介绍一下自己吗?"}]
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
enable_thinking=True,
return_dict=True,
return_tensors="pt",
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=128)
print(tokenizer.decode(
outputs[0][inputs["input_ids"].shape[-1]:],
skip_special_tokens=True,
))

推荐采样参数:temperature=1.0, top_p=0.95 其余后端(llama.cpp / Ollama / LM Studio / MLX / ArcLight / vLLM Ascend)见部署指南。

工具调用(Function Call)​

推荐使用 SGLang。 MiniCPM5-2B 以 XML 格式产出工具调用,SGLang 内置的 minicpm5 parser 会自动将其转换为 OpenAI 兼容的 tool_calls 字段。

Bash
python -m sglang.launch_server --model-path openbmb/MiniCPM5-2B --port 30000 \
--tool-call-parser minicpm5 # 或:--tool-call-parser auto

相关资源​

开发者精选

查看全部 →