AuPair: Golden Example Pairs for Code Repair

Aditi Mavalankar, Hassan Mansoor, Zita Marinho, Masha Samsikova, Tom Schaul · DOI

Introduction

Large Language Models (LLMs) have demonstrated remarkable proficiency in code generation, yet they frequently produce "flawed guesses"—solutions that are logically sound in most cases but fail on specific edge cases or complex constraints. Current mitigation strategies, such as Best-of-N sampling or iterative self-repair, often encounter performance plateaus or feedback loops where the model repeats its errors.

This paper introduces AuPair, a novel algorithm designed to enhance LLM code-repair capabilities through In-Context Learning (ICL). Instead of merely asking a model to "fix" code, AuPair provides curated "golden example pairs" consisting of a problem description, a flawed initial guess, and a verified correction. This approach teaches the model the transformation logic required to move from a near-miss to a correct solution.

Methodology

The AuPair framework operates in two distinct phases:

  1. Candidate Pair Generation: A large library of potential pairs is generated by sampling problems from a training set. For each problem, the model generates multiple fixes. Pairs are retained only if the fix demonstrates improved performance on unit tests compared to the original flawed guess.
  2. Submodular AuPair Extraction: To select the most effective examples, the researchers employ a submodular selection algorithm. Rather than selecting the "best" individual pairs, the algorithm greedily picks pairs that are complementary. A pair is selected if it helps solve validation problems that previously selected pairs could not. This ensures the final set of AuPairs covers a diverse spectrum of bug types, from syntax errors to deep logic flaws.

At inference time, the top $N$ selected AuPairs are provided as 1-shot examples across $N$ independent LLM calls to guide the repair process.

Experimental Results

The authors evaluated AuPair across seven competitive programming datasets (including CodeForces and AtCoder) using five state-of-the-art models such as Gemini-1.5-Pro and GPT-4o-mini.

Performance comparison of AuPair against baselines across multiple models on CodeForces and AtCoder.

Performance and Scaling

AuPair consistently outperforms standard sampling and self-repair baselines. On CodeForces, Gemini-1.5-Pro achieved a 51.32% pass rate at 144 calls, a significant jump from the ~16% observed with traditional methods. Crucially, AuPair exhibits superior scaling properties; while other methods plateau, AuPair shows log-linear improvement as the computational budget (number of LLM calls) increases.

Scaling and efficiency: AuPairs vs. Random Pairs as a function of LLM calls.

Efficiency and Generalization

The method is highly compute-efficient. Results indicate that just 12 carefully selected AuPairs can match the performance of 32 randomly selected pairs. Furthermore, AuPair demonstrates impressive generalization: pairs generated on one dataset or model remain highly effective when applied to different datasets or smaller models, suggesting that the "logic of repair" captured by AuPair is universal.

Conclusion

AuPair shifts the focus of code repair from iterative prompting to high-quality, diverse in-context examples. By prioritizing complementarity over individual pair quality, the method achieves state-of-the-art results and robust scaling. Future work aims to extend this grounded feedback mechanism to domains where unit tests are unavailable, potentially using Reward Models to identify "golden pairs" in creative or open-ended reasoning tasks.

Summary updated

BibTeX
@inproceedings{mavalankar2025aupair,
  author = {Aditi Mavalankar and Hassan Mansoor and Zita Marinho and Masha Samsikova and Tom Schaul},
  title = {{AuPair: Golden Example Pairs for Code Repair}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=GmqZ3WvkeV},
}
Figure