MiniCPM-V MiniCPM-V & o Cookbook

MiniCPM-V 4.7 — SGLang 文档

说明

MiniCPM-V 4.7 暂未合入上游 SGLang。请使用 fork tc-mb/sglang 的 Support-MiniCPM-V4.7 分支。 上游 PR 进行中,合入后可直接安装 SGLang main。

MiniCPM-V 4.7 提供两个尺寸,改 --model-path 即可切换:

1. 安装 SGLang

git clone -b Support-MiniCPM-V4.7 https://github.com/tc-mb/sglang.git
cd sglang

pip install --upgrade pip
pip install -e "python[all]"

需要 transformers >= 5.18.0(4.7 在其中为原生架构)。验证:

python -c "import torch, transformers; print('torch', torch.__version__, '| cuda', torch.version.cuda, '| transformers', transformers.__version__)"

安装 FlashInfer(可选,推荐)

重要

FlashInfer 的 wheel 与特定 (torch, cuda) 组合绑定。请选择与上面刚验证过的 torch + CUDA 匹配的索引 —— 不要盲目照抄 cu121/torch2.4 这类 URL。

通用索引见 https://flashinfer.ai/whl/,例如:

你的 torch / CUDA 索引 URL
torch 2.7 + CUDA 12.8 https://flashinfer.ai/whl/cu128/torch2.7/
pip install flashinfer-python -i <上表对应索引 URL>

Docker 镜像与纯 CPU 回退见 SGLang 官方安装文档。

2. 启动推理服务

# 1B
python -m sglang.launch_server --model-path openbmb/MiniCPM-V-4.7-1B --port 30000 --dtype bfloat16

# 35B-A3B(需大显存节点;用 --tp-size 跨卡分片)
python -m sglang.launch_server --model-path openbmb/MiniCPM-V-4.7-35B-A3B --port 30000 --dtype bfloat16 --tp-size 2

或指定本地路径:

python -m sglang.launch_server --model-path /your/local/MiniCPM-V-4.7-1B --port 30000 --dtype bfloat16

4.7 不需要 --trust-remote-code(在 transformers >= 5.18.0 中原生支持)。

3. 调用服务

若 image_url 本机不可达,换成本地路径 / base64 data URL。

v4.7 使用 Qwen3.5 词表 —— 若模型在答案后继续输出,传入 stop_token_ids = [248044, 248046]。

如需关闭 <think> 块,传 chat_template_kwargs={"enable_thinking": false}(或服务端等价默认值)。