Views
No views yet
openbmb/MiniCPM5-1B, fine-tuned for function and tool calling.| protocol | parse | function name | semantic | strict | tokens/call | |
|---|---|---|---|---|---|---|
| this adapter | 98.0% | 98.0% | 96.5% | 79.0% | 75.0% | 62 |
| base model | 0.5% | 87.0% | 82.5% | 58.5% | 48.0% | 249 |
protocol is whether the model used the <tool_call> JSON form the prompt asked forsemantic is the right function with the right arguments, ignoring serialization differences the dataset is itself inconsistent about (80 vs "80", "a, b" vs "a,b")<think> block before answering while this one answers directly.modal run eval_toolcall.py --n 200.1import json
2
3# Whatever functions you want the model to be able to call.
4TOOLS = [{"name": "live_giveaways_by_type",
5 "description": "Retrieve live giveaways by type.",
6 "parameters": {"type": {"type": "str", "description": "game, loot or beta"}}}]
7
8from peft import PeftModel
9from transformers import AutoModelForCausalLM, AutoTokenizer
10
11base = "openbmb/MiniCPM5-1B"
12tokenizer = AutoTokenizer.from_pretrained(base)
13model = AutoModelForCausalLM.from_pretrained(base, torch_dtype="bfloat16", device_map="auto")
14model = PeftModel.from_pretrained(model, "HIMANSHUKUMARJHA/minicpm5-1b-toolcall-lora")
15
16messages = [
17 {
18 "role": "system",
19 "content": (
20 "You are a function calling AI model. You are provided with function "
21 "signatures within <tools></tools> XML tags. Call one or more functions "
22 "to assist with the user query. Do not make assumptions about what "
23 "values to plug into functions.\n<tools>\n"
24 + json.dumps(TOOLS, ensure_ascii=False)
25 + "\n</tools>\nFor each call, return a JSON object inside "
26 "<tool_call></tool_call> tags."
27 ),
28 },
29 {"role": "user", "content": "Show me live giveaways for beta access."},
30]
31inputs = tokenizer.apply_chat_template(
32 messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
33).to(model.device)
34inputs.pop("token_type_ids", None) # this architecture's generate() rejects it
35out = model.generate(**inputs, max_new_tokens=256)
36text = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False)
37for ctrl in ("<s>", "</s>", "<|im_start|>", "<|im_end|>"):
38 text = text.replace(ctrl, "") # keep <tool_call>, it is a real token
39print(text.strip())transformers>=4.51, which is the first version that reads MiniCPM's standalone chat_template.jinja.| Base model | openbmb/MiniCPM5-1B |
| Dataset | argilla/apigen-function-calling |
| Training rows | 60,000 |
| Steps | 6,000 (~1.6 epochs at effective batch 16) |
| LoRA rank / alpha | 32 / 64 |
| Target modules | attention + MLP projections |
| LR schedule | 0.0002 cosine, 3% warmup |
| Precision | bfloat16 |
| Hardware | 1x A100 |
modal run finetune.py --profile toolcall<tools></tools> in the system turn and emits each call as JSON inside <tool_call></tool_call> tags.