英特尔×面壁智能:OpenVINO™ Day0适配MiniCPM5-2B,端侧推理开箱即用
导语:把推理模型搬上 Agentic PC
英特尔已实现对MiniCPM5-2B的Day0适配支持,这是双方7月签署战略备忘录后的又一次深度合作。本次适配的模型来自面壁智能刚刚开源的小钢炮系列端侧语言基础模型MiniCPM5-2B,其最大突破是实现端侧通用Agent能力雏形,部分任务表现超越Qwen3.5、DeepSeek R1等主流模型,验证了端侧通用Agent的技术可行性。同时,本次开源同步开放模型权重、RL框架、部分训练Recipe及一批SFT数据,相比多数团队仅开源权重的做法,对开发者更具研究价值。
在技术层面,MiniCPM5-2B主打三大亮点:AA Index榜单4B参数以下能力最强,支持混合思考,覆盖通用知识、数学/代码推理、指令遵循、多语言、长文本、工具调用、深度搜索等任务;采用全新预训练数据处理工具UltraX,可对L1网页数据进行行级自动编辑,同步开源三个数据集;原生支持工具调用、深度搜索、代码生成等Agent能力,并完成Agentic预训练、SFT、大规模RL全流程优化与开源。依托酷睿Ultra平台的XPU异构算力与OpenVINO™工具套件,英特尔为模型提供全链路端侧优化,涵盖混合精度量化、异构计算调度与NPU加速等关键环节,有效控制内存占用,降低长上下文推理延迟,保证Agent任务低功耗运行。
在英特尔平台上,依托酷睿Ultra系列XPU全异构算力(CPU、GPU、NPU)以及OpenVINO™工具套件,对MiniCPM5-2B开展算子、图融合、内存调度全链路深度优化。相较于基准版本,预填充(Prefill)和解码(Decode)性能均得到大幅提升;可显著压低运行内存占用,大幅削减长上下文推理时延,以低功耗稳定跑通混合思考推理、工具调用、深度搜索、代码生成全套端侧Agent能力。开发者基于英特尔AI PC可实现开箱即用的本地化部署,从底层硬件、优化工具链到上层Agent应用形成完整闭环,充分释放MiniCPM5-2B端侧AI产业潜力。
接下来,本文会带你完整走一遍部署路径:从环境安装,到用 optimum-cli 一键导出 INT4 IR,再到基于 openvino-genai 的 LLMPipeline 完成推理,最后实战 Hybrid Reasoning 双模式切换。文中所有命令与代码都已在 Intel 平台的 Windows + Python 3.12 上实测跑通,并附上了本机验证产物;想看完整示例,可以直接参考 https://github.com/openvinotoolkit/openvino_notebooks/pull/3468 。
为什么选 OpenVINO™
OpenVINO™工具套件基于英特尔oneAPI跨架构编程框架构建,其核心思路是通过统一的中间表示(IR)将模型从训练框架(如PyTorch)解耦,再由针对CPU、集成显卡与NPU分别优化的硬件插件进行编译和执行,从而实现"一次转换、多端部署"的异构调度能力。在具体优化手段上:一是混合精度量化,支持INT8、FP16、FP8等多种数据类型的自动或手动量化,在几乎不损失模型效果的前提下大幅降低计算量与内存带宽压力;二是算子融合与图优化,通过合并冗余计算节点、优化内存访问模式,减少数据搬运开销,从而降低长上下文场景下的推理延迟;三是动态任务调度,根据负载特征(如首Token生成的低延迟需求与后续解码的高吞吐需求)智能地在CPU、GPU、NPU间分配计算任务,将持续性、低功耗的AI负载优先调度至NPU执行,从而在保证响应速度的同时显著降低整机功耗,这对于MiniCPM5-2B这类需要长时间保持在线、频繁调用工具与深度搜索能力的Agent任务尤为关键。
Demo 演示视频
以下演示视频完整呈现 MiniCPM5-2B 在 OpenVINO™ 上的端侧部署效果,内容涵盖多轮对话、代码生成与工具调用等核心场景。
演示视频
端到端部署 MiniCPM5-2B
环境准备
建议 Python 3.10 及以上,先创建并激活独立 venv,再装本教程依赖:
python -m venv minicpm5-venv
# Windows: minicpm5-venv\Scripts\activate
# Linux / macOS: source minicpm5-venv/bin/activate
pip install -U \
"openvino-genai" \
"git+https://github.com/huggingface/optimum-intel.git" \
"nncf>=3.0" \
"transformers>=5.6" \
"torch" \
"accelerate" \
"huggingface_hub"
MiniCPM5-2B 是新发布的模型,部分特性需要 optimum-intel 主线分支才能完整支持,因此先用 git 主干;待 PyPI 新版本发布后即可切回。
国内访问 HuggingFace 不畅时,可在导出命令前临时注入 hf-mirror:
# Linux / macOS / Git Bash
export HF_ENDPOINT=https://hf-mirror.com
# Windows PowerShell
$env:HF_ENDPOINT = "https://hf-mirror.com"
一键导出 INT4 量化 IR
推荐使用 INT4 权重压缩——MiniCPM5-2B 量化后体积约 1.6GB,2B dense 模型在 Agentic PC 上即可流畅交互:
optimum-cli export openvino \
--model openbmb/MiniCPM5-2B \
--task text-generation-with-past \
--weight-format int4 \
--group-size 128 \
--ratio 0.8 \
MiniCPM5-2B-ov/INT4
–task text-generation-with-past 告诉 optimum-intel 这是带 KV-Cache 的因果语言模型;–ratio 0.8 表示 80% 的权重走 INT4,剩余 20% 保留更高精度,是社区在 LLM 上验证较稳的默认折中;–group-size 128 是 NNCF 分组量化的组大小。
导出完成后目录结构:
MiniCPM5-2B-ov/INT4/
├── chat_template.jinja
├── config.json
├── generation_config.json
├── openvino_config.json
├── openvino_detokenizer.bin / .xml
├── openvino_model.bin (~822 MB) / .xml
├── openvino_tokenizer.bin / .xml
├── tokenizer.json
└── tokenizer_config.json
想要更高质量或更小体积,分别有:
# INT8
optimum-cli export openvino --model openbmb/MiniCPM5-2B \
--task text-generation-with-past --weight-format int8 \
MiniCPM5-2B-ov/INT8
# FP16
optimum-cli export openvino --model openbmb/MiniCPM5-2B \
--task text-generation-with-past --weight-format fp16 \
MiniCPM5-2B-ov/FP16
复刻 chat_sample.py:最小可跑示例
下面这段代码是 OpenVINO™ GenAI 官方样例 chat_sample.py 的最小化版本,配合 HuggingFace 模型卡 transformers 章节里的同一句 prompt——Who are you? Please briefly introduce yourself.:
import openvino_genai
MODEL_DIR = "MiniCPM5-2B-ov/INT4"
DEVICE = "CPU" # 也可填 "GPU" / "AUTO"
pipe = openvino_genai.LLMPipeline(MODEL_DIR, DEVICE)
config = openvino_genai.GenerationConfig()
config.max_new_tokens = 128
def streamer(subword: str) -> openvino_genai.StreamingStatus:
print(subword, end="", flush=True)
return openvino_genai.StreamingStatus.RUNNING
# 与 chat_sample.py 一致:用 ChatHistory 累积多轮上下文
history = openvino_genai.ChatHistory()
history.append({
"role": "user",
"content": "Who are you? Please briefly introduce yourself.",
})
result = pipe.generate(history, config, streamer)
print("\n----------")
运行后预期看到模型流式打印自我介绍,并以 result.texts[0] 拿到完整回答。 本机实测(INT4 + Intel CPU)输出节选:
<think>
Hmm, the user is asking about my identity and wants a brief introduction.
...
</think>
I'm a model from the MiniCPM series, developed by ModelBest Inc. and the Open...
默认 chat template 启用了 thinking,所以输出里看到了 <think>…</think> 块——下一节我们用 enable_thinking 显式控制这个行为。
多轮 chat 循环
把 4.3 包装成一个交互循环就是 chat_sample.py 的标准形态:
import openvino_genai
pipe = openvino_genai.LLMPipeline("MiniCPM5-2B-ov/INT4", "CPU")
config = openvino_genai.GenerationConfig()
config.max_new_tokens = 256
def streamer(subword):
print(subword, end="", flush=True)
return openvino_genai.StreamingStatus.RUNNING
history = openvino_genai.ChatHistory()
while True:
try:
prompt = input("\nquestion:\n")
except EOFError:
break
history.append({"role": "user", "content": prompt})
result = pipe.generate(history, config, streamer)
history.append({"role": "assistant", "content": result.texts[0]})
print("\n----------")
混合思考:think vs no-think 实战
openvino-genai 提供了 Tokenizer.apply_chat_template 的 extra_context 参数,正好用来把 enable_thinking 透传给模型自带的 chat template,从而精确切换两种模式:
import openvino_genai
pipe = openvino_genai.LLMPipeline("MiniCPM5-2B-ov/INT4", "CPU")
tokenizer = pipe.get_tokenizer()
messages = [
{"role": "user",
"content": "Who are you? Please briefly introduce yourself."},
]
def streamer(subword):
print(subword, end="", flush=True)
return openvino_genai.StreamingStatus.RUNNING
for mode, enable_thinking, T in [("NO-THINK", False, 0.7),
("THINK", True, 0.9)]:
print(f"=== {mode} ===")
prompt = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
extra_context={"enable_thinking": enable_thinking},
)
config = openvino_genai.GenerationConfig()
config.max_new_tokens = 256
config.do_sample = True
config.temperature = T
config.top_p = 0.95
if not enable_thinking:
soc = openvino_genai.StructuredOutputConfig()
soc.regex = r"[^<].*"
config.structured_output_config = soc
pipe.generate(prompt, config, streamer)
print()
本机实测两种模式下,apply_chat_template 生成的 prompt 尾部明显不同,决定了模型行为:
# enable_thinking=False -> assistant 段落里被预填了空 think
'... <|im_start|>assistant\n<think>\n\n</think>\n\n'
# enable_thinking=True -> 留出空 think 让模型自由展开
'... <|im_start|>assistant\n<think>\n'
实测输出节选(INT4 + GPU + 上述采样参数):
=== NO-THINK ===
<think>
</think>
I am a MiniCPM series model, developed by ModelBest and the OpenBMB community.
For more information about the project, visit https://github.com/OpenBMB/.
=== THINK ===
<think>
...
</think>
I am a MiniCPM series model, developed by ModelBest and the OpenBMB
open-source community. ...
那么两种模式究竟该怎么选?答案其实很直观:闲聊问答、客服 FAQ、纯执行类任务追求的是低延迟和简洁输出,交给 No-Think 模式最合适;而数学推导、代码生成、复杂规划这类质量优先的场景,则更适合 Think 模式——不妨把 max_new_tokens 提到 1024 以上,再打开流式输出,让漫长的推理过程也不至于让人枯等。
总结与资源链接
MiniCPM5-2B 把「端侧 2B 混合思考」做到了开源 SOTA;OpenVINO™ + Optimum Intel + GenAI 这一套组合,让你只需一条 optimum-cli + 几十行 Python,就能在 Intel CPU / iGPU / 独显上跑出生产级别的多轮 chat,并随手切换两种思考模式。
- MiniCPM5-2B 模型卡: https://huggingface.co/openbmb/MiniCPM5-2B
- OpenVINO™ notebook: https://github.com/openvinotoolkit/openvino_notebooks/tree/latest/notebooks/llm-chatbot
- OpenBMB/MiniCPM 仓库: https://github.com/OpenBMB/MiniCPM
- openvino.genai chat_sample.py: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/python/text_generation/chat_sample.py
- Optimum Intel: https://github.com/huggingface/optimum-intel
- OpenVINO™: https://github.com/openvinotoolkit/openvino
- OpenVINO™ GenAI: https://github.com/openvinotoolkit/openvino.genai
- NNCF: https://github.com/openvinotoolkit/nncf
更多推荐



所有评论(0)