A lenient parser rescued 0 of 75 Qwen3.6 tool-call misses in MLX; the model skipped calls https://hackbig.com/blog/local-tool-call-accuracy-m3-max Files: - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/README.md.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/analyze.py.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/parsers.py.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/prompts.py.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/ref__Qwen_Qwen3.6-35B-A3B.README.md.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/ref__mlx-community_Qwen3.6-35B-A3B-4bit.README.md.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/ref__mlx-community_gemma-3-12b-it-4bit.README.md.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/results.json.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/run.sh.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/run_bench.py.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/scoring.py.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/tasks.py.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/test_offline.py.txt - https://hackbig.com/blog-data/local-tool-call-accuracy-m3-max/tools.py.txt # Tool-call accuracy of local models on an M3 Max (MLX) When a local model gets a tool call wrong, is the model at fault, or the parser? Does Qwen3.6's thinking mode fix enough errors to justify the extra latency? This benchmark answers both on **96 hand-written tool-calling tasks**, using: | condition | model | tool menu | thinking | seeds | max tokens | |---|---|---|---|---|---| | `qwen_nothink_8` | mlx-community/Qwen3.6-35B-A3B-4bit | 8 tools | off | 3 | 512 | | `qwen_nothink_32` | same | 32 tools (12 real + 20 decoys) | off | 1 | 512 | | `qwen_think_8` | same | 8 tools | on | 1 | 1536 (thinking + answer) | | `gemma_8` | mlx-community/gemma-3-12b-it-4bit | 8 tools | n/a | 3 | 512 | ## What it measures - Exact-match tool-call accuracy under a **strict** parser (the format exactly as specified) and a **lenient** parser (also recovers calls from missing closing tags, JSON inside ``, other code fences, bare JSON, single quotes, trailing commas and key aliases; it never edits values). For Qwen it also reports a third parser: **mlx_lm's own `qwen3_coder` parser**, applied the way `mlx_lm.server` applies it. - The **parser-recoverable share**: runs wrong under strict but right under lenient, as a share of all strict failures. - One failure label per miss: `truncated_by_cap`, `malformed_output`, `skipped_needed_call`, `called_when_not_needed`, `wrong_tool`, `wrong_or_missing_arg`, `hallucinated_arg`. - Accuracy per category, the drop from 8 to 32 tools, thinking gain, and Gemma vs Qwen (all paired by task, with 95% bootstrap CIs over tasks). - Median and p90 latency per task, median generated tokens, cap-hit rate, peak memory, and seed spread. Every number is written to `results.json` (`metrics`, `tables`, `observations`, `caveats`). ## Files | file | purpose | |---|---| | `tools.py` | 12 fictional tool schemas (enums, nested objects, optional args, arrays) and 20 decoys | | `tasks.py` | 96 tasks (6 categories x 16) with exact ground truth and accepted alternatives; 3 warm-up tasks | | `prompts.py` | tool menus, chat-template rendering, and the shared prefix used for the prompt cache | | `parsers.py` | strict, lenient and mlx_lm parsers | | `scoring.py` | argument normalisation (case and whitespace, numeric tolerance, order-insensitive arrays, arithmetic equivalence for `evaluate_math`) and failure labels | | `run_bench.py` | MLX generation, writing `raw/.jsonl` and `raw/meta.json` | | `analyze.py` | scoring, bootstrap and `results.json`; also writes `review/wrong_arg_misses.jsonl` and `scored_rows.jsonl` | | `test_offline.py` | CPU-only checks: suite validity, gold answers rendered by Qwen's own template must score 100%, parser and failure-label unit tests, and the analysis pipeline on a synthetic fixture held in a temp dir | | `ref/` | model cards downloaded from Hugging Face, kept as the source for the sampling settings | ## Method notes - **Native formats.** Qwen gets its tools through the chat template's `tools=` argument. The template shipped in this snapshot (sha256 in `results.json`) defines an XML-style call format, `value`, not JSON. So "strict" means that format; strings are raw and everything else is JSON, as the template writes them. Gemma 3's template has no tool role. It gets a fixed system prompt that lists the tool JSON schemas and asks for ```` ```tool_call ```` JSON blocks. That makes Gemma a prompted-format comparison, not like for like. - **Menus.** The 8-tool menu holds the needed tool(s), any forced similar distractors, and random other real tools, shuffled per task with a fixed seed. The 32-tool menu is the same fixed order for every task. - **Sampling** follows the model cards. Qwen thinking off: temp 0.7, top_p 0.8, top_k 20, presence 1.5. Qwen thinking on: temp 1.0, top_p 0.95, top_k 20, presence 1.5. The presence penalty applies to generated tokens only, matching OpenAI/vLLM semantics. Gemma 3: temp 1.0, top_p 0.95, top_k 64. - **Prompt cache.** For each tool menu, the tokens shared by all prompts (system + tool definitions) are prefilled once and deep-copied for each task. The dry run checks that all 96 prompts in every condition start with that prefix. Latency is per task with the prefix already cached. The one-off prefix prefill is reported separately (`*.prefix_prefill_median_s`). - **Time budget.** Conditions run sequentially, 3 untimed warm-up tasks per model. Each condition has a cumulative deadline (10 / 14 / 25 / 36.5 min), so the whole run fits in 40 minutes. Tasks run round-robin across categories, with seeds in the inner loop. If a condition is cut short, it stays balanced across categories, `tasks_completed` says so, and every comparison is paired on common tasks. - **Hand review.** Every `wrong_or_missing_arg` miss is written to `review/wrong_arg_misses.jsonl`. To publish adjudications, add `adjudications.json` (`{"cond|task_id|seed": {"correct": true, "note": "..."}}`) and re-run `analyze.py`. Adjudicated accuracy is then reported separately; headline numbers never include it. ## Reproduce Hardware: Apple M3 Max (the run records `hw.model`, CPU, RAM, macOS build, and mlx/mlx_lm versions). Software: Python 3.13 (miniconda), mlx 0.31.2, mlx-lm 0.31.3, numpy 2.4.2, transformers 5.12.1. ```zsh # one-time, with network: fetch the two models into the Hugging Face cache (about 27 GB) hf download mlx-community/Qwen3.6-35B-A3B-4bit hf download mlx-community/gemma-3-12b-it-4bit # offline, nothing else running on the machine (~40 min) ./run.sh # pieces HF_HUB_OFFLINE=1 python test_offline.py # CPU-only checks HF_HUB_OFFLINE=1 python run_bench.py --dry-run # render all prompts, verify prefix caching HF_HUB_OFFLINE=1 python run_bench.py --limit 12 --budget-scale 0.3 # quick partial GPU run python analyze.py # re-score raw/ -> results.json ``` ## Caveats - 96 synthetic tasks we wrote ourselves. Differences under about 8 points may be noise, so read the CIs. Thinking-on and 32-tool use 1 seed each. - Exact-match scoring can punish valid alternatives. We normalise case, whitespace, numbers, array order, clock times ("9:15" = "09:15") and arithmetic ("0.18*2450" = 441), and accept city aliases ("Lisbon, Portugal"). Dates must be ISO, as the schemas say. - An optional argument the user never asked for counts as `hallucinated_arg` unless it equals the schema default or the task allows it. - The lenient parser can also over-extract, for example JSON shown in a normal answer. `lenient_regressions` counts those cases. - Results apply to these 4-bit MLX builds, these chat templates and these mlx/mlx_lm versions, not to vLLM or llama.cpp. - If the run is not on an idle machine, the timings are not comparable.