Planning in Natural Language Improves LLM Search for Code Generation

## Abstract

Abstract While scaling training compute has led to remarkable improvements in large language models (LLMs), scaling inference compute has not yet yielded analogous gains.
We hypothesize that a core missing component is a lack of diverse LLM outputs, leading to inefficient search due to models repeatedly sampling highly similar, yet incorrect generations.
We empirically demonstrate that this lack of diversity can be mitigated by searching over candidate plans for solving a problem in natural language.
Based on this insight, we propose PlanSearch ,
a novel search algorithm which shows strong results across HumanEval+, MBPP+, and LiveCodeBench (a contamination-free benchmark for competitive coding). PlanSearch generates a diverse set of observations about the problem and uses these observations to construct plans for solving the problem. By searching over plans in natural language rather than directly over code solutions, PlanSearch explores a significantly more diverse range of potential solutions compared to baseline search methods.
Using PlanSearch on top of Claude 3.5 Sonnet achieves a pass@200 of 77.0% on LiveCodeBench, outperforming both the best pass-rate achieved without any search (pass@1 = 41.4%) and using standard repeated sampling on top of existing non-search models (pass@200 = 60.6%).
Finally, we show that, across all models, search algorithms, and benchmarks analyzed, we can accurately predict performance gains from search as a function of the diversity over generated ideas.
Code can be found at https://github.com/scaleapi/plansearch .

## 1 Introduction

The bitter lesson [] famously posits that two forms of scaling trump everything else: learning and search.
While recent advances in large language models (LLMs) have shown that learning is extremely effective, search has not yet proven its value for LLMs, despite its success with classical machine learning techniques [, , , , , , ].

Here, we refer to search as any method of spending compute at inference time to improve overall performance []. In this work, we focus our efforts on improving LLM search for code generation, one of the most important current applications of LLMs.
We hypothesize the major bottleneck preventing widespread use of search at inference time for code is a lack of high-level diversity in model outputs. This lack of diversity is likely in part due to specific post-training objectives commonly used to train LLMs as chatbots, in which models are oftentimes optimized to produce a single correct answer [, ].
We empirically demonstrate that this is the case for many open-source language models which have undergone significant post-training. Specifically, we show that in many cases, despite instruction tuned models outperforming base models by large margins on a single sample regime (pass@1), this trend disappears—sometimes even reversing—when generating many samples. We refer to Figure 3 as an example of this phenomenon.

Furthermore, the lack of diversity is particularly harmful for search algorithms. In the most egregious of cases with little to no diversity, such as greedy decoding, repeated sampling from the model returns highly similar programs, resulting in minimal gain from additional inference-time compute.
This diversity problem is also not reflected in many public leaderboards (e.g. LMSYS Chatbot Arena [], LiveCodeBench [], OpenLLMLeaderboard []), which often report only the pass rate from a single sample of the model, ignoring an entire dimension along which to compare models.
While the performance of one sample is the primary metric of relevance for applications such as chatbots, as users typically are sensitive to latency, this single scalar is insufficient to fully capture the quality of a model when it is allowed to use more inference-time compute.

Figure: Figure 2: An example trajectory of PlanSearch, which searches over plans in natural language as a method of increasing diversity in the search process. PlanSearch first generates observations, then combinatorially samples subsets of these observations to generate the next step in the search process. To generate the next layer of observations, the combinations derived from the first observations are used as a stepping stone to generate the next observations, and the process repeats. After generating both the first and second order observations, PlanSearch then generates a natural language description of a strategy to solve the problem. For additional diversity, the model is prompted to regenerate its strategy as an additional sample before generating code. See Section 4.3 for additional discussion.
Refer to caption: x2.png

In this paper, we explore several directions for improving the diversity of LLMs at inference time. We hypothesize that the right axis of diversity to search over is the natural language conceptual/idea space, and we validate our hypothesis across several experiments. First, we show that models can produce the correct final program when fed correct solution sketches, where these sketches have been “backtranslated” from passing solution code into sketches in idea space (Section 3.2).
Second, we show that when models are asked to generate their own ideas before implementing them on LiveCodeBench (IdeaSearch), their accuracy conditioned on a particular sketch trends towards either 0% or 100%, suggesting that most of the variance in passing a particular problem is captured by whether the sketch is correct rather than any other factor.
These two experiments suggest a natural method to improving LLM search for code generation: by searching for the correct idea to implement.

Guided by this principle of *maximizing exploration of ideas*, we propose PlanSearch. In contrast to many existing search methods that search over individual tokens [, ], lines of code [], or even entire programs [], PlanSearch searches over possible *plans* for solving the problem at hand, where a plan is defined as a collection of high level observations and sketches helpful to solve a particular problem (Figure 2). To generate novel plans, PlanSearch generates a number of observations about the problem, before combining these observations into a candidate plan for solving the problem. This is done for every possible subset of the generated observations to maximally encourage exploration in idea space, before the codes are eventually all translated into a final code solution (Section 4.3). We find that searching over plans outperforms both standard repeated sampling and directly searching over ideas (IdeaSearch, introduced in Section 4.2) in terms of effectively using compute at inference time.

Applying PlanSearch on top of Claude 3.5 Sonnet achieves a pass@200 of 77.0% on LiveCodeBench, outperforming both the best score achieved without search (pass@1 = 41.4%) and the standard best-of-n sampling score on non-search models (pass@200 = 60.6%). Furthermore, consistent with recent findings on the effectiveness of search on top of small models [, , , ], running PlanSearch on top of a small model (GPT-4o-mini) outperforms larger models not augmented with search after merely 4 attempts. Evaluations of PlanSearch across two other coding benchmarks, HumanEval+ and MBPP+ [], suggest similar improvements.

Finally, we measure the diversity of output code over the idea space of all search methods via an LLM-as-a-judge procedure (Section 6.1) and show that the resulting diversity score is highly correlated with the performance gains generated by that search method. This provides further support for our hypothesis that the effective exploration of plans in idea space is key to LLM search for code generation (Figure 6).

## 2 Related Work

We reiterate that search as defined in the context of our paper refers to any method which expends inference time compute to improve performance. We further specify planning as any form of high level observation or abstract thought that assists a model in generating a final solution.
Our work builds off a long history of work in scaling search and planning.

### 2.1 Search in Classical AI

Classical search algorithms like breadth-first search, depth-first search, and A* search have been widely used for pathfinding, planning, and optimization []. More advanced search techniques like Monte Carlo Tree Search (MCTS) have achieved remarkable success in domains like game playing, enabling superhuman performance in Go [, ], Poker [, ] and Diplomacy [].
More recently, scaling laws have been found for the performance of AI systems in board games, where ELO improves logarithmically with the amount of compute spent at inference [].

### 2.2 Search with Language Models

Applying search on top of LLMs has been a topic of much interest, especially with an eye towards code generation [, ]. Historically, methods such as beam search significantly improved performance for translation systems []. Closer to the present day, several recent works have explored repeated sampling [, , , ] as a search method for improving performance. Repeated sampling is a method which directly generates candidate code solutions from the model many times at moderate to high temperatures in hopes that one of the resulting generations will be correct. However, although these works address the roughly linear increase in pass@k with respect to $\log k$, they only focus on the most basic version of repeated sampling, without searching in idea space.

When combined with a verifier, reward model, or other filtering algorithm to select the best generation (in cases where pass@k is not a viable metric due to lack of test cases), it is also known under the name of best-of-n sampling []. Many works show somewhat good results under intelligent selection of such a filtering algorithm [, ].
Recently, several approaches have demonstrated the power of repeated sampling. For example, repeated sampling from a small model can sometimes outperform taking a single sample from a large model on an equalized compute bases [].
Unlike algorithms such as repeated sampling, which search over the output space, the key insight of PlanSearch is that it is far more effective to instead search plans over the *latent idea space*. By explicitly searching over different natural language plans before generating the code, we significantly increase the diversity of the final code outputs and thus, the resulting pass@k scores for sufficiently large k.

Regarding searching over plans in natural language, several approaches have also proposed generalizing chain-of-thought [] reasoning into a search-like process, such as Tree of Thoughts [] and Reasoning via Planning [].
However, prior methods have largely demonstrated effectiveness on somewhat contrived problems designed to highlight the power of search, such as the game of 24, or classic planning benchmarks such as Blocksworld [], where both benchmarks are easier to solve by explicitly considering many options, and where the ‘steps’ over which to search over are fairly obvious.
By contrast, most real-world planning is used to assist in domains that are complex enough to benefit from, but not require, the additional exploration of plans. We demonstrate that PlanSearch, which plans in natural language, outperforms baseline search methods in one such domain: code generation.
Moreover, our analysis reveals the underlying reason that such search is effective: it increases the diversity of the generated ideas, allowing more efficient search relative to other methods which repeatedly submit highly similar, incorrect solutions. This is consistent with prior work suggesting the importance of diversity in natural language generation [, ]. Other directions for search include decomposing programs down into smaller parts before solving each one individually [, , ].

PlanSearch is also distinct from other methods which explicitly train a model to search or on reasoning traces sampled from the model [, , , ] in that PlanSearch induces diversity at inference-time and converts an LLM API not designed for search into one that is capable of showing strong gains from search. Separately, there is a large family of work in the agent space, in which outputs from terminal commands or other tools are fed back into the model before the agent is queried for the next step [, , , ].

## 3 Motivation

Figure: Figure 3: Despite DeepSeek-Coder-V2-Lite-Base having significantly lower pass@1 than its instruct counterpart, we observe that this trend reverses as $k$ increases, suggesting that the instruct model has less diversity than its base model counterpart. We observe this trend for many, but not all, models and benchmarks, and provide the full data in Appendix I.
Refer to caption: x3.png

Coding is a powerful area in which search should excel. While search in other domains requires both generating many solutions *and* selecting the correct solution amongst all the resulting generations, coding often only requires the former, as any valid piece of code can be tested via code execution against given test cases. This allows code search algorithms to sidestep many of the issues that plague search algorithms for more open-ended domains (e.g. generating poetry) due to difficulty in selecting correct solutions out of all the generated solutions.

Figure: (a) Performance of GPT-4o-mini on LiveCodeBench when provided with backtranslated solutions of varying lengths. The baselines plot performance without backtranslated solutions. Providing the model with a compressed solution in natural language, even as short as 10 tokens, significantly increases performance.
Refer to caption: x4.png

### 3.1 Defining the Search Space

Perhaps the most important question for eliciting strong search capacities is determining which space to search over, as finding the proper layer of abstraction is critical to progress in the field. Prior approaches have varied, with many people searching over individual tokens [, ], lines of code [], or even entire programs [].
We hypothesize that the key factor is obtaining *the correct solution sketch*, which we define as a description of the correct program in natural language space. Intuitively, conducting the reasoning process in natural language space allows us to effectively harness the training process of LLMs, which have observed many human reasoning traces in both pre- and post-training. Prior work [] has observed strong positive effects from being allowed to conduct such reasoning in natural language, making it a natural place to search over. We describe two experiments providing evidence for this hypothesis by testing on the LiveCodeBench benchmark using GPT-4o-mini as our model.

### 3.2 Backtranslation

To investigate the hypothesis whether the idea space, instantiated as solution sketches, is the right area of exploration, a natural question is whether LLMs can correctly implement a correct code solution given a correct sketch. Inspired by approaches to backtranslation in machine learning [, , ], we experiment with “backtranslating” passing code solutions back into idea space.
First, we generate code solutions using GPT-4o to generate $1000$ attempts to solve the problem and filter out problems without any passing solutions.
As we also do not have a dataset of correct solution sketches associated with each solution, we generate a candidate correct idea via backtranslation.
We do this by feeding an LLM both the problem and code solution and asking the LLM to convert said solution into a natural language description of the solution. Additionally, we vary the detail of the backtranslated idea via instructions to the LLM in the prompt (e.g. ‘in $w$ words’). A full description of the prompts can be found in Appendix M.1, alongside several example backtranslated solutions of various lengths.

We observe that prompting a model with a backtranslated idea significantly improves accuracy, increasing with the length of the translated idea (Figure 4(a)), which suggests that having a correct sketch is sufficient to produce the correct final solution with relatively high accuracy, even only after $10$ tokens of backtranslated solution. This suggests that the correct direction of search is to explore through idea space to maximize the chance of arriving at a correct idea.

### 3.3 Conditioning on Idea Quality

In a follow-up experiment, we prompt an LLM to generate its own sketches to solve LiveCodeBench problems instead of providing it with golden ones via backtranslation. First, we generate $5$ ideas per problem using IdeaSearch, defined in Section 4.2. For each idea, we then sample $25$ candidate solutions and measure their pass rate.
For this experiment, we filter out any problem that GPT-4o-mini solves with either a $100\%$ or a $0\%$ solve rate, since such problems are either too easy or too hard for the model and would not be informative for this experiment. We end with $75$ problems and $375$ sketches.

To test our hypothesis that generating a correct sketch is a critical factor for solving problems, we compare the distribution of solve rates for generating correct code solutions *conditioned* on a given sketch to the distribution over solve rates given a sketch drawn at random, i.e., just the distribution over solve rates.

Formally, for a problem $P_{i}$, IdeaSearch samples a sketch $I$ from some conditional distribution with probability mass $P(I|P_{i})$. The probability of solving $P_{i}$ is then $P(\mathrm{solve}|P_{i},I)$. In this experiment, we compare the solve-rate distribution $P(\mathrm{solve}|P_{i},I)$ over all problems and all sketches *versus* the solve-rate distribution of $\sum_{I}P(\mathrm{solve}|P_{i},I)\cdot P(I|P_{i})=P(\mathrm{solve}|P_{i})$ over all problems.

While verifying whether a sketch is correct or incorrect is difficult without access to external labels, a key insight is that if generating the correct idea is a critical factor in solving the problem, then conditioning on a particular sketch should polarize the distribution of solve rates towards $\{0,1\}$. If the model is given a correct sketch, it should consistently generate correct solutions, while if given a bad sketch, it should consistently generate incorrect solutions.

Our results confirm this to be the case. Figure 4(b) shows the distribution of solve rates across problems, both unconditionally (in red) and conditioned on each sketch (in blue). We notice that when grouping by sketches, the solve rates indeed become polarized towards $\{0,1\}$.
This result has important implications for improving code generation, suggesting that a large portion of variance in performance can be explained by whether the model is able to generate a correct idea or not. Therefore, a natural path for improvement is to focus on the sketch generation step and search for correct sketches and observations in idea space before generating solution code.

## 4 Methods

We provide a description of the various methods of search we explore in our work. If additional background on competitive programming and related notation is desired, we provide more (optional) information in Appendix P.

### 4.1 Repeated Sampling

We consider the basic prompting approach as a baseline, in which we use few-shot prompting by providing the LLM with a number of problem-solution pairs before asking it to solve the desired question []. A full example of the prompt is given in Appendix M.2. In code generation, the most common variant of search utilized is repeated sampling, where models are repeatedly sampled from until they generate an output that passes the test or the maximum number of samples is reached. Refer to the Related Work for more information (Section 2.2).

### 4.2 IdeaSearch

A natural extension of the Repeated Sampling approach discussed in Section 4.1 is to avoid prompting the LLM for the solution code immediately.
This can be viewed as an application of the commonly used “chain-of-thought” prompting to programming problems [], although we find that IdeaSearch shows non-negligible performance boosts over standard “chain-of-thought” prompting (see Appendix E).

In IdeaSearch, the LLM is given the problem $P$ and is asked to output a natural language solution $S$ of the problem. Then, a separate instance of the LLM is given $P$ and $S$, and tasked to follow the proposed solution $S$ to solve the problem $P$. The purpose of IdeaSearch is to isolate the effectiveness of having the correct “idea/sketch” for solving the problem. Empirically, we find that explicitly forcing the search algorithm to articulate an idea for solving the problem increases diversity.
See Appendix M.3 for detailed prompts.

### 4.3 PlanSearch

While both Repeated Sampling and IdeaSearch are successful and lead to improvement in the results on benchmark results, we observe that in many of the cases,
prompting multiple times (pass@k) (even at high temperatures) will only lead to small, narrow changes in the output code that change minor aspects but fail to improve upon pitfalls in idea.

Ablations for many of the choices in the subsequent description of PlanSearch can be found in Appendix H.

#### 4.3.1 Prompting for Observations

Starting from the problem statement $P$, we prompt an LLM for “observations”/hints to the problem.

We denote these observations as $O^{1}_{i}$, where, $i\in\{1,\dots,n_{1}\}$ due to the fact that they are first-order observations. Typically, $n_{1}$ is on the order of $3$ to $6$. The exact number depends on the LLM output.
To use these observations to inspire future idea generation, we create all subsets with size at most $S=2$ of $s^{1}=\left\{O^{1}_{1},\dots,O^{1}_{n_{1}}\right\}$. Each of these subsets is a combination of observations, and for clarity we denote each subset as $C^{1}_{i},i\in\{1,\dots,l_{1}\}$, where $l_{1}=1+n_{1}+\binom{n_{1}}{2}$.

#### 4.3.2 Deriving New Observations

The set of all observations can be thus defined as a directed tree with depth $1$, where the root node is $P$, and an edge exists for each $C^{1}_{i}$ pointing from $P$ to $C^{1}_{i}$. We then repeat this procedure from Section 4.3.1 on each leaf node $C^{1}_{i}$ to generate a set of second order observations, $s^{2}_{i}=\{O^{2}_{i,1},\dots,O^{2}_{i,n_{i,2}}\}$. To obtain second order observations, we prompt the model with both the original problem $P$ and all observations contained in $C^{1}_{i}$, framed as primitive observations that are necessary in order to solve $P$. The LLM is then prompted to use/merge the observations found in $C^{1}_{i}$ in order to derive new ones.

The same procedure as Section 4.3.1 is used to create all subsets $C^{2}_{i,j}$, for all $i\in\{1,\dots,l_{1}\}$. This process may be arbitrarily repeated, but we truncate the tree at depth $L=2$ for computational constraints.

Note that there is no assumption any of the observations generated are correct. In fact, it is critical to note that many of them may be incorrect.
The observations merely serve to elicit the model to search over a more diverse set of ideas.

#### 4.3.3 Observations to Code

After the observations have been made, they must be implemented as ideas before being translated into code. For each leaf node, we prompt the model with all observations, along with the original problem $P$, in order to generate a natural language solution to the problem $P$.
To add more diversity, for each generated idea, we generate an additional idea by supposing the idea is wrong, and asking an LLM to give criticisms/feedback, thus increasing our proposed ideas by a factor of $2$.

These natural language solutions are then translated into pseudocode, which are subsequently translated into actual Python code. We take a more granular approach to reduce the translation error (which may cause the model to revert to its original mode, disregarding the reasoned-through observations).
We provide all prompts for all sections in Appendix M.4.

## 5 Experimental Results

**Table 1: LCB, HE+, M+ short for LiveCodeBench, HumanEval+, and MBPP+, respectively. IS short for IdeaSearch and PS short for PlanSearch. We find that PlanSearch and IdeaSearch improve upon search baselines across all models, with PlanSearch achieving the best results across all models and benchmarks considered. Notably, using PlanSearch on top of Claude 3.5 Sonnet [] has a pass@200 of $77.0$ on LiveCodeBench, which is nearly double the performance of the top model without using search ($41.4$). PlanSearch also outperforms basic pass@200 on o1-mini for LiveCodeBench, though since o1-mini already uses inference-time compute, the gap is much smaller than compared to non-search models. The full pass@k curves are included in Appendix A.**
| Model | Eval | Pass@1 | Pass@200 | IS@200 (ours) | PS@200 (ours) |
| --- | --- | --- | --- | --- | --- |
| GPT-4o-mini | LCB | 39.0 | 53.3 | 59.4 | 64.9 |
| GPT-4o | LCB | 41.3 | 60.6 | 70.4 | 73.0 |
| DeepSeek-Coder-V2 | LCB | 41.4 | 53.2 | 65.9 | 70.3 |
| Claude-Sonnet-3.5 | LCB | 40.3 | 55.6 | 70.2 | 77.0 |
| GPT-4o-mini | HE+ | 83.7 | 95.0 | 97.5 | 98.2 |
| GPT-4o | HE+ | 86.4 | 98.2 | 97.6 | 99.5 |
| DeepSeek-Coder-V2 | HE+ | 82.8 | 91.4 | 97.2 | 99.3 |
| Claude-Sonnet-3.5 | HE+ | 81.6 | 88.9 | 95.6 | 98.5 |
| GPT-4o-mini | M+ | 73.5 | 83.8 | 87.3 | 91.0 |
| GPT-4o | M+ | 77.2 | 87.4 | 89.3 | 92.2 |
| DeepSeek-Coder-V2 | M+ | 76.3 | 81.9 | 89.1 | 92.6 |
| Claude-Sonnet-3.5 | M+ | 77.1 | 83.0 | 87.8 | 93.7 |
| o1-mini (search model) | LCB | 69.5 | 90.8 | 91.2 | 91.3 |

Figure: Figure 5: Performance of all models and methods on LiveCodeBench with public test filtering. The purpose of filtering is to shift pass@k curves leftward (i.e., bringing performance high $k$ to low $k$), so we plot curves in detail over $k\in\{1,\dots,20\}$. Dotted lines are provided for reference of the base method pass@k before filtering. Even at 10 completions, PlanSearch outperforms *filtered* Repeated Sampling by a flat 30 to 40%. Again, full pass@k plots are included in their entirety in Appendix A.
Refer to caption: x6.png

### 5.1 Datasets

We evaluate our search methods on three benchmarks: MBPP+, HumanEval+  [], and LiveCodeBench []. MBPP [] and HumanEval [] are some of the most widely used code benchmarks in the field. However, since both benchmarks provide only a few test cases, [] updates both benchmarks with additional test cases that increase the benchmarks’ robustness to reward hacking. LiveCodeBench is a benchmark for coding that consists of competitive programming problems which typically require advanced reasoning capabilities.

Given the reality that coding data is often highly upsampled during pre-training [, ], LiveCodeBench differentiates itself from other benchmarks by taking care to segregate problems by date to avoid data contamination concerns. For this paper, we use only the subset of problems between May 2024 and September 2024 to avoid possibilities of contamination.
We choose May 2024 as the cutoff date to ensure that our results with our best performing model (Claude 3.5 Sonnet) are not due to contamination, because Claude 3.5 Sonnet has a knowledge cutoff of April 2024.
To ensure fair comparison, we use the same cutoff for all models evaluated, even though the precise cutoff dates for other models may vary slightly from May 2024.

### 5.2 Experiment Details

For all search algorithms, we require that all output code be in the correct format specified, and we mark a solution as incorrect if it does not follow the intended formatting. The extracted code is then run through all tests of the program and marked as correct if and only if it passes all tests.

All models are run with temperature $0.9$ and top-$p$ of $0.95$. (o1-mini was run with temperature $1.0$ and top-$p$ of $1.0$ because of API constraints.) Temperature was determined through a coarse hyperparameter sweep on Repeated Sampling and IdeaSearch from $T\in\{0.0,0.1,0.2,\dots,1.2\}$, which we describe in Appendix F.

Both Repeated Sampling and IdeaSearch generate exactly $n$ codes, whereas PlanSearch generates a variable number of codes, usually ranging on the order of 300 to 400. To compute pass@k, we use the unbiased estimator in Equation 4 [](^1^11Note that the estimator in Equation 4 theoretically requires that the number of successes follows a binomial distribution. Repeated Sampling and IdeaSearch obey this, but PlanSearch generations may not be independent. See Appendix O for more discussion.).
If $k>n$, we assume the remaining generations did not pass.
To compute pass@k for filtering, we limit the pool of codes to those that are filtered, meaning that both $n$ and $c$ may shrink in size. This can be thought of as a conditional probability, where the condition is that the code passes public tests. For more information on public test filtering, see Section 5.4.

### 5.3 Results

Our summarized results for Repeated Sampling, IdeaSearch, and PlanSearch can be found in Table 1, Figure 1, and Figure 5. We find that PlanSearch improves over existing methods for all models and benchmarks considered.

Additionally, we plot our full pass@k curves for all methods, models, and datasets in Appendix A.
Due to prohibitively high costs, we only evaluate o1-mini on LiveCodeBench, as HumanEval+ and MBPP+ show strong saturation effects even with weaker models like GPT4o-mini.
The pass@k curves of o1-mini and associated discussion can be found in Appendix K.

For sake of easy comparison, we also plot all relative gains compared to Repeated Sampling@1 averaged over all models in Appendix C. For a compute-normalized comparison between Repeated Sampling and PlanSearch, see Figure 18.
We also ablate over the design choices made for PlanSearch in Appendix H.

### 5.4 Public Test Filtering

Public test filtering is a method which only chooses samples out of the original pool $n$ which pass the public tests.
This is particularly useful in settings such as code deployment where executing the full suite of tests may be computationally costly or otherwise undesirable (e.g. in a coding contest where every incorrect submission is penalized).
Thus, instead of submitting all $n$ codes, after public test filtering, only codes $c_{i}$ would be submitted such that $c_{i}(x_{j})=y_{j}$ for all $j\in\{1,\dots,u\}$, where $c_{i}(x)$ refers to the output from running the code on some input $x$. The primary effect of public test filtering is to shift the pass@k curve leftward, since public test filtering will discard low quality candidate solutions that either fail to compile or fail elementary test cases for the problem.

All problems in MBPP+, HumanEval+, and LiveCodeBench come with a few public tests which are usually used to sanity check any submissions. We can further improve performance by filtering on these public tests before a final submission, as described.
Applying public test filtering reduces the number of samples to achieve the same accuracy by tenfold: PlanSearch to achieve a 77.1% accuracy on LiveCodeBench after just 20 submissions (pass@20) compared to a pass@200 of 77.0% without using public filtering (see Figure 5). We provide full results for the other datasets in Appendix B.

## 6 Analysis

Our results suggest that both PlanSearch and IdeaSearch outperform basic sampling by a wide margin (Figures 12, 13, 14), with PlanSearch achieving the best score across all methods and models considered. Since o1-mini is unique from all other models tested, we show and discuss its unique results in Appendix K.
We show the detailed pass@k results for each dataset in Figures 7, 8 and 9.
We also compare with Chain-of-Thought [] in Appendix E. Interestingly, we find that IdeaSearch performs somewhat better, which we speculate comes from differences in splitting solution sketch into *two* model responses, instead of doing both chain-of-thought and code solution in one model response.

Investigating the differences in specific models, we notice that trends exhibited by the pass@k curves are not uniform across all models; in fact, each curve seems unique.
We hypothesize that these differences are in part due to changes in idea diversity, as investigated in Figures 6, 26, 27. Figure 6 includes o1-mini diversities, which also follow the observed trend. From the figures, we can see that our approximate diversity score accounts for much of the variance we see in the relative improvement that arrives from scaling-up inference-time compute. This correlation holds across all methods and models on the same dataset, thus suggesting that diversity score can be used as a proxy to predict for relative pass@k improvement. For further discussion on the specifics of the diversity score, see Section 6.1.

One interesting point of observation is that PlanSearch often hurts pass@1 for several models, including most notably Sonnet 3.5 on LiveCodeBench, our best performing combination.
Intuitively, this is because increasing the diversity across ideas likely dilutes the probability that any *particular* idea is generated, while simultaneously increasing the chance of having *at least one* correct idea within said pool. Therefore, pass@1 may be slightly lower than usual, yet pass@k will likely surpass “pools” of ideas lacking diversity for this reason. See Figure 41 for a graphical intuition.

Finally, in Table 1 and Figure 1, we present our main results normalized across attempts/completion, where each search method is allowed $k$ attempts to solve each problem. An alternative method of normalizing across methods is to equalize the amount of compute spent on each method. Since PlanSearch and IdeaSearch first plan out an idea before implementing the final solution, they both spend more compute at inference time per solution generated. In Appendix D, we report the equivalent plots normalized across compute. Our findings are highly similar and suggest that PlanSearch outperforms all other methods if sufficient compute is expended at inference time.

### 6.1 Measuring Diversity

Figure: Figure 6: We observe a strong positive correlation between the measured amount of idea diversity (higher score is better) in a search algorithm and the resulting improvements due to search. See Section 6.1 for information regarding the diversity score.
Refer to caption: x7.png

We find that diversity as measured in idea space is highly predictive of search performance, as measured by the relative improvement between a model/method’s pass@1 and its pass@200 (Figure 6).
While entropy is a common diversity measure [], it is oftentimes insufficient for LLM settings [, ]. For instance, consider two different language models, one of which generates minor variations of the same program while another generates a variety of programs with different underlying ideas. Even if both models have the same entropy, the latter model will perform significantly better if augmented with search.

In our setting, we measure diversity in idea space via pairwise comparisons across all generated programs. Let $\{c_{1},\dots,c_{n}\}$ be the pool of $n$ generated codes from a model, each corresponding to some latent idea.
We consider two sketches similar if they are within $\epsilon$ of each other in this latent space, for some choice of $\epsilon$. As such, in this space, $c_{i}$ having a similar idea to $c_{j}$ and similarly for $c_{j}$ and $c_{k}$ *does not imply* $c_{i}$ and $c_{k}$ share a similar idea.

To compute the diversity of such a model, we construct the $\binom{n}{2}$ pairs and evaluate their similarity using an LLM. We define $S(c_{i},c_{j})\in\{0,1\}$, where $S(c_{i},c_{j})=1$ iff $c_{i}$ and $c_{j}$ are similar.
Our overall diversity score for a particular problem is then defined as:

$$ $\displaystyle D=1-\frac{\sum_{i<j}S(c_{i},c_{j})}{\binom{n}{2}}$ (1) $$

A model that produces programs that all implement identical ideas will have a diversity score of $D=0$, whereas one generating codes with all unique ideas have $D=1$. Notably, a method with a score of $D$ is equivalent to the probability that two randomly selected programs from the method are similar to each other, as measured by the LLM. See Appendix Q for more details.

For a particular method, our reported diversity score is simply the diversity score averaged over all problems in the considered dataset.
For large $n$, we sample a subset of $40$ codes and compare all pairs from said subset. To evaluate $S$, we first backtranslate both codes to express each code in natural language before comparing each pair using both the code and its corresponding backtranslated idea.
Full prompt details can be found in Appendix O.1. We use OpenAI’s GPT-4o-mini as the supporting LLM.

## 7 Limitations and Future Work

While PlanSearch substantially improves diversity over idea space at inference-time, fundamentally, improvements in diversity should come at the post-training stage, like with methods such as o1 []. This likely requires re-imagining the post-training pipeline for LLMs around search, instead of the current paradigm optimized for a single correct response.
We are optimistic about future work in designing improved post-training objectives to maximize both quality and diversity, while specifically optimized to use inference-time compute to maximum effectiveness.

PlanSearch and IdeaSearch tradeoff a slight deterioration of pass@1 performance for a large improvement in pass@k performance. However, in many such cases outside of code generation, it is infeasible to run an LLM-based model for more than a few attempts at most. For example, in Figure 9, PlanSearch does not significantly outperform Repeated Sampling until $k\geq 4$.

Fortunately, many filtering algorithms exist, which mitigates this tradeoff by implicitly bringing pass@k (for high $k$) to pass@1 (or lower $k$), i.e. shifting the original pass@k curve leftward. Even the simplest filtering—public test filtering—improves PlanSearch’s pass@1 significantly above Repeated Sampling’s pass@1, which continues as $k$ increases.
Moreover, *most to almost all* base models with public test filtering outperform their instruct model variants at pass@1, no matter the dataset (see Appendix J).
Since base models’ pass@1 is known to be worse than instruct models to trade off for higher diversity, we suggest a new paradigm—developing search algorithms which tradeoff pass@1 performance for much stronger pass@k performance, then filtering the generated solutions to extract the pass@k *back into* pass@1.

With good filtering methods, which we demonstrate can be simple in nature, pass@k, for medium $k$, can be effectively brought down to pass@1, emphasizing a similar paradigm of increasing diversity, then strengthening existing filtering methods, even for domains outside of code generation that are out of scope of this paper.

Finally, a natural extension of this work is training the underlying model itself on successful plans and code solutions obtained from PlanSearch. This has the potential to distill the pass@k into the pass@1—without inference-time methods like filtering—by reducing the likelihood of the model going down unfavorable branches of the search tree.
We believe that such training is likely to significantly improve the model and look forward to future work in this direction.

## 8 Acknowledgements

We would like to thank Jason Wei, Charlie Snell, Miles Turpin, Sail Wang, Horace He, Kenneth Li, Celia Chen, Rahul Chalamala, Alan Wu, Kevin Chang, and Jerry Wei for their helpful comments, suggestions and discussion over the course of this project.

## Appendix A Full Pass@K curves for All Models and All Benchmarks

See Figures 7, 8, 9. We plot all models and methods on HumanEval+, MBPP+ [], and LiveCodeBench [], respectively.

Figure: Figure 7: Pass@k performance of all models and methods on HumanEval+, plotted over $k\in\{1,\dots,200\}$.
Refer to caption: x8.png

Figure: Figure 8: Pass@k performance of all models and methods on MBPP+, plotted over $k\in\{1,\dots,200\}$.
Refer to caption: x9.png

Figure: Figure 9: Pass@k performance of all models and methods on LiveCodeBench, plotted over $k\in\{1,\dots,200\}$.
Refer to caption: x10.png

## Appendix B Full Pass@k Curves with Public Filtering

See Figures 10, 11, 5. We plot all models and methods with public test filtering on HumanEval+, MBPP+ [], and LiveCodeBench [], respectively.

Figure: Figure 10: Pass@k performance of all models and methods on HumanEval+, with public test filtering, plotted over $k\in\{1,\dots,20\}$. Note that dotted lines are provided for reference of the base method pass@k before filtering.
Refer to caption: x11.png

Figure: Figure 11: Pass@k performance of all models and methods on MBPP+, with public test filtering, plotted over $k\in\{1,\dots,20\}$. Note that dotted lines are provided for reference of the base method pass@k before filtering.
Refer to caption: x12.png

## Appendix C Average Relative Improvements

See Figures 12, 13, 14. To create these graphs, the relative improvements of each point on all pass@k curves are computed and compared to the respective pass@1 of Repeated Sampling. Then these values are averaged over all models, so that there is one curve per method per dataset. The datasets are HumanEval+, MBPP+ [], and LiveCodeBench [], respectively. For the public test filtered versions, see Figures 15, 16, 17.

Figure: Figure 12: Performance gain over Repeated Sampling@1 averaged over all models on HumanEval+, plotted over $k\in\{1,\dots,200\}.$
Refer to caption: x13.png

Figure: Figure 13: Performance gain over Repeated Sampling@1 averaged over all models on MBPP+, plotted over $k\in\{1,\dots,200\}.$
Refer to caption: x14.png

Figure: Figure 14: Performance gain over Repeated Sampling@1 averaged over all models on LiveCodeBench, plotted over $k\in\{1,\dots,200\}.$
Refer to caption: x15.png

Figure: Figure 15: Average performance gain over all models of methods with public test filtering compared to Repeated Sampling@1, plotted over $k\in\{1,\dots,20\}$.
Refer to caption: x16.png

Figure: Figure 16: Average performance gain over all models of methods with public test filtering compared to Repeated Sampling@1, plotted over $k\in\{1,\dots,20\}$.
Refer to caption: x17.png

Figure: Figure 17: Average performance gain over all models of methods with public test filtering compared to Repeated Sampling@1, plotted over $k\in\{1,\dots,20\}$.
Refer to caption: x18.png

## Appendix D Compute Normalized Pass@K Graphs

See Figure 18. For each run of a method in Appendix A, we compute the number of generated tokens needed per completion, per problem, independently on each dataset. Then, we average across all datasets to obtain $244$ generated tokens per completion per problem for Repeated Sampling, and $1,428$ generated tokens per completion per problem for PlanSearch.

Figure: Figure 18: Normalized pass@k by average tokens used per problem. Repeated Sampling uses roughly $244$ tokens per completion per problem, and PlanSearch uses roughly $1428$ tokens per completion per problem. When we normalize compute across methods, we find that PlanSearch begins to be more effective than repeated sampling if the user is willing to sample at least 10,000 tokens per problem.
Refer to caption: x19.png

## Appendix E Comparison with Chain-of-Thought

See Figures 19, 20, 21, which are run on LiveCodeBench [], MBPP+, and HumanEval+ [], respectively. These are the same plots as Appendix A, with CoT []. See Figures 22, 23, 24 for the public test filtered versions.

Figure: Figure 19: Pass@k graphs on LiveCodeBench, with the Chain-of-Thought baseline.
Refer to caption: x20.png

Figure: Figure 20: Pass@k graphs on MBPP+, with the Chain-of-Thought baseline.
Refer to caption: x21.png

Figure: Figure 21: Pass@k graphs on HumanEval+, with the Chain-of-Thought baseline.
Refer to caption: x22.png

Figure: Figure 22: Pass@k graphs on LiveCodeBench, with the Chain-of-Thought baseline and public filtering.
Refer to caption: x23.png

Figure: Figure 23: Pass@k graphs on MBPP+, with the Chain-of-Thought baseline and public filtering.
Refer to caption: x24.png

Figure: Figure 24: Pass@k graphs on HumanEval+, with the Chain-of-Thought baseline and public filtering.
Refer to caption: x25.png

## Appendix F Ablation on Temperature for Repeated Sampling and IdeaSearch

See Figure 25. We sweep over temperature increments of $0.1$ from $0.0$ to $1.2$, inclusive, with top-$p$ of $0.95$, on Repeated Sampling and IdeaSearch.

Figure: Figure 25: Sweep over temperature in $0.1$ increments from $0.0$ to $1.2$. Repeated Sampling and IdeaSearch both exhibit pass@k improvements at higher temperature, although it seems that higher temperatures may begin to plateau.
Refer to caption: x26.png

## Appendix G Diversity Score vs Search Improvement Plots for MBPP+ and HumanEval+

See Figures 26, 27, 6. Each figure is made through running the diversity measure as described in Section 6.1 on the generated codes of each run, then compared with the relative gain from pass@k compared to pass@1.

Figure: Figure 26: Relationship between the measured diversity score as described in Section 6.1 (where higher is more diverse) and relative improvement from the pass@1 of the method to the pass@200 of the method.
Refer to caption: x27.png

Figure: Figure 27: Relationship between the measured diversity score as described in Section 6.1 (where higher is more diverse) and relative improvement from the pass@1 of the method to the pass@200 of the method on MBPP+.
Refer to caption: x28.png

## Appendix H Ablations

We run ablations on the core parts of PlanSearch, using GPT-4o-mini on LiveCodeBench []. On the diverse observation generation side, we first verify our choice of $S=2$—the maximum subset size to sample from out of a given pool of observations—and also compare performance across varying the number of observation layers used (Figures 28, 29).
On the implementation side, we compare different sections of the proposed pipeline (see Figure 2) to translate combinations of observations to code in Figure 30. We compare each method’s pass@k from $k=1$ to $k=200$.

Figure: Figure 28: We run ablations of PlanSearch with different $S$—controlling the maximum subset size from a given pool of observations. There is not a large difference between different $S$, but we find that $1$ or $2$ is slightly more optimal, although if more completions are desired, $S$ can be increased to $3$ as well.
Refer to caption: x29.png

The effect $S$, the maximum observation subset size to build upon, has on performance is not overly significant; there are small degradations as $S$ is increased to $3$, but not noticeable. We choose $S=2$ to obtain more code completions. See Figure 28.

Figure: Figure 29: We run ablations of PlanSearch with different $L$—controlling the maximum order of observation used, i.e., how many layers the observation tree will search. We find pass@k scales with respect to increasing $L$
Refer to caption: x30.png

Increasing $L$, the maximum number of layers of the observation tree, increases pass@k at large enough $k$ (above $50$). We choose $L=2$ to strike a balance between extracting a large pass@k gain while keeping compute costs reasonable. See Figure 29.

Figure: Figure 30: We run ablations of PlanSearch with different methods of translating a combination of observations to code.
Refer to caption: x31.png

From Figure 30, we see that our overall translation step adds minor pass@k gains. We deconstruct the translation step into parts: the pseudocode step, the fix step (i.e., asking the model to fix its proposed solution sketch), and creating the solution sketch at all (which includes the fix step).

- •
“No solution sketch, no pseudocode” implies using a given observation combination to directly prompt for the solution code.
- •
“No pseudocode” implies skipping the pseudocode step. In other words, given a solution sketch, the sketch is directly translated into code.
- •
“No fix step, no pseudocode” implies the fix step is skipped, as well as the pseudocode. In order to have the same number of completions, the whole PlanSearch pipeline is run twice.

## Appendix I Base Models vs. Instruct Models for Large Samples

We find that base models, despite performing poorly relative to their instruct counterparts for evaluated with pass@1, will frequently match or even exceed performance on pass@k for sufficiently high $k$. This is likely due to higher amounts of diversity in base models, which have not undergone post-training designed to elicit a single strong response from the model.

We see this effect across all models for HumanEval+ and MBPP+, but only the DeepSeek-Coder-V2 family for LiveCodeBench.

See Figure 31 for all base and instruct model comparisons between DeepSeek-Coder-V2-Lite, Llama-3.1-8B, and Llama-3.1-70B on all three datasets.

We also provide Llama-3.1-8b and DeepSeek-Coder-V2-Lite pass@k comparisons for $k$ up to $10,000$; see Figures 33, 32.

Figure: Figure 31: Pass@k curves comparing DeepSeek-Coder-V2-Lite, Llama-3.1-8B, and Llama-3.1-70B base and instruct performance.
Refer to caption: x32.png

Figure: Figure 32: Pass@k curves comparing DeepSeek-Coder-V2-Lite’s base and instruct versions on LiveCodeBench with up to $10,000$ completions.
Refer to caption: x33.png

Figure: Figure 33: Pass@k curves comparing Llama-3.1-8B’s base and instruct versions on LiveCodeBench with up to $10,000$ completions.
Refer to caption: x34.png

## Appendix J Base Models vs. Instruct Models with Public Test Filtering

We repeat the graphs from Appendix I, but with public test filtering. We find that base models with public test filtering almost always exceed the pass@1 of their instruct model variants.

See Figure 34 for all base and instruct model comparisons between DeepSeek-Coder-V2-Lite, Llama-3.1-8B, and Llama-3.1-70B on all three datasets with public test filtering.

We also report Llama-3.1-8b and DeepSeek-Coder-V2-Lite pass@k comparisons with public test filtering for $k$ up to $10,000$; see Figures 35, 36.

Figure: Figure 34: Pass@k curves comparing DeepSeek-Coder-V2-Lite, Llama-3.1-8B, and Llama-3.1-70B base and instruct performance with public test filtering.
Refer to caption: x35.png

Figure: Figure 35: Pass@k curves comparing Llama-3.1-8B’s base and instruct versions on LiveCodeBench with up to $1,000$ completions and with public test filtering.
Refer to caption: x36.png

Figure: Figure 36: Pass@k curves comparing DeepSeek-Coder-V2-Lite’s base and instruct versions on LiveCodeBench with up to $1,000$ completions and with public test filtering.
Refer to caption: x37.png

## Appendix K OpenAI O1

We also do a brief analysis of OpenAI’s o1 [] models. We run PlanSearch on top of o1-mini, which is the best o1 model available through API access at the time of writing for competitive coding. Due to both severe cost constraints and dataset saturation on HumanEval+ and MBPP+, we only run o1-mini on LiveCodeBench [].

First, we investigate its pass@k trends on LiveCodeBench. (See Figure 37.) As expected, PlanSearch trails Repeated Sampling for low $k$. However, at high $k$, PlanSearch competes with/slightly outperforms Repeated Sampling.

We believe there to be two reasons why there is not as large of an improvement compared to other non-search-based models. First, there may be diminishing returns when stacking multiple search methods on top of each other naïvely. Second, LiveCodeBench is noticeably saturated, reaching solve-rates of over $90\%$. Thus, it is much harder to notice large jumps in dataset performance, as can be seen in pass@k curves (see Figure 7) on HumanEval+ []. There, Repeated Sampling, IdeaSearch, and PlanSearch all perform roughly the same, with PlanSearch only slightly outperforming the others. We believe a combination of these effects also implies a greater $k$ is required to notice a large difference between Repeated Sampling and PlanSearch.

Figure: Figure 37: Pass@k performance methods applied on top of o1-mini, on LiveCodeBench, plotted over $k\in\{1,\dots,200\}$. PlanSearch slightly outperforms Repeated Sampling at high $k$; larger $k$ is not run due to cost constraints.
Refer to caption: x38.png

We notice that the OpenAI frequently refuses to answer queries from PlanSearch, likely due to efforts to minimize revealing the full chain-of-thought the model is using. To combat this, we find that filtering out the words steps, step, and quote reduces the fraction of unanswered queries from roughly $40\%$ to less than $0.5\%$. For any query that is still refused after this approach, we route the same prompt to GPT-4o. In addition, we remove the pseudocode step to reduce the amount of flagged responses.

On the diversity end, we apply the same methodology as described in Section 6.1. The corresponding plot can be found in Figure 6. Even though o1-mini is strong on its own, we find that it is not very diverse, which is consistent with our claim that diversity correlates with relative performance gain seen with increasing $k$.

## Appendix L Bar Charts

See Figures 38, 39, 1. These plot pass@1 and pass@200 of select methods between Repeated Sampling and PlanSearch, on datasets MBPP+, HumanEval+ [], and LiveCodeBench [].

Figure: Figure 38: Bar chart with Repeated Sampling@1, Repeated Sampling@200, and PlanSearch@200, on MBPP+.
Refer to caption: x39.png

Figure: Figure 39: Bar chart with Repeated Sampling@1, Repeated Sampling@200, and PlanSearch@200, on HumanEval+.
Refer to caption: x40.png

## Appendix M Prompts

### M.1 Backtranslation

#### M.1.1 Backtranslate System Prompt

You are an expert Python programmer. You will be given an algorithmic question (problem specification). You will return a high-level, natural language solution to the question, like an editorial. You will NOT return any code. Be as creative as possible, going beyond what you think is intuitively correct.

#### M.1.2 Implement Backtranslation Idea

You are an expert Python programmer. You will be given a question (problem specification) and a natural language solution/tutorial that describes how to solve the problem. You will generate a correct Python program that matches said specification and tutorial and passes all tests. You will NOT return anything except for the program inside markdown codeblocks.

### M.2 Repeated Sampling

You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests. You will NOT return anything except for the program inside Markdown codeblocks.

### M.3 Simple Idea

You will given a competitive programming problem; please output a high-level description of how to solve the problem in natural language. Below are examples:
Example input: PROBLEM DESCRIPTION HERE
Example output: EXAMPLE OUTPUT HERE
Here is the competitive programming problem: PROBLEM TO SOLVE
Brainstorm a high-level, natural language solution to the problem above. Note that your intuition may lead you astray, so come up with simple, creative ideas that go beyond what you would usually come up with and go beyond your narrow intuition. Brainstorming solutions that do not seem intuitively correct IS CRUCIAL.

### M.4 PlanSearch

#### M.4.1 Prompt for Observation Part 1

You are an expert Python programmer. You will be given an competitive programming question (problem specification). You will return several useful, non-obvious, and correct observations about the problem, like hints to solve the problem. You will NOT return any code. Be as creative as possible, going beyond what you think is intuitively correct.

#### M.4.2 Prompt for Observation Part 2

You are an expert Python programmer. You will be given an competitive programming question (problem specification) and several correct observations about the problem.
You will brainstorm several new, useful, and correct observations about the problem, derived from the given observations. You will NOT return any code. Be as creative as possible, going beyond what you think is intuitively correct.

#### M.4.3 Combining Observations

Here is a sample prompt from the function with placeholders:
Here is the competitive programming problem:
Problem statement placeholder
Here are the intelligent observations to help solve the problem:
Observation 1 placeholder
Observation 2 placeholder
Observation 3 placeholder
Use these observations above to brainstorm a natural language solution to the problem above.
Note that your intuition may lead you astray, so come up with simple, creative ideas that go beyond what you would usually come up with and exceeds your narrow intuition.
Quote relevant parts of the observations EXACTLY before each step of the solution.
QUOTING IS CRUCIAL.

## Appendix N A Model of Repeated Sampling: Pass@k

Consider a simplified model of repeated sampling for code generation.
Suppose we have a dataset $D=\{P_{1},\dots,P_{l}\}$ with $l$ problems.
For some problem $P_{i}$, define the probability $p_{i}$ as the probability that our code generation model solves the problem $P_{i}$ in one submission.
The pass@k [, ] metric (for problem $P_{i}$) is defined as the probability that our code generation model solves the problem $P_{i}$ at least once out of $k$ submissions.
Thus, if we know the true $p_{i}$ of our model, we may compute our pass@k simply:

$$ $\displaystyle\mathrm{pass@k}_{i}$ $\displaystyle=1-(1-p_{i})^{k}$ (2) $\displaystyle\mathrm{pass@k}$ $\displaystyle=\sum_{i}\mathrm{pass@k}_{i}/l$ (3) $$

However, it turns out that for $k>1$, the naïve estimator as seen in Equation 2 is biased, if we sample $n_{i}\geq k$ from our code model to solve $P_{i}$, $c_{i}\leq n_{i}$ are correct, and compute $p_{i}=c_{i}/n_{i}$ [].
Instead, $\mathrm{pass@k}_{i}$ is typically computed using the unbiased estimator:

$$ $\displaystyle\mathrm{pass@k}_{i}$ $\displaystyle=1-\frac{\binom{n-c}{k}}{\binom{n}{k}}$ (4) $$

Note that reporting pass@k on a dataset where $l=1$ is rather pointless, since pass@k can be derived using only $\mathrm{pass@1}_{1}$ and $n_{1}$. Every curve, over a suitable range of $k$ values, will look like the *S-curve* seen in Figure 40 (as $k$ is plotted on a $\log$ scale).

Figure: Figure 40: A simple pass@k ‘*S-curve*’ plotted with $1-(1-p)^{k}$, where $p=0.04$.
Refer to caption: x41.png

However, with datasets where $l>1$, models are able to differentiate themselves through larger $k$, since the overall pass@k is an average of these $l$ curves. For example, for $l=3$, it is less optimal to have solved probabilities of $\mathrm{Set1}=\{0.001,0.7,0.9\}$ versus $\mathrm{Set2}=\{0.05,0.1,0.25\}$, in the regime of roughly $k=20$ to $k=2,000$ (in which both converge to $1$), even though $\mathrm{Set1}$ has a pass@1 of $53\%$ and $\mathrm{Set2}$ has a pass@1 of $13\%$. See Figure 41.

Although not shown in the graph, $\mathrm{Set2}$ converges close to $1$ at roughly $k=400$, several orders of magnitude below $\mathrm{Set1}$. In addition, note that the slight notch seen in $\mathrm{Set1}$’s curve at large $k$ is due to the presence of low, but non-zero solve-rates, which can be seen in empirical pass@k curves later on. (These can be thought as the beginning of the ‘ramping-up’ regime of the typical *S-curves* in Figure 40.)

Figure: Figure 41: Two pass@k curves on a hypothetical dataset of length $l=3$, and the solve probabilities of Set 1 are $\{0.001,0.7,0.9\}$ and Set 2 are $\{0.05,0.1,0.25\}$. Note that the pass@1 is $53\%$ and $13\%$, respectively. However, at roughly $k=20$, Set 2 surpasses Set 1 and within an order of magnitude, achieves pass@k of roughly $1.0$.
Refer to caption: x42.png

## Appendix O Biased Estimator for Pass@K Due to Non-Independence of PlanSearch

From a pure theoretical standpoint, the expression is biased (if using the same interpretation), but it still leads to a similar interpretation—computing the probability that a subset of size $k$ drawn from the set of samples we already generated contains at least one success. (These given samples were generated by one run of PlanSearch.) As such, in theory, the estimator may be slightly biased in the PlanSearch case when computing its true pass@k. In practice, we do not believe this to be a large concern, especially as our primary results feature a relatively large $k=200$.

### O.1 Measuring Diversity

You are an expert Python programmer. You will be given a competitive programming problem and two pieces of code which are attempts to solve the problem. For your convenience, you will also be given the idea for each code, summarized in natural language. You will be asked to answer whether the ideas behind the code are the same. You must ONLY output ’Yes.’ or ’No.’

## Appendix P Competitive Programming

Competitive programming is a popular subset of programming tasks that involve solving complex algorithmic reasoning. Typically, problems consist of a problem statement (written in natural language) $P$, with associated tests: $(x_{i},y_{i}),i\in\{1,\dots,m\}$, for which any solution must pass all of them.

The number of tests $m$ depends on the problem, but typically ranges on the order of $25$ to $100$. A small subset of the tests are typically given to the solver (we call these public tests) to use as validation that their program passes simple cases. The rest of the tests are hidden. Solutions to the problems must generally pass all the tests to be considered correct. Formally, we let $f(x)$ denote the output of said code ran on input $x$. The solution code is considered correct (passing) if and only if $f(x_{i})=y_{i}$ for all $i\in\{1,\dots,m\}$.

Each dataset consists of many (on the order of low-hundreds) independent problems, and models are evaluated on each of these problems independently.

## Appendix Q Mathematics and Examples of the Diversity Measure

While our choice of a diversity metric is intuitive, one should note that there are a number of intriguing details that result from our definition.

For example, *it is* the case that with $k$ unique ideas and $n$ samples of each idea, respectively (for a total of $kn$ total generated codes), we achieve a diversity score approaching $(k-1)/k$.

For a quick proof, suppose that there are $k$ cliques, each of $n$ size. Each clique represents a unique idea. We wish to capture the number of unfilled edges over the number of possible edges as our diversity score:

$$ $\displaystyle\frac{\binom{k}{2}n^{2}}{\binom{kn}{2}}=\frac{(k-1)n}{kn-1}$ (5) $$

which converges to $\frac{k-1}{k}$ as $n$ grows large.

Our formulation seems more intuitive than other proposals, such as one that simply counts how many unique ideas $k$ lie within a pool of size $n$ to compute $k/n$ as the diversity score.

For instance, suppose there are only two unique ideas, one clique of which is of size $2n-1$, and the other only output once. The simple proposal would compute both the diversity score of this uneven group *and* that of an even group (where both ideas are output $n$ times) to be $\frac{2}{2n}=\frac{1}{n}$.

However, our score would compute the even group to be $\frac{n}{2n-1}$, and the uneven group as:

$$ $\displaystyle\frac{1}{2n}\cdot 1+\frac{2n-1}{2n}\cdot\frac{1}{2n-1}=\frac{1}{n}$ (6) $$

Instead of counting edges, we compute the probability that two randomly selected outputs have similar idea to each other, which is another interpretation of our diversity score.

It seems clear that a case with $2n-1$ instances of idea 1 and $1$ instance of idea 2 is ‘less diverse’ than a case with $n$ instances of both idea 1 and idea 2. A naïve proposal may score these two as being the same diversity, whereas our score scores them as $1/n$ and roughly $1/2$, respectively.

## Appendix R Additional Directions for Future Work

In terms of methodological improvements to PlanSearch, PlanSearch currently searches all leaf nodes in the search tree uniformly. Because of this, it becomes quickly intractable to go further than a couple levels deep, and in our experiments, we are only able to go two levels down the tree. Several approaches based on Monte-Carlo Tree Search (MCTS), such as Tree of Thought [] or Reasoning as Planning [], have suggested that some form of dynamic pruning and expansion of nodes can be very helpful. We are optimistic that PlanSearch can be further improved by such methods.

Furthermore, PlanSearch is a fairly elementary method taking advantage of the paradigm that searching over a *conceptual or idea space* is an effective method to improve diversity, and thus, downstream task performance. It is completely feasible to search at an even higher level of abstraction than observations, which may be used to inject even more diversity into the final generated outputs.

## Peer Reviews

confidence: 3
contribution: 4
initial_rating: 10
presentation: 4
questions: - > Interestingly, we find that IDEASEARCH performs somewhat better, which we speculate comes from differences in splitting solution sketch into two model responses, instead of doing both chain-of-thought and code solution in one model response.

  This is surprising. Is the only difference here that a new model response comes as a new "message" in the chat LLM API?
soundness: 4
strengths: There were a great many things I liked about this paper, and I learned a lot from its experiments.
- Figure 1 is very compelling and sells the main takeaway immediately: Searching over *ideas* in natural language (PlanSearch) is a significantly more effective way to spend inference-time compute than naive repeated sampling of direct solutions.
- The broad strategy of "generate plan first then generate the solution based on that" is highly applicable to other domains; PlanSearch can be used to generate plans for anything, and could plausibly improve performance across many domains besides code generation.
- Useful takeaway that performance can be seen as a function of diversity of ideas. This is an important lesson for the field which is not currently prioritizing LLMs' diversity of ideas, but should take idea diversity more seriously given this evidence.
- Interesting to see that instruction-tuned models can sacrifice the diversity of ideas present in base models, Figure 30 is a great figure illustrating this effect! This line was quite surprising to me:
  > in many cases, despite instruction tuned models outperforming base models by large margins on a single sample regime (pass@1), this trend disappears—sometimes even reversing—on a multi-sample regime (pass@k). We refer to Figure 30 as an example of this phenomenon

  and this further line in the Conclusion is clear-sighted in pointing out the implication of the problem of losing diversity during post-training:
  > while PLANSEARCH substantially improves diversity over idea space at inference-time, fundamentally, improvements in diversity should also come at the post-training stage
- Section 3 builds a great foundation to motivate why we care about searching over idea sketches: Starts by considering the correct layer of abstraction to search over, run experiments showing the power of the right "idea sketch". Figure 3a and 3b are great.
- Interesting to see that o1-mini, a model which itself already scales inference-time compute, benefits less from this method (which makes sense, but good to know).
- Impressive thoroughness in sharing results, with >40 figures throughout the paper and appendices!

Overall, the paper is very well-written, adds new insights to an emerging topic (diversity and search) with important ramifications for the field, and is very thorough with well-designed experiments, with many interesting results.
summary: This paper investigates the effect of inference-time search in LLMs applied to contemporary coding benchmarks. The investigations start by asking about the appropriate level of abstraction at which to perform search, and identifies "natural language plans" as a useful level through clear experimentation. They introduce a new inference-time search algorithm for LLMs in code generation called "PlanSearch". The algorithm appears general enough to be applied to other domains, though the paper does not pursue this. In the main experiments, the authors find that PlanSearch improves LLM performance on coding benchmarks significantly, and by a large margin compared to standard inference-scaling methods (RepeatedSampling). Further experiments identify "idea diversity" as the key driving factor for PlanSearch's success, with their custom measures of idea diversity being predictive of downstream performance. The authors further discover that instruction-finetuned models can have less diverse ideas than base model variants, raising important questions around the best way to perform LLM post-training.
weaknesses: Few complaints overall. One minor weakness that doesn't cut against the broader claims and lessons of the paper:
- The actual search algorithm of PlanSearch in Section 4.3 feels somewhat arbitrary. If the goal is simply to generate diverse plans, I suspect there will be many other different ways to prompt LLMs to generate diverse ideas besides the specific PlanSearch algorithm as described. Did the authors try other algorithms / prompts? Would have been nice to see the failure cases and understand why this specific design was selected.
  - Ablations in Appendix H address this complaint somewhat, but still assumes the same algorithm structure and is mostly just a "hyperparameter search" which has small effect on the results.
  - To give a concrete example of what I imagine could be a completely different approach: directly prompting models with previously sampled ideas, and asking models to generate different plans.

---

confidence: 3
contribution: 2
initial_rating: 5
presentation: 3
questions: See weaknesses
soundness: 3
strengths: 1. The authors achieve impressive results on three benchmarks, e.g. they make Claude 3.5 Sonnet achieves a pass@200 of 77.0% on LiveCodeBench.
2. They provide an interesting motivation for their work: showing that idea generation, not idea execution is the bottleneck of LLMs and they the solutions they generate lack diversity. It's interesting that "a correct sketch is sufficient to produce the correct final solution with relatively high accuracy, even only after 10 tokens of backtranslated solution." and that conditioning on a correct idea or bad idea polarizes the score distribution that much.
3. They provide and elaborate scaffolding for generating solutions.
4. The conducted experiments are sound. I like showing scaling of pass@k as a function of k. I like that all frontier models as well as open-weight models were used in experiments.
5. Results are complemented with an interesting analysis of the role of diversity (Fig. 5)
6. The paper is clearly written
summary: The authors describe a new method for code generation (for short problems). It involves generating a set of observations about the problem (in natural language), constructing plans to solve it and then generating solutions.
weaknesses: 1. The authors do not compare with several important baselines, e.g. iterative methods such as ReAct, Reflexion and agentic approaches (e.g. AgentCoder). I thinks that a bit weakness: there are relatively simple methods and scale well to more complex tasks (e.g. SWE-Bench).
2. I don't think it's that surprising or impressive that burning more test-time compute [1, 2, 3] leads to better results. A fair comparison would involve, e.g. a scatter plot of pass@200 on X axis and compute spent on Y axis. Compute spent can be operationalized as either tokens or dollars spent (ideally you'd report both). Then, the question is: is your method strictly optimal? Is it Pareto-optimal? See [1, 2, 3] for a discussion.

More specific points:
3. I think the opening sentence of the abstract is false as of November 2024: "While scaling training compute has led to remarkable improvements in large language models (LLMs), scaling inference compute has not yet yielded analogous gains". See again [1, 2, 3]. 
4. I don't understand this sentence: "LLMs as chatbots, in which models are oftentimes optimized to produce a single correct answer (Rafailov et al., 2024; Ouyang et al., 2022)." RL optimizes for reward (which could be correctness) and DPO optimizes a contrastive loss (e..g. preferring correct responses over incorrect ones). Neither optimizes for a single correct answer. This could be the case for supervised fine-tuning though.


[1] Large Language Monkeys: Scaling Inference Compute with Repeated Sampling
[2] An empirical analysis of compute-optimal inference for problem-solving with language models
[3] OpenAI O1 system card
[4] AI Agents That Matter

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 3
questions: Please refer to the weakness.
soundness: 3
strengths: The paper is well-written. Analysis and ideas are presented progressively, making it easier to follow. The proposed method is well-motivated by the polarized results of different solution sketches. The experiment results also show clear improvement over the baseline model and methods.
summary: The paper proposes a new methodology to improve language model test time scaling efficiency. Their study shows that simply sampling more outputs from the same input prompt will have limited diversity, thus limiting the improvement of the model performance. To avoid this issue, they propose to sample the natural language plan of the solution first and then ask the language model to generate a solution based on the plan. They propose an effective method for sampling various plans, and experiments show that the proposed method improved the model accuracy in best-of-n settings.
weaknesses: 1. Although the method shows promising results with models including Claude 3.5 sonnet and GPT-4o, etc., the improvement over o1-mini is marginal. Does this suggest the method is not compatible with other inference-time scaling compute?
2. While the proposed method shows promising improvement compared to naive sampling and Pass@1, how does it compare to another search-based method, like MCTS?

Meta-review: The paper introduces PLANSEARCH, a novel search algorithm that enhances code generation by leveraging natural language planning. The authors identify a lack of diversity in large language model (LLM) outputs during inference, leading to inefficient search processes. To address this, PLANSEARCH generates diverse observations about a problem and constructs natural language plans before producing code solutions. The authors reported strong empirical results across benchmarks like HumanEval+, MBPP+, and LiveCodeBench. There is some minor feedback, including the discussion of test-time compute cost and the comparison with self-improve baselines and agentic methods. The authors should try to incorporate the feedback into the final paper.

Decision: Accept (Spotlight)