Introduction
Large Language Models (LLMs) have demonstrated impressive capabilities in code generation. However, they often struggle with the complex logic required for competitive programming, frequently producing code that is "almost right" but fails due to minor syntax errors or logical edge cases. Researchers from Peking University propose Self-Edit, a framework designed to mimic the human programming process: write, test, and refine.
Problem Statement
The primary challenge in automated code generation is "pass@1" accuracy—the likelihood that the first generated solution is correct. In competitive programming, even a single character error can lead to failure. Current state-of-the-art solutions often rely on computationally expensive "brute-force" sampling, generating thousands of candidates to find one correct solution. Self-Edit addresses this by introducing an iterative refinement process, leveraging execution feedback to debug initial outputs.
Methodology: The Self-Edit Pipeline
The Self-Edit framework employs a "generate-and-edit" strategy consisting of three main stages:
- Generation: An initial LLM (the generator) produces a code solution from a problem description.
- Execution: The generated code is executed against example test cases. The system captures the results, categorizing them as "Passed," "Wrong Answer" (capturing input/output discrepancies), or "Error" (capturing stack traces and line numbers).
- Editing: A smaller, fine-tuned "fault-aware code editor" (PyCodeGPT-110M) receives the problem description, the buggy code, and a Supplementary Comment containing the execution feedback. It then generates a corrected version of the code.
The editor is trained using the GOLD (Generation Off-policy Learning from Demonstrations) objective, which encourages the model to learn debugging patterns and effectively utilize the provided feedback.
Experimental Results
Self-Edit was evaluated on the APPS and HumanEval benchmarks. Key findings include:
- Performance Gains: The framework improved the average pass@1 across nine different LLMs by up to 89% on APPS-dev and 48% on HumanEval.
- Cross-Model Synergy: A small 110M parameter editor significantly improved the output of massive models like the 175B parameter GPT-3, raising its pass@1 on APPS-dev from 26.6% to 32.4%.
- Efficiency: Self-Edit is significantly faster than re-ranking baselines, completing the generation-execution-edit cycle in approximately 12 seconds, compared to over 110 seconds for traditional re-ranking.
Conclusion
Self-Edit demonstrates that providing LLMs with execution feedback and a specialized editing component can dramatically improve code generation quality. By focusing on iterative refinement rather than massive sampling, the framework offers a more efficient and human-like approach to automated programming. Future work will explore scaling the editor model and implementing multi-round debugging strategies.
Summary updated