Lune

ACL2025Top-tier venue

CodeDPO: Aligning Code Models with Self Generated and Verified Source Code

Kechi Zhang, Ge Li, Yihong Dong, Jingjing Xu, Jun Zhang, Jing Su, Yongfei Liu, Zhi Jin

Abstract

Code generation models have shown significant potential for programming tasks. However, existing training methods like supervised fine-tuning face key limitations: they do not effectively teach models to prioritize correct over incorrect solutions in ambiguous situations, nor do they effectively optimize the runtime efficiency of the generated code. To address these challenges, we propose CodeDPO, a framework that integrates preference learning into code generation to improve two key code preference factors: code correctness and efficiency. CodeDPO employs a novel dataset construction method, utilizing a self-generation-andvalidation mechanism that simultaneously generates and evaluates code and test cases. The underlying assumption is that test cases executable by multiple code snippets provide more reliable validation, and code that passes more tests is more likely to be correct. Through this self-validation process, our PageRank-inspired algorithm iteratively updates the ranking score of each code snippet, ultimately creating a code preference optimization dataset based on correctness and efficiency. CodeDPO is flexible and scalable, generating diverse preference optimization data without depending on powerful models such as GPT-4. Through comprehensive evaluations of five widely used benchmarks, CodeDPO demonstrates significant improvements in correctness and efficiency compared to existing methods. Our experiments prove that CodeDPO enhances the capabilities of LLMs in code generation and provides a robust foundation for conducting code preference optimization in more complex and challenging real-world scenarios. 1 Figure 1 : Log probabilities for code with varying correctness and efficiency during Phi-2-2.7B model training on our constructed dataset. The traditional SFT strategy struggles to teach models to prefer correct solutions over incorrect or slow ones. In contrast, our CodeDPO approach effectively optimizes for both correctness and efficiency.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

24 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Fine-R1: Make Multi-modal LLMs Excel in Fine-Grained Visual Recognition by Chain-of-Thought Reasoning cites Visual-RFT: Visual Reinforcement Fine-Tuning
  • WizardCoder: Empowering Code Large Language Models with Evol-Instruct cites DS-1000: A Natural and Reliable Benchmark for Data Science Code Generation
  • JarvisArt: Liberating Human Artistic Creativity via an Intelligent Photo Retouching Agent cites Visual-RFT: Visual Reinforcement Fine-Tuning
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers24

  1. Visual-RFT: Visual Reinforcement Fine-TuningZiyu Liu, Zeyi Sun, Yuhang Zang, Xiaoyi Dong et al.ICCV 2025 · 563 citations
  2. JarvisArt: Liberating Human Artistic Creativity via an Intelligent Photo Retouching AgentYunlong Lin, Zixu Lin, Kunjie Lin, Jinbin Bai et al.NeurIPS 2025 · 42 citations
  3. GRE Suite: Geo-localization Inference via Fine-Tuned Vision-Language Models and Enhanced Reasoning ChainsChun Wang, Xiaojun Ye, Xiaoran Pan, Zihao Pan et al.NeurIPS 2025 · 18 citations
  4. Fine-R1: Make Multi-modal LLMs Excel in Fine-Grained Visual Recognition by Chain-of-Thought ReasoningHulingxiao He, Zijun Geng, Yuxin PengICLR 2026 · 12 citations
  5. PEACE: Towards Efficient Project-Level Efficiency Optimization via Hybrid Code EditingXiaoxue Ren, Jun Wan, Yun Peng, Zhongxin Liu et al.ASE 2025 · 5 citations

Builds on12

  1. Direct Preference Optimization: Your Language Model is Secretly a Reward ModelRafael Rafailov, Archit Sharma, Eric Mitchell, Christopher D. Manning et al.NeurIPS 2023 · 10,924 citations
  2. Teaching Large Language Models to Self-DebugXinyun Chen, Maxwell Lin, Nathanael Schärli, Denny ZhouICLR 2024 · 1,085 citations
  3. WizardCoder: Empowering Code Large Language Models with Evol-InstructZiyang Luo, Can Xu, Pu Zhao, Qingfeng Sun et al.ICLR 2024 · 945 citations
  4. Self-Instruct: Aligning Language Models with Self-Generated InstructionsYizhong Wang, Yeganeh Kordi, Swaroop Mishra, Alisa Liu et al.ACL 2023 · 540 citations
  5. DS-1000: A Natural and Reliable Benchmark for Data Science Code GenerationYuhang Lai, Chengxi Li, Yiming Wang, Tianyi Zhang et al.ICML 2023 · 504 citations

Related papers

  1. Teaching Your Models to Understand Code via Focal Preference AlignmentJie Wu, Haoling Li, Xin Zhang, Xiao Liu et al.EMNLP 2025
  2. Focused-DPO: Enhancing Code Generation Through Focused Preference Optimization on Error-Prone PointsKechi Zhang, Ge Li, Jia Li, Yihong Dong et al.ACL Findings 2025 · 6 citations
  3. Enhancing Machine Translation with Self-Supervised Preference DataHaoxiang Sun, Ruize Gao, Pei Zhang, Baosong Yang et al.ACL 2025 · 7 citations
  4. Alignment with Fill-In-the-Middle for Enhancing Code GenerationHouxing Ren, Zimu Lu, Weikang Shi, Haotian Hou et al.EMNLP 2025
  5. Preference Optimization for Reasoning with Pseudo FeedbackFangkai Jiao, Geyang Guo, Xingxing Zhang, Nancy F. Chen et al.ICLR 2025
Dusk over the sea between two cliffs drawn in fine vertical lines