Example

Spend a token budget and watch accuracy saturate

Run three tasks at three synthetic thinking budgets and separate the accuracy gain from the cost that keeps rising.

A reasoning model can spend more tokens before its final answer. That extra compute may improve accuracy on hard tasks, but it is not free: latency and cost grow with the budget. A useful experiment reports the accuracy curve and the cost curve together, and marks where additional budget stops helping.

This example uses a synthetic solver: a task is solved when the budget is at least the task string’s length, latency is the budget, and cost is the budget times 0.001. It is not a reasoning model and not a provider measurement. It is an accounting fixture for the trade-off. With budgets 2, 5 and 10, accuracy is 5/9 and total cost proxy is 0.051; the hard task needs 10, while the easy tasks saturate earlier.

Run it

From the canonical repository at commit f958967d70992d7b09d9c75000bd8c543f1644d4:

python examples/ch33/reasoning.py --json

Python 3.11 or later, standard library only. No model, network, provider API or credentials. It finishes immediately.

Implementation

The solver is deterministic: difficulty is the task string length, and solved = budget >= difficulty. Latency and cost are simple functions of the budget. There is no hidden chain of thought and no model call.

def solve_task(task: str, budget: int) -> TaskResult:
    # Synthetic: more budget increases chance of solving; deterministic.
    difficulty = len(task)
    solved = budget >= difficulty
    return TaskResult(
        task=task,
        budget=budget,
        solved=solved,
        latency_proxy=float(budget),
        cost_proxy=float(budget) * 0.001,
        metadata={"difficulty": difficulty},
    )


def run_benchmark(tasks: List[str], budgets: List[int]) -> dict:
    results = []
    for task in tasks:
        for budget in budgets:
            results.append(solve_task(task, budget).to_dict())
    solved = sum(1 for r in results if r["solved"])
    return {
        "results": results,
        "accuracy": solved / len(results) if results else 0.0,
        "total_cost": sum(r["cost_proxy"] for r in results),
    }

Expected outcome

Observed with the command above (exit 0). The summary fields were:

  "accuracy": 0.5555555555555556,
  "total_cost": 0.051000000000000004

The nine combinations produced this pattern:

Task Difficulty Budget 2 Budget 5 Budget 10
2+2 3 failed solved solved
12*7 4 failed solved solved
sqrt(144) 9 failed failed solved

Five of nine runs solved. The hard task needed the largest budget; the easy tasks gained nothing from 10 over 5. Total cost proxy rose with every budget increase, including the increases that produced no new success.

Mechanism and limitations

Documented: solve_task compares the budget with the task length, reports a latency proxy equal to the budget and a cost proxy of budget * 0.001. run_benchmark evaluates every task at every budget and reports accuracy and total cost. The tests check a solved case, an insufficient budget, the demo, JSON serialisation and non-negative cost.

Observed: the command exited 0 with accuracy 0.5555555555555556 and total cost 0.051000000000000004, and the per-task pattern above. The targeted tests.test_ch33_reasoning is part of the canonical suite; no independent test count is claimed here.

Not shown: a real reasoning model, hidden reasoning tokens, provider billing, accuracy on a meaningful benchmark, or latency. The “difficulty” is string length, which is not a measure of reasoning difficulty. The cost proxy is a fictional constant. The page therefore demonstrates budget accounting, not the value of inference-time compute.

Challenge this result

Add a budget of 20 and rerun. Accuracy should not change, but total cost should rise. Compute the marginal cost per additional solved task between budgets 5 and 10, then between 10 and 20. Explain why a service might cap a budget even when a larger budget could solve more tasks, and what measurement would be needed to choose the cap for a real model.

Source and verification

Canonical source: examples/ch33/reasoning.py at commit f958967d70992d7b09d9c75000bd8c543f1644d4. Tests: tests/test_ch33_reasoning.py . Chapter: Reasoning Models and Inference-Time Compute . The run above is a fresh local execution on Windows 11 with Python 3.13.15; it uses a synthetic solver, not a reasoning model.

Understand this example

Copy this prompt into your AI tool. No code runs here.

Apply this example

Copy this prompt into your AI tool. No code runs here.