Qwen2.5-3B-Instruct, tool calling with abstention (v6)
Improved using Qwen. Fine-tuned from Qwen/Qwen2.5-3B-Instruct with QLoRA, then the adapter was merged into the weights.
Contents of this repo: merged fp16 model (root), 4-bit MLX version (mlx/, for Apple silicon with mlx-lm), and the LoRA adapter (adapter/). Code, evaluation and agent pipeline: https://github.com/siva-0104/toolcall-slm
Qwen2.5-Instruct (0.5B, 1.5B, 3B) fine-tuned with QLoRA for tool calling with abstention.
What it does
Given a user request and a list of tool schemas (JSON), the model either emits <tool_call>{"name": ..., "arguments": {...}}</tool_call> (one or several calls), asks for missing information, or says that no listed tool applies. Intended use: small local agents, with tools retrieved from a larger library (top 5 by embedding similarity) and calls validated against the schema before execution (see agent/).
Training data (all public, leak-gated)
xLAM function-calling 60k (CC-BY-4.0, gated; cite APIGen / xLAM), Glaive function-calling v2 (Apache-2.0; filler replies merged with the call that follows), Hermes function-calling v1 (Apache-2.0), ToolACE (Apache-2.0), plus synthetic mismatched-tool negatives. About 49% of call rows carry 1 to 4 look-alike distractor tools retrieved from the training tool library. 8,559 rows (8,366 after the 1,024-token limit); 24% are no-call rows. No When2Call and no BFCL rows. Splits are disjoint by tool name; leak_check.py passes (0 BFCL query matches, no test tool name in training). Disclosure: 13 of 9,314 BFCL function definitions are identical (name and description) to a training tool, an information-only overlap with different queries.
Training
QLoRA, 4-bit NF4, LoRA r=16 alpha=32, lr 2e-4 cosine, effective batch 16, 1 epoch, loss on the reply only, free Kaggle T4 (0.5B 44 min, 1.5B 100 min, 3B 169 min).
Results (own scorer, not the official BFCL checker; one seed; BFCL report-only)
| 0.5B | 1.5B | 3B | |
|---|---|---|---|
| BFCL simple, exact match | 79.3 | 83.7 | 89.7 |
| BFCL irrelevance, abstained | 75.8 | 84.2 | 87.1 |
| BFCL live simple / live irrelevance | 44.6 / 71.7 | 56.6 / 77.0 | 66.3 / 77.0 |
| xLAM / Hermes / ToolACE exact (leak-free tests) | 68.0 / 48.0 / 44.3 | 71.7 / 53.3 / 49.0 | 77.3 / 59.3 / 53.7 |
| Mismatched tools, abstained | 99.7 | 99.7 | 100 |
| Agent over MCP, 49 queries, 10 tools: call success | 80.6% | 93.5% | 93.5% |
Comparison with the base model
| Set | 3B base -> v6 |
|---|---|
| BFCL simple, exact | 90.7 -> 89.7 |
| BFCL live simple, exact | 59.3 -> 66.3 |
| BFCL irrelevance, abstained | 79.3 -> 87.1 |
| BFCL live irrelevance, abstained | 65.3 -> 77.0 |
| xLAM, exact | 38.7 -> 77.3 |
| Hermes, exact | 41.3 -> 59.3 |
| ToolACE, exact | 27.3 -> 53.7 |
| Glaive, decision accuracy | 90.0 -> 99.0 |
| Mismatched tools, abstained | 98.7 -> 100.0 |
Reading it: the base 3B model is already strong on single calls (BFCL simple 91% base, 90% after; no gain within noise). Fine-tuning helps most on the multi-call and mixed sets (xLAM 39 to 77, Hermes 41 to 59, ToolACE 27 to 54, Glaive 90 to 99) and raises abstention on BFCL irrelevance (79 to 87) and live irrelevance (65 to 77), because the base model calls a tool on 21% of the irrelevance prompts.
Base = the untouched Qwen2.5-Instruct model with the same prompt and scorer. Base rows use the first 150 items per set (BFCL from results_v2, other sets from results_v4); v6 rows use up to 300, so base numbers are noisier (about ±8 points). A fresh same-size rerun was not possible (free GPU quota exhausted).
Limitations
- Weak on missing information: the 1.5B model often calls with an invented value instead of asking (4 of 6 test queries; 3B: 3 of 6).
- Abstention is imperfect (BFCL irrelevance 76 to 84%); a similarity gate adds a few points at a cost on valid calls.
- With thousands of tools the retriever is a bottleneck: right tool in the top 5 for 70% of queries at 12,641 tools (94% at 100), and "no tool fits" handling falls from 93-100% at 10 tools to 15-19% when the top 5 come from the full library (laptop sample, n = 100 per condition). Putting 100 tools in the prompt is worse still (exact match 6% at 0.5B, 29% at 1.5B).
- Schema-constrained decoding (lm-format-enforcer) gave 100% parsed and schema-valid calls and no invented tool names on xLAM, BFCL simple and live simple at 0.5B and 1.5B (100 items per set; plain decoding is 90% and 97% valid on live simple). It does not make arguments correct. The 3B model was not tested with it (memory).
- Hand-written agent evaluation is small (49 queries); differences under about 10 points are noise.
- English only; not safety-tuned beyond the base model; tool outputs should be treated as untrusted.
Quick start
from transformers import AutoModelForCausalLM, AutoTokenizer
m='siva-0104/qwen2.5-3b-toolcall-abstain-v6'
tok=AutoTokenizer.from_pretrained(m); model=AutoModelForCausalLM.from_pretrained(m, torch_dtype='auto')
Prompt with the Qwen chat template and your tool list in the system message; the model answers with <tool_call>{...}</tool_call>, a clarifying question, or a statement that no tool applies. See the GitHub repo for the exact prompt format (tc_eval_lib.py) and the validating agent loop.
Licence
The base model Qwen2.5-3B-Instruct is released under the Qwen Research License (non-commercial: research and evaluation only; commercial use needs a licence from Alibaba Cloud). This derivative inherits those terms; the licence text is in LICENSE. Improved using Qwen. Training data licences as above (CC-BY-4.0 attribution for xLAM).