Skip to content

support MiniCPM5 XML tool calls - #24743

Open
zkh2016 wants to merge 7 commits into
ggml-org:masterfrom
zkh2016:minicpm-toolcall
Open

support MiniCPM5 XML tool calls#24743
zkh2016 wants to merge 7 commits into
ggml-org:masterfrom
zkh2016:minicpm-toolcall

Conversation

@zkh2016

@zkh2016 zkh2016 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Overview

support MiniCPM5 BPE tokenizer (fixes garbage generation)
support MiniCPM5 XML tool calls ()

./build/bin/llama-server   -m MiniCPM5-1B-Q4_0.gguf   --jinja --chat-template-file models/templates/MiniCPM5.jinja   --host 0.0.0.0 --port 8080

Additional information

Requirements

zkh2016 added 2 commits June 15, 2026 12:48
MiniCPM5-2.8B ships a BPE tokenizer.json (LlamaTokenizerFast) plus a stale
sentencepiece tokenizer.model with a different vocabulary. The minicpm
converter hardcoded _set_vocab_sentencepiece(), so it picked the wrong vocab
and the model produced garbage / immediate-EOS despite loading fine.

- minicpm set_vocab(): fall back to the BPE path (_set_vocab_gpt2) when there
  is no sentencepiece tokenizer.model.
- register the MiniCPM5 pre-tokenizer hash as the qwen2-style pre-tokenizer.

Convert from a directory without tokenizer.model so the BPE path is used.
Verified: tokenization now matches transformers, and short/long-context
generation is correct on host and on the Hexagon NPU.

(cherry picked from commit cd8f6f26b427cfbc570b6c09d4e4efa934efb1e6)
MiniCPM5 emits tool calls as attribute-keyed XML:
  <function name="NAME"><param name="KEY">VALUE</param>...</function>

Two problems prevented llama.cpp from returning OpenAI-style tool_calls:

1. The shipped chat template references an undefined variable (has_tool_sep)
   in its assistant tool_call branch, so minja throws when the differential
   auto-parser probes it. Analysis then aborts and the generated grammar is
   empty. Add a normalized, analyzer-friendly template in models/templates/
   that keeps the same <function>/<param> wire format (use via
   --chat-template-file).

2. Even with a clean template the differential analyzer mis-infers this
   attribute-keyed format. Pin it explicitly in the workarounds table as
   TAG_WITH_TAGGED with the right markers, and register the <function>/<param>
   delimiters as preserved tokens so they survive detokenization (they are
   special/control tokens) and reach the tool-call parser.

Verified end-to-end on MiniCPM5-1B (llama-server --jinja): single-arg,
multi-arg, and no-tool requests all produce correct tool_calls / content.
@zkh2016
zkh2016 requested review from a team and CISC as code owners June 18, 2026 01:37
@github-actions github-actions Bot added the python python script changes label Jun 18, 2026
Comment thread conversion/base.py Outdated
Comment thread models/templates/MiniCPM5.jinja
@github-actions github-actions Bot added the jinja parser Issues related to the jinja parser label Jun 23, 2026
@aldehir

aldehir commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This is already taken care of here: #24889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jinja parser Issues related to the jinja parser python python script changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants