TL;DR
PLUM (Preference Learning Augmented with Test Cases for Code LMs) is an execution-guided preference tuning framework that trains code language models using their own outputs. By automatically generating unit tests to score on-policy code solutions as preferred or dis-preferred, PLUM sidesteps noisy reward models and produces substantial gains across benchmarks like HumanEval, MBPP, and LiveCodeBench.
What Problem Does This Paper Address?
Supervised Fine-Tuning (SFT) teaches models how to mimic human coding styles and follow instructions, but it fails to teach them the difference between correct and subtly buggy code. Consequently, SFT models frequently output programs that are syntactically valid yet functionally flawed on edge cases.
Preference learning methods (such as DPO and KTO) offer a solution by teaching models to prefer correct solutions over failed ones. However, preference learning works best when fed on-policy data (responses generated by the model currently being trained). In code generation, building on-policy preference datasets at scale has traditionally required either manual annotation or training learned reward models, which are noisy, difficult to optimize, and prone to reward hacking.
Methods
PLUM bypasses learned reward models entirely by relying on unit test execution as a ground-truth reward oracle:
- Synthetic Test Generation & Quality Filtering: Given natural language programming prompts, a generator LLM (e.g., GPT-4) generates reference solutions and accompanying unit test assertions. A self-consistency filter discards any sample where the generated reference solution fails its own unit tests.
- On-Policy Sampling & Execution: Multiple candidate solutions are sampled directly from the target policy model. Candidate code is statically analyzed (using
mypy) to remove syntax errors and executed against the test suite. Solutions passing all tests are labeled as positive (chosen); solutions failing tests are marked as negative (rejected). - Preference Optimization: The model is tuned on these on-policy pairs using algorithms like Kahneman-Tversky Optimization (KTO) or Direct Preference Optimization (DPO). The framework readily supports both single-turn offline tuning and multi-turn iterative (online) alignment.
[Prompt] ➔ [LLM Generates Tests + Ref] ➔ [Self-Consistency Check]
│
[Policy Model] ➔ [Sample On-Policy Code] ➔ [Execute Tests] ➔ [KTO / DPO Training]
Datasets
- Training Instruction Sources: Prompt instructions were sourced from OSS-Instruct, Evol-Instruct-Code, and a Python subset of ShareGPT. The original reference solutions provided in these datasets were deliberately discarded; only the prompts were used.
- Evaluation Benchmarks:
- HumanEval & HumanEval(+) and MBPP & MBPP(+) (standard unit-test benchmarks and their rigorous edge-case enhanced versions).
- LiveCodeBench (LCB) (contamination-free, interview-level coding challenges).
- LeetCode (algorithmic problem solving).
Key Insights and Ideas
- Test cases beat reward models: Automated execution feedback provides a lightweight, objective signal that enables iterative alignment without reward model collapse.
- On-policy data is critical: Training with completions sampled from the policy model itself outperforms using off-policy data from other open/closed models.
- Synthetic AST mutations hurt performance: Artificially introducing errors (e.g., mutating operators or argument order via Abstract Syntax Trees) degraded performance compared to natural on-policy mistakes made by the model.
- Non-executable negatives are insufficient: Relying solely on syntax-error code as negative preference examples provides a noisy signal; models learn much better when penalized for code that compiles but fails logical tests.
- Cost-effective generators suffice: Ablations demonstrated that smaller, cost-effective test generators (e.g., GPT-4o-mini, Claude-3-Haiku, or Llama 3.1-70B) yielded performance gains comparable to GPT-4.
Key Results
- Standard Benchmarks (MBPP & HumanEval): PLUM delivered consistent improvements across various model families (CodeQwen, DeepSeek-Coder, MagiCoder, OpenCodeInterpreter). For instance, PLUM-KTO improved CodeQwen-1.5-Chat from an average of 76.8% to 79.3%, and DeepSeek-Coder-Instruct from 71.8% to 76.2%.
- Challenging Benchmarks (LiveCodeBench): On complex interview problems, PLUM improved CodeQwen-1.5-Chat pass rates from 23.2% to 25.8% (and medium difficulty problems from 18.8% to 23.2%). MagiCoder-DS saw its overall score jump from 14.0% to 25.8%.
- Stronger Base Models: When applied to larger, modern models like Qwen-2.5-Coder-14B, PLUM pushed LeetCode accuracy from 58.3% to 61.7% and LiveCodeBench from 32.2% to 35.0%.
- Iterative / Online Preference Tuning: Multi-turn online policy updates outperformed offline preference tuning on LeetCode (achieving up to 37.2% on CodeQwen vs. 33.9% baseline).
Limitations and Future Work
- Language Scope: The current implementation and experiments are restricted to Python.
- Test Case Incompleteness & Under-specification: Synthetic test suites can suffer from false positives if the generated tests fail to cover rare edge cases.
- Competitive Programming Bottlenecks: On extremely hard problem distributions (like CodeContests), PLUM struggled because policy models rarely generated any passing candidate solutions to form positive pairs.
Summary updated