| # The Hidden Cost of Thinking: Evaluating Small Reasoning Models on Code Generation | |
| Artifacts for evaluating a small reasoning model (Qwen3-0.6B, thinking enabled) against a small non-reasoning model (Qwen2.5-1.5B-Instruct) on Python code generation, with a focus on a gap that standard benchmarks rarely report: what thinking costs and how often it fails to finish. | |
| --- | |
| ## 1. The Blind Spot | |
| **Standard code benchmarks report one number: pass@1.** They do not show how many tokens a model spent to get there, or how often it never produced an answer at all. | |
| For small reasoning models this is a serious omission. A thinking-enabled model emits a long reasoning trace before the code. On a small model this trace can: | |
| - run past the generation limit, so the answer is cut off and the problem counts as a failure with no usable output, | |
| - multiply latency and compute per problem several times over, and | |
| - look "better" on a leaderboard while being unusable in practice on limited hardware. | |
| This matters to me directly. I work on local-first LLM systems, running and fine-tuning small models with Ollama, vLLM, and Unsloth on limited compute. In that setting tokens are time and money, and a model that needs thousands of tokens to solve an easy problem is not a good fit, whatever its accuracy. Benchmarks aimed at frontier-scale, API-based use rarely penalize this, so the cost of reasoning in small models stays underexplored and underdiscussed. | |
| **Hypothesis (checked in the Analysis below, not assumed):** the thinking model spends many more tokens per problem, and a measurable share of its failures are truncations rather than wrong code. | |
| --- | |
| ## 2. Evaluation | |
| ### Models | |
| Both models are within the 0.6B to 6B range and are served locally with vLLM on a Colab GPU. | |
| | Role | Model | Parameters | Thinking | | |
| |---|---|---|---| | |
| | Baseline | Qwen/Qwen2.5-1.5B-Instruct | 1.5B | Not supported | | |
| | Reasoning | Qwen/Qwen3-0.6B | 0.6B | Enabled (`enable_thinking=True`) | | |
| ### Benchmark | |
| - Dataset: `google-research-datasets/mbpp` (test split, 500 problems). | |
| - Subset: 50 problems sampled once with seed 42, identical for both models. | |
| - The exact subset is saved in `datasets/mbpp_50.jsonl`. | |
| ### Methodology | |
| 1. **Serving:** each model runs behind vLLM's OpenAI-compatible chat endpoint. | |
| 2. **Prompt:** the task description and the MBPP assertions are sent as one user message asking for Python code only. The assertions are included so the model knows the required function name (the standard MBPP protocol), and they are also used for scoring. | |
| 3. **Decoding:** greedy (`temperature=0.0`), `repetition_penalty=1.05`, up to 4096 new tokens, 8 concurrent requests. | |
| 4. **Code extraction:** text before `</think>` is discarded. If a thinking generation never reaches `</think>`, no code is extracted and the problem counts as a failure. Otherwise the first fenced code block is used, or the raw answer if there is no fence. | |
| 5. **Scoring:** the extracted code runs in a separate Python process with each MBPP assertion (8 second timeout per test). A problem passes only if every assertion passes. | |
| 6. **Metrics:** pass@1, plus the cost-oriented metrics that standard reporting omits: truncated generations and mean generated tokens per problem. | |
| ### Results | |
| | model | mode | n_samples | passed | pass_at_1 | truncated | tokens_per_sample | wall_time_seconds | | |
| |:---------------------------|:------------|------------:|---------:|------------:|------------:|--------------------:|--------------------:| | |
| | Qwen/Qwen2.5-1.5B-Instruct | baseline | 50 | 21 | 0.42 | 0 | 42.94 | 16.68 | | |
| | Qwen/Qwen3-0.6B | thinking_on | 50 | 17 | 0.34 | 12 | 1982.86 | 578.53 | | |
| - **pass_at_1:** fraction of the 50 problems solved. | |
| - **truncated:** generations cut off by the token limit. These count as failures. | |
| - **tokens_per_sample:** mean generated tokens per problem, including thinking tokens. | |
| - **wall_time_seconds:** generation plus test execution, not pure model latency. | |
| ### Analysis | |
| - **Accuracy:** Qwen2.5-1.5B-Instruct solved 21/50 (42%); Qwen3-0.6B with thinking solved 17/50 (34%). | |
| - **Token cost:** the thinking model generated 1983 tokens per problem versus 43 for the baseline, about 46.2x more. | |
| - **Time cost:** the thinking run took 579s versus 17s for the baseline, about 34.7x longer. | |
| - **Failure breakdown (thinking model):** 33 of 50 problems failed; 12 were cut off by the 4096-token limit and 21 finished but did not pass the tests. | |
| - **Hypothesis check:** the claim that thinking costs many more tokens is supported by this run; the claim that a measurable share of failures are truncations is supported by this run (12 of 33 failures, 36%; threshold 10%). | |
| --- | |
| ## 3. Path Forward | |
| These are proposals, not tested results. | |
| 1. **Length-aware training signal.** Fine-tune with a reward that credits correct answers but penalizes unnecessarily long reasoning, so the model learns to stop thinking once it has a solution. | |
| 2. **Data curation for concise reasoning.** Build a training set of reasoning traces for coding problems, keep only traces that end in verified-correct code, and prefer the shortest correct trace for each problem. This teaches that short, correct reasoning is the target. | |
| 3. **Adaptive thinking.** Train or prompt the model to decide when to think. Easy problems get a direct answer, hard ones get a reasoning budget. This is a lightweight alternative to always-on thinking. | |
| 4. **Better evaluation reporting.** Report accuracy at a fixed token budget, tokens per solved problem, and truncation rate alongside pass@1, so that cost-blind leaderboards stop hiding this gap. | |
| --- | |
| ## Limitations | |
| - 50 problems is a small sample, so differences of a few points are within noise. | |
| - The two models differ in size, generation, and training data, so the comparison does not isolate the effect of reasoning alone. | |
| - Greedy decoding is used for reproducibility, although Qwen recommends sampling for thinking mode, which may change truncation behavior. | |
| - The evaluation set is a subset of an existing benchmark, not a newly built dataset. | |
| - Generated code is executed locally with only process isolation and a timeout, not a full sandbox. | |
| --- | |
| ## Files | |
| | File | Description | | |
| |---|---| | |
| | `README.md` | This document | | |
| | `results.jsonl` | Per-problem prompt, raw completion, extracted code, pass/fail, finish reason, token count | | |
| | `summary.json`, `summary.csv` | Aggregate metrics per model | | |
| | `run_config.json` | Seed, decoding settings, experiment list | | |
| | `environment.json` | Package versions used for the run | | |
| | `datasets/mbpp_50.jsonl` | The evaluated problems and their tests | | |
| | `models/` | Copies of both evaluated models | | |
| | `fit_mbpp_evaluation.ipynb` | The notebook that produced everything above | | |
| ## Reproducing | |
| Run `fit_mbpp_evaluation.ipynb` on a Colab GPU runtime with an `HF_TOKEN` secret. It installs vLLM, samples the problems, evaluates both models, and writes all files above, including this README. | |
Xet Storage Details
- Size:
- 7.12 kB
- Xet hash:
- 111bb3c25c86e86e72d5878a18f33d9a8503b52ece06ac709d43bf7daad1642d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.