PLUM: Preference Learning Plus Test Cases Yields Better Code Language Models

Dylan Zhang, Shizhe Diao, Xueyan Zou, Hao Peng

Abstract

Preference learning provides a promising solution to address the limitations of supervised fine-tuning (SFT) for code language models, where the model is not explicitly trained to differentiate between correct and incorrect code. Recent findings demonstrate that on-policy data is the key to successful preference learning, where the preference data is collected using the same policy LM being trained. Inspired by this, we propose PLUM, an on-policy Preference Learning framework Augmented with test cases for code LMs. The framework operates in three key stages: (1) automatic generation of test cases from natural language instructions, (2) creation of a preference data by evaluating candidate code solutions sampled from the policy, which can then be used to (3) train the policy LM. PLUM obviates the need to train reward models, allowing for large scale on-policy and online preference data collation. PLUM is evaluated on both standard benchmarks (HumanEval, MBPP) and more challenging ones (LiveCodeBench), delivering substantial improvements over original SFT'ed models and other execution-feedback-driven approaches. We show PLUM's benefits are consistent across various widely-used code LMs even they have been well-trained with SFT. For example, PLUM increases pass rates by up to 4.8% on average on standard benchmarks and 11.8% on LiveCodeBench, demonstrating its effectiveness and generalizability.

Introduction

Supervised Fine-Tuning (SFT) is the current standard for training code language models. However, SFT primarily teaches models to imitate code patterns rather than understand functional correctness. This often leads to "hallucinated" logic—code that is syntactically correct but fails to solve the intended problem. While preference learning (e.g., RLHF) can address this by teaching models to distinguish between successful and failed outputs, it typically requires expensive human labeling or complex neural reward models that are prone to errors.

Furthermore, most existing preference datasets are "off-policy," meaning they are generated by models other than the one being trained. This creates a distributional shift that can hinder generalization. PLUM addresses these challenges by using an execution-guided, on-policy approach.

The PLUM Framework

PLUM turns the code execution environment into an automated teacher through a three-stage pipeline that leverages the binary nature of code correctness.

The PLUM framework: a three-stage pipeline for on-policy preference learning using execution-guided labeling.
  1. Synthetic Test Generation: Using a strong generator model (e.g., GPT-4), PLUM creates a reference solution and a suite of unit tests for natural language prompts. To ensure quality, a self-consistency filter is applied: if the reference solution fails the generated tests, the suite is discarded.
  2. On-Policy Sampling: The model under training (the "policy") generates multiple candidate solutions for a given prompt. This ensures the training data remains in-distribution.
  3. Execution-Guided Labeling: Instead of a neural reward model, PLUM uses a Python interpreter as an oracle. Candidates passing all unit tests are labeled as "positive" (preferred), while those that fail are labeled "negative" (dispreferred).
  4. Preference Optimization: The model is updated using algorithms like Direct Preference Optimization (DPO) or Kahneman-Tversky Optimization (KTO), redistributing probability mass toward functional solutions.

Experimental Setup

We utilized natural language prompts from diverse sources, including OSS-Instruct, Evol-Instruct-Code, and ShareGPT. Models were evaluated on industry-standard benchmarks such as HumanEval and MBPP, as well as the more rigorous, contamination-free LiveCodeBench and algorithmic challenges from LeetCode.

Results and Analysis

PLUM consistently outperformed SFT-only baselines and other execution-feedback approaches across all tested models and benchmarks.

Performance comparison (Pass@1) across various models and benchmarks, showing consistent gains with PLUM.

Key Findings

  • Significant Performance Gains: PLUM achieved an average pass rate increase of 4.8% on standard benchmarks. The improvements were most pronounced on difficult tasks, with a 11.8% increase on LiveCodeBench.
  • Execution as the Ultimate Oracle: By using unit tests, PLUM bypasses the need for fuzzy neural reward models and eliminates "reward hacking," where models trick a judge without solving the problem.
  • The Importance of On-Policy Data: Training on the model's own mistakes proved more effective than using off-policy data, as it targets the specific errors the model is prone to making.
  • Algorithm Stability: While both DPO and KTO were effective, KTO generally demonstrated superior stability during the optimization process.

Conclusion

PLUM demonstrates that high-quality, execution-verified feedback is a powerful substitute for massive amounts of unverified data. By focusing on functional correctness through on-policy preference learning, PLUM significantly enhances the reliability of code LMs. Future work will explore extending this framework to languages beyond Python and investigating mutation-based methods to generate even more challenging negative examples for training.

Summary updated

Abstract

Preference learning provides a promising solution to address the limitations of supervised fine-tuning (SFT) for code language models, where the model is not explicitly trained to differentiate between correct and incorrect code. Recent findings demonstrate that on-policy data is the key to successful preference learning, where the preference data is collected using the same policy LM being trained. Inspired by this, we propose PLUM, an on-policy $\textbf{P}$reference $\textbf{L}$earning framework A$\textbf{u}$gmented with test cases for code L$\textbf{M}$ s. The framework operates in three key stages: (1) automatic generation of test cases from natural language instructions, (2) creation of a preference data by evaluating candidate code solutions sampled from the policy, which can then be used to (3) train the policy LM. PLUM levitates the need to train reward models, allowing for large scale on-policy and online preference data collation. PLUM is evaluated on both standard benchmarks (HumanEval, MBPP) and more challenging ones (LiveCodeBench), delivering substantial improvements over original SFT'ed models and other execution-feedback-driven approaches. We show PLUM's benefits are consistent across various widely-used code LMs even they have been well-trained with SFT. For example, PLUM increases pass rates by up to 4.8% on average on standard benchmarks and 11.8% on LiveCodeBench, demonstrating its effectiveness and generalizability. We also demonstrate the benefits of on-policy and online preference learning by comprehensive experimentation.
BibTeX
@misc{zhang2024plum,
  author = {Dylan Zhang and Shizhe Diao and Xueyan Zou and Hao Peng},
  title = {{PLUM: Preference Learning Plus Test Cases Yields Better Code Language Models}},
  year = {2024},
  eprint = {2406.06887},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.06887},
}
Figure