Majority Voting For Code Generation

Tim Launer, Jonas Hübotter, Marco Bagatella, Ido Hakimi, Andreas Krause

TL;DR

This paper introduces Functional Majority Voting (FMV), a novel test-time inference strategy for Large Language Models (LLMs) that leverages code execution to find the most reliable code generation. FMV significantly boosts performance on code generation tasks without a substantial increase in computational cost. The authors also demonstrate FMV's utility in a label-free reinforcement learning setting, improving performance on unseen tasks.

What Problem Does This Paper Address?

Large Language Models (LLMs) are increasingly capable of generating code, but they often produce plausible-looking but incorrect solutions (hallucinations). A key challenge in using LLMs for code generation is reliably identifying the correct program from multiple generated candidates, especially when ground-truth labels are unavailable during inference. Existing methods like consensus sampling or test-time reinforcement learning have limitations when applied to code generation due to its unique property: executability. This paper addresses the need for an effective and efficient method to select the best code generation from a set of LLM outputs by leveraging this executability.

Methods

The core contribution is Functional Majority Voting (FMV). This method takes multiple code generations from an LLM for a given prompt and executes them against a set of test inputs. The outputs of these executions form "execution vectors." FMV then identifies a "consensus program" by selecting the candidate program that has the highest pairwise agreement with the execution vectors of all other valid candidates. This "functional consensus" acts as a proxy for ground truth.

FMV is presented in two main ways:

  1. Standalone Test-Time Inference: FMV is used directly to select the best code generation from a pool of candidates, improving accuracy without needing additional training or complex decomposition.
  2. FMV-based Test-Time Reinforcement Learning (TTRL): FMV is extended to act as a pseudo-label generator for TTRL. Instead of relying on a single consensus program, a "synthetic target execution vector" is created by taking the mode of outputs for each test case across all candidates. This synthetic target is then used as a reward signal for training the LLM at test time, enabling it to learn from its own generated outputs without external labels.

Datasets

The primary dataset used for evaluation is LiveCodeBench-v6 (LCB-v6), a benchmark for code generation. The authors use both the full LCB-v6 and randomized subsets for training and evaluation. They also utilize the oracle test inputs provided by the benchmark for execution and evaluation, ensuring that the quality of test case generation does not confound the evaluation of the voting mechanism itself.

Key Insights and Ideas

  • Leveraging Executability is Key: Code's executability is a powerful, underutilized signal for verifying LLM outputs. FMV demonstrates that this signal can be effectively used to achieve a "functional consensus."
  • Soft Consensus for Robustness: Unlike strict consensus methods that require identical outputs, FMV's "soft similarity" awards partial credit for matching on subsets of test cases. This makes it more robust to minor variations in correct solutions.
  • Compute Efficiency: FMV relies on CPU-based execution, which is significantly more efficient than methods requiring additional LLM calls for verification (like some "LLM-as-a-judge" approaches).
  • TTRL as a Pseudo-Labeler: FMV can effectively generate synthetic targets for label-free reinforcement learning, enabling models to improve their zero-shot performance on unseen tasks.
  • No Recursive Self-Improvement: Despite improvements, the paper finds no evidence of models recursively improving beyond their inherent capabilities (i.e., raising the "best@64" ceiling). This suggests that FMV primarily amortizes existing scaling gains rather than unlocking new levels of performance.

Key Results

  • Standalone FMV: FMV consistently outperforms baseline performance and Semantic Voting, achieving performance on par with or better than GenCluster on LCB-v6. For example, accuracy increased from 37.7% to 52.7% with GenCluster and FMV on Qwen3-4B-Thinking-2507.
  • Scaling: FMV shows efficient and consistent improvement with an increasing number of generated samples (rollout budget N).
  • TTRL for Generalization: TTRL with FMV targets improves zero-shot performance on unseen tasks, increasing accuracy from 31.6% to 34.5% on holdout subsets of LCB-v6.
  • Amortization of Gains: While TTRL with FMV raises average performance (mean@64), it does not improve the maximum potential quality (best@64), indicating that the model is amortizing inference-time scaling rather than achieving true self-improvement.

Limitations and Future Work

  • No Self-Improvement Ceiling: The most significant limitation noted is the lack of evidence for recursive self-improvement. The models trained with FMV-TTRL do not seem to surpass their inherent best performance ceiling. The authors attribute this to a "breakdown of the 'Lucky Hit' phenomenon," where incorrect solutions exhibit substantial agreement, leading to false positive rewards.
  • Future Work: The authors suggest further investigation into the "Lucky Hit" phenomenon and how to mitigate it. Exploring how to achieve true self-improvement beyond amortizing existing gains remains an open challenge. Additionally, further research into the theoretical underpinnings of functional consensus and its application in other domains could be fruitful.

Summary updated

BibTeX
@inproceedings{launer2026majority,
  author = {Tim Launer and Jonas Hübotter and Marco Bagatella and Ido Hakimi and Andreas Krause},
  title = {{Majority Voting For Code Generation}},
  booktitle = {TTU Main Track @ ICLR},
  year = {2026},
  url = {https://openreview.net/forum?id=hEnnYgRJdC},
}
Figure