PaT: Planning-after-Trial for Efficient Test-Time Code Generation

Youngsik Yoon, Sungjae Lee, Seockbean Song, Siwei Wang, Wei Chen, Jungseul Ok

TL;DR

Scaling test-time compute for code generation usually relies on expensive planning steps applied indiscriminately to every problem. This paper introduces Planning-after-Trial (PaT), an adaptive policy that only invokes a planner when an initial direct code generation attempt fails verification. By pairing this failure-triggered policy with a heterogeneous model setup (a small model for generation and a large model for planning), PaT cuts inference costs by up to 69% while matching the performance of much larger homogeneous models.

What Problem Does This Paper Address?

Large Language Models (LLMs) are increasingly capable of solving complex programming tasks by scaling "test-time computation"—using methods like iterative repair, tree search, or modular problem decomposition. State-of-the-art code generation frameworks often use a Planning-before-Trial (PbT) approach, which forces the model to explicitly decompose every problem into sub-functions before writing any code.

However, this introduces a massive, flat-rate computational tax. In reality, a large portion of coding workloads consists of relatively simple tasks that an LLM can solve directly in a single shot. Indiscriminately applying heavy planning modules to easy problems wastes tokens, increases latency, and degrades the cost-performance ratio, sometimes making a small model using a planning framework more expensive than a much larger model using standard inference.

Methods

PaT flips the conventional pipeline by introducing a simple, reactive, failure-triggered policy:

  1. Trial Phase: Given a problem, a cost-efficient generator model ($M_G$) first attempts a direct solution using a Best-of-N strategy ($N=5$).
  2. Verification: The generated candidates are executed against a suite of unit tests. If any candidate passes all tests, the pipeline terminates immediately—achieving a cheap, fast success.
  3. Planning Phase: If all initial candidates fail, PaT treats this as a definitive signal that the problem exceeds the generator's direct capabilities. Only then does it invoke a powerful planner model ($M_P$) to break the problem down into smaller subproblems.
  4. Recursive Solving & Composition: The subproblems are solved recursively using the same trial-first policy. Once verified, they are composed back into the main function. If the final composed code fails, a replanning loop triggers, feeding the successful sub-functions back to the planner as context for a refined attempt.
Comparison of Standard, FunCoder, and PaT pipelines

Heterogeneous Model Configuration

Because planning is invoked infrequently, PaT naturally lends itself to a heterogeneous model setup. The authors assign a small, cheap language model (sLM) to handle the high-volume generation trials and a large, capable LLM to act exclusively as the planner. This strategically allocates expensive reasoning compute only where it is strictly necessary.

Handling Noisy Tests

To prevent infinite loops caused by potentially flawed or noisy self-generated test cases, PaT tracks the test pass count across iterations and applies a plateau rule: if performance fails to improve between iterations, the search halts and returns the best-known solution.

Datasets

The authors evaluated PaT across several prominent code generation benchmarks:

  • HumanEval & MBPP: Standard foundational benchmarks for functional correctness.
  • EvalPlus (HumanEval+ & MBPP+): Enhanced versions of the standard benchmarks featuring significantly expanded, rigorous unit test suites to minimize false positives.
  • xCodeEval: A highly challenging, competition-level dataset partitioned into Easy, Mid, Hard, and Expert categories, allowing for a granular look at how the policy behaves across difficulty scales.

Key Insights and Ideas

  • The Workload Difficulty Asymmetry: A small model like Qwen3-4B can already solve roughly 76% of foundational benchmark tasks using standard inference. This means explicit planning is an unnecessary overhead for over three-quarters of typical workloads.
  • Grounded vs. Subjective Complexity: Previous methods relied on the model's own subjective assessment to decide if a problem was too hard. PaT replaces this with a grounded execution signal (test failure), which provides a reliable binary trigger for escalation.
  • Capital-Efficient Upgrading: Upgrading only the planner model in a heterogeneous setup yields massive performance returns for a marginal increase in average cost. This decouples the baseline generation cost from the advanced reasoning cost.

Key Results

  • Advancing the Pareto Frontier: PaT consistently outperforms standard inference, Best-of-N, CodeT, and FunCoder across multiple model families (Qwen3, Llama, DeepSeek), establishing a superior cost-performance frontier.
Cost vs. Performance Pareto Frontier
  • Massive Cost Savings: In the heterogeneous setup, pairing a Qwen3-8B generator with a Qwen3-32B planner achieved an average Pass@1 of 87.39%—less than 1% shy of the fully homogeneous 32B PaT setup—while slashing the relative inference cost to just 31% (a 69% cost reduction).
  • High Return on Investment: PaT achieved an average Compute Return on Investment (ROI) of 1.58, which is 2.4× higher than FunCoder and 4.6× higher than CodeT, proving it makes far more efficient use of additional test-time tokens.
  • Wall-Clock Latency: PaT reduced execution time overhead compared to static planning baselines (incurring a ~3× latency overhead over standard inference, compared to FunCoder's 5× overhead).

Limitations and Future Work

  • Dependence on Test Fidelity: PaT's reactive trigger relies heavily on the quality of the test suite. If self-generated tests contain false positives (accepting buggy code) or false negatives (rejecting correct code), the adaptive escalation can misfire. Incorporating higher-fidelity test generation frameworks is a key area for future integration.
  • Static Memory Footprint: Serving a heterogeneous configuration requires keeping both a small and a large model active in memory simultaneously. While this increases the static hardware footprint, the authors note it aligns well with modern Mixture-of-Experts (MoE) serving infrastructures designed to optimize dynamic inference costs.

Summary updated

BibTeX
@inproceedings{yoon2026pat,
  author = {Youngsik Yoon and Sungjae Lee and Seockbean Song and Siwei Wang and Wei Chen and Jungseul Ok},
  title = {{PaT: Planning-after-Trial for Efficient Test-Time Code Generation}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.1703},
}
Figure