Ascend-SACT/MiniCPM5-1B
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

MiniCPM5-1B 补丁应用与运行手册

1. 简介

本目录提供的是 MiniCPM5-1B 在 vLLM-Ascend 上运行所需的 patch 交付物:

  • vllm-minicpm5-1b.patch

其中:

  • vllm-minicpm5-1b.patch
    • 面向 vllm
    • 新增 minicpm_xml 工具调用解析器,用于将 MiniCPM5-1B 的 XML 工具调用输出转换为 OpenAI 兼容的 tool_calls 字段。

2. 补丁应用

基础镜像:

  • quay.io/ascend/vllm-ascend:v0.19.1rc1

准备变量:

PATCH_DIR=/path/to/minicpm5_1b/patch
VLLM_REPO=/path/to/vllm
MODEL_PATH=/path/to/MiniCPM5-1B

应用 vllm 补丁:

cd "$VLLM_REPO"
git apply --check "$PATCH_DIR/vllm-minicpm5-1b.patch"
git apply "$PATCH_DIR/vllm-minicpm5-1b.patch"

如需回退已应用补丁,可执行:

cd "$VLLM_REPO"
git apply -R --check "$PATCH_DIR/vllm-minicpm5-1b.patch"
git apply -R "$PATCH_DIR/vllm-minicpm5-1b.patch"

3. 服务启动

3.1 MiniCPM5-1B 单逻辑 NPU

cd /workspace
ASCEND_RT_VISIBLE_DEVICES=0 HCCL_OP_EXPANSION_MODE=AIV \
vllm serve "$MODEL_PATH" \
  --served-model-name MiniCPM5-1B \
  --trust-remote-code \
  --dtype bfloat16 \
  --port 8000 \
  --enable-auto-tool-choice \
  --tool-call-parser minicpm_xml \
  --compilation-config '{"cudagraph_mode":"FULL_DECODE_ONLY"}'

--tool-call-parser minicpm_xml 用于启用 MiniCPM5-1B 的 XML 工具调用解析器;如不需要工具调用能力,可去掉 --enable-auto-tool-choice 和 --tool-call-parser minicpm_xml。

4. 基本验证

服务健康检查:

curl -sS http://127.0.0.1:8000/health -w '\nHTTP %{http_code}\n'

预期返回 HTTP 200。

服务就绪检查:

curl -sS http://127.0.0.1:8000/v1/models

预期返回中应包含:

  • id: MiniCPM5-1B
  • root: 当前 MODEL_PATH
  • max_model_len: 模型默认上下文长度

文本生成验证:

curl -sS http://127.0.0.1:8000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model":"MiniCPM5-1B",
    "messages":[
      {"role":"user","content":"用中文简短回答:2+3等于几?"}
    ],
    "temperature":0,
    "max_tokens":32,
    "chat_template_kwargs":{
      "enable_thinking":false
    }
  }'

工具调用验证:

curl -sS http://127.0.0.1:8000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model":"MiniCPM5-1B",
    "messages":[
      {"role":"user","content":"查询北京今天的天气"}
    ],
    "tools":[
      {
        "type":"function",
        "function":{
          "name":"get_weather",
          "description":"查询城市天气",
          "parameters":{
            "type":"object",
            "properties":{
              "city":{"type":"string","description":"城市名称"}
            },
            "required":["city"]
          }
        }
      }
    ],
    "tool_choice":"auto",
    "temperature":0,
    "max_tokens":128,
    "chat_template_kwargs":{
      "enable_thinking":false
    }
  }'

预期返回中应包含 OpenAI 兼容的 tool_calls 字段。

5. 注意事项

  • 启动命令中的 --trust-remote-code 需要保留,否则模型侧自定义配置可能无法加载。
  • MiniCPM5-1B 支持 Think / No Think 两种对话模式,可通过 chat_template_kwargs.enable_thinking 控制。
  • 启用工具调用时,需要同时设置 --enable-auto-tool-choice 和 --tool-call-parser minicpm_xml。