NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Learning Code Preference via Synthetic Evolution

Jiawei Liu, Thanh Nguyen, Mingyue Shang, Hantian Ding, Xiaopeng Li, Yu Yu, Varun Kumar, Zijian Wang · DOI

Introduction

While Large Language Models (LLMs) have demonstrated remarkable proficiency in generating code, the ability to accurately evaluate and rank code candidates remains a significant bottleneck. Traditional evaluation methods, such as test-case execution, are computationally expensive and often brittle in complex environments. Human annotation, while considered a gold standard, is slow, costly, and—as research reveals—surprisingly inconsistent when judging non-functional traits like security and efficiency.

To address these challenges, researchers from AWS AI Labs and UIUC have introduced CODEFAVOR, a framework designed to train small, specialized preference models. These models act as efficient "judges," capable of distinguishing between high-quality and low-quality code across multiple dimensions with high accuracy and low cost.

The CODEFAVOR Framework

CODEFAVOR shifts the paradigm from absolute quality scoring to pairwise preference learning. Given an instruction, two code candidates (A and B), and a specific criterion (e.g., "efficiency"), the model is trained to identify the superior candidate.

Overview of the CODEFAVOR framework, illustrating the synthetic evolution process through Commit-Instruct and Critic-Evol.

The core innovation of CODEFAVOR is Synthetic Evolution, a data generation strategy that leverages the natural progression of code toward better states. This process utilizes two primary pipelines:

  1. Commit-Instruct: This pipeline extracts real-world code changes from version control history. A critic LLM analyzes "before" and "after" snapshots of commits, filters out trivial changes, and rephrases the commit into a clean preference pair where the post-commit version is the preferred choice.
  2. Critic-Evol: This method employs a "strong" critic model (such as Llama-3-70B) to identify faults in code generated by a "weak" draft model (such as Llama-3-8B). The critic then provides a revised, improved version, creating a synthetic preference pair.

Models are trained using two distinct objectives: classification (predicting a simple preference token) and generation (producing a Chain-of-Thought explanation before making a selection).

Benchmarking with CODEPREFBENCH

To rigorously evaluate these models, the authors introduced CODEPREFBENCH, a comprehensive benchmark consisting of 1,364 tasks. Unlike previous benchmarks that rely solely on human intuition, CODEPREFBENCH utilizes objective oracles for its primary categories:

  • Correctness: Verified through extensive test-case execution (EvalPlus).
  • Efficiency: Measured via CPU instruction profiling (EvalPerf).
  • Security: Assessed using static analysis tools (CyberSecEval).
  • Human Preference: Based on consensus among 18 professional developers.

Key Results and Insights

The experimental results demonstrate that CODEFAVOR significantly enhances the evaluative capabilities of smaller models. By fine-tuning 7B and 12B parameter models on synthetic evolution data, the researchers created judges that rival or exceed the performance of models 6–9x their size.

Performance comparison of CODEFAVOR models against proprietary and open-weight baselines across correctness, efficiency, and security.

Key findings from the performance evaluation include:

  • Performance Gains: CODEFAVOR improved the accuracy of model-based preferences by up to 28.8% over base models. For instance, a tuned Mistral-7B model matched the performance of much larger models like Llama-3.1-70B.
  • Cost-Effectiveness: The framework is 34x more cost-effective than using high-end proprietary LLMs as judges and five orders of magnitude cheaper than human annotation.
  • The "Human Gap": A striking insight from the study is that human developers often struggle to identify security vulnerabilities and efficiency bottlenecks. Human agreement with security oracles was only ~60%, suggesting that specialized preference models can catch subtle issues that generalist developers might overlook.
  • The "Good-Looking Code" Bias: The study found that well-commented code can sometimes "fool" both humans and models into overlooking underlying bugs, highlighting the importance of training on diverse, evolution-based signals rather than just aesthetic markers.

Conclusion and Future Work

CODEFAVOR demonstrates that synthetic evolution is a powerful signal for teaching models the nuances of code quality. By leveraging the natural history of code improvements, researchers can train small, efficient models to perform high-level architectural and security critiques. Future work will focus on scaling the synthetic datasets to millions of samples and expanding the framework to incorporate repository-level context and a wider array of programming languages.

Paper Citation: Jiawei Liu et al. "Learning Code Preference via Synthetic Evolution." arXiv:2410.03837v2 [cs.LG], Oct 2024.

Summary updated

BibTeX
@misc{liu2024learning,
  author = {Jiawei Liu and Thanh Nguyen and Mingyue Shang and Hantian Ding and Xiaopeng Li and Yu Yu and Varun Kumar and Zijian Wang},
  title = {{Learning Code Preference via Synthetic Evolution}},
  year = {2024},
  eprint = {2410.03837},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.03837},
}
Figure