File size: 4,270 Bytes
a87bee4
 
ae0023a
 
 
 
 
 
 
 
 
 
a87bee4
ae0023a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
license: apache-2.0
base_model: Qwen/Qwen3-1.7B
tags:
- tool-calling
- function-calling
- gguf
- llama.cpp
- on-device
- qwen3
library_name: llama.cpp
pipeline_tag: text-generation
---

# qwen3-1.7b-toolcall (Q5_K_M GGUF)

A QLoRA fine-tune of **Qwen3-1.7B** that reliably emits `<tool_call>` blocks for four
local search tools, intended for **on-device inference** (iOS / llama.cpp). Quantized to
**Q5_K_M** (~1.2 GB).

- **Base model:** [Qwen/Qwen3-1.7B](https://huggingface.co/Qwen/Qwen3-1.7B) (Apache-2.0)
- **Method:** QLoRA (Unsloth) — r=16, α=32, all 7 attn/MLP projections, 3 epochs, lr 2e-4, cosine, AdamW-8bit
- **Format:** bare ChatML, no `<think>` blocks

## What it does

Given a user message, it either calls one of four tools or answers directly (math, chitchat,
general knowledge, questions about the tools).

| Tool | Purpose |
|---|---|
| `search_recipes(query, sort_by)` | find recipes by dish / ingredient |
| `search_events(query, region, max_price)` | find concerts, sports, shows |
| `search_food_categories(query, min_tier)` | browse dish categories by popularity tier (1–5) |
| `search_regions(query)` | look up which cities a region covers |

A tool call is emitted as exactly:

```
<tool_call>
{"name": "search_recipes", "arguments": {"query": "cubano"}}
</tool_call>
```

## Prompt format

Plain ChatML, one block per message, then an empty assistant turn to generate:

```
<|im_start|>system
{system prompt}<|im_end|>
<|im_start|>user
{user message}<|im_end|>
<|im_start|>assistant
```

System prompt the model was trained on:

```
You have access to these tools. To use one, reply ONLY with a tool_call block:

<tool_call>
{"name": "TOOL_NAME", "arguments": {"key": "value"}}
</tool_call>

Tools:
- search_recipes(query, sort_by): Find recipes by dish name or ingredient.
- search_events(query, region, max_price): Find concerts, sports, shows.
- search_food_categories(query, min_tier): Browse 100 dish categories by tier (1-5).
- search_regions(query): Look up which cities a region covers.

If the question does NOT need a tool, answer directly without a tool_call block.
```

Two-turn flow: the model emits a `<tool_call>`; your app runs the tool and feeds the result
back as a system message (`Tool results:\n{...}\n\nNow answer the user's question using the
results above.`), then the model writes the final natural-language answer.

## Evaluation

12-test tool-use suite + a 250-example held-out set. Q5_K_M, temperature 0:

| Metric | Base Qwen3-1.7B | This model (Q5_K_M) |
|---|---|---|
| Overall score | 0.767 | **0.850** |
| Pass rate (≥0.8) | 8/12 | **10/12** |
| Tool-call rate | 70% | **100%** |
| Valid tool-call JSON | 70% | **100%** |
| Correct tool name | 70% | **100%** |
| Held-out tool-name acc (unseen) | 47% | **100%** |

Q5_K_M matches the full-precision model (0.85) and passes under both the trained (no-few-shot)
prompt and a few-shot variant. An **overfitting check** showed train acc = holdout acc = 100%
(zero gap) and 94% on deliberately off-template slang/typo queries — it learned the skill, not
the training set.

## Usage (llama.cpp)

```bash
hf download python3isfun/qwen3-1.7b-toolcall-gguf qwen3-1.7b-toolcall-Q5_K_M.gguf --local-dir .
./llama-cli -m qwen3-1.7b-toolcall-Q5_K_M.gguf --temp 0 -p "<your ChatML prompt>"
```

```python
from llama_cpp import Llama
llm = Llama(model_path="qwen3-1.7b-toolcall-Q5_K_M.gguf", n_ctx=2048)
prompt = ("<|im_start|>system\n" + SYSTEM_PROMPT + "<|im_end|>\n"
          "<|im_start|>user\nFind me a recipe for tacos<|im_end|>\n"
          "<|im_start|>assistant\n")
print(llm(prompt, temperature=0.0, stop=["<|im_end|>"])["choices"][0]["text"])
# -> <tool_call>\n{"name": "search_recipes", "arguments": {"query": "tacos"}}\n</tool_call>
```

## Notes & limitations

- Trained against a specific local dataset (recipes/events/food categories/regions); tool
  *results* must come from that data for grounded final answers.
- Constrained task (4 tools) — strong scores mean "no overfitting on this skill," not "flawless
  on every input."
- A `Q4_K_M` variant (~1.06 GB) also exists; it matches Q5 under the trained prompt but is
  slightly less robust under a longer few-shot prompt.

## License

Apache-2.0, inherited from the Qwen3-1.7B base model.