Introduction
Large Language Models (LLMs) have revolutionized automated code generation, yet they frequently produce code containing syntax or runtime errors. Traditional preference optimization techniques, such as Direct Preference Optimization (DPO), typically rely on binary pass/fail signals. This "black-box" approach suffers from three critical issues: Error Blindness, where the model lacks diagnostic feedback; Lack of Focus, as training batches mix disparate error types; and Static Weakness, where fixed datasets fail to adapt to the model's evolving error patterns during training.
The AP2O Framework
To address these limitations, we propose Adaptively Progressive Preference Optimization (AP2O). This framework mimics human learning by categorizing errors and focusing on specific weaknesses progressively.
The process is structured into four distinct phases:
- Exam (Generation): The LLM generates multiple candidates for a problem set, which are then partitioned into "passed" and "failed" groups based on unit tests.
- Analysis (Diagnosis): An analyzer identifies specific error types (e.g.,
SyntaxError,TypeError) from the failed code, populating an "Error Notebook." - Correction (Progressive Optimization): The model focuses on one error type at a time using a sliding window. Two strategies were evaluated: Low-to-High frequency (L2H) and High-to-Low frequency (H2L).
- Quiz (Adaptive Error Replay): To prevent catastrophic forgetting, the system periodically evaluates the model on a validation set and re-introduces examples of current weaknesses into the training stream.
Key Insights and Results
Our evaluation across benchmarks like MBPP, TACO, and LiveCodeBench reveals that AP2O-Coder consistently outperforms state-of-the-art baselines, showing up to a 3% improvement in Pass@1 scores.
Efficiency and Scaling
A standout feature of AP2O is its remarkable data efficiency. By targeting specific error types rather than training on the entire dataset simultaneously, AP2O achieves superior performance using significantly less data.
As shown in the figure above, AP2O-Coder variants (L2H and H2L) utilize only a fraction of the data required by standard DPO-Coder. These efficiency gains become more pronounced as model size increases; for the 32B model, AP2O requires less than 10% of the original data to reach peak performance. This suggests that as models grow more capable, they require more targeted, rather than more voluminous, feedback.
Strategic Learning and Generalization
The research highlights that the optimal learning order is model-dependent. Smaller models (e.g., 0.5B) benefit from the L2H strategy, where learning from rare, diverse errors first aids generalization. Conversely, larger models (e.g., 34B) perform better with H2L, focusing on the most frequent errors to refine their specialized knowledge.
Furthermore, AP2O-Coder maintains these gains across higher sample counts (Pass@5 and Pass@10). The "Quiz" module proved essential here; by re-evaluating the model's current weaknesses, it ensures that fixing one type of error (like a ValueError) does not lead to a regression in another (like a SyntaxError).
Conclusion
AP2O-Coder demonstrates that a human-like, structured approach to error correction significantly enhances LLM coding capabilities while drastically reducing training costs. While currently dependent on Python-specific analyzers and high-quality unit tests, the "Error Notebook" concept offers a promising path for other verifiable domains like mathematics and formal logic.
Summary updated