Coffee: Boost Your Code LLMs by Fixing Bugs with Feedback

Seungjun Moon, Yongho Song, Hyungjoo Chae, Dongjin Kang, Taeyoon Kwon, Kai Tzu-iunn Ong, Seung-won Hwang, Jinyoung Yeo · OpenReview

Abstract

Code editing is an essential step towards reliable program synthesis to automatically correct critical errors generated from code LLMs. Recent studies have demonstrated that closed-source LLMs (i.e., ChatGPT and GPT-4) are capable of generating corrective feedback to edit erroneous inputs. However, it remains challenging for open-source code LLMs to generate feedback for code editing, since these models tend to adhere to the superficial formats of feedback and provide feedback with misleading information. Hence, the focus of our work is to leverage open-source code LLMs to generate helpful feedback with correct guidance for code editing. To this end, we present Coffee, a collected dataset specifically designed for code fixing with feedback. Using this dataset, we construct CoffeePots, a framework for COde Fixing with FEEdback via Preference-Optimized Tuning and Selection. The proposed framework aims to automatically generate helpful feedback for code editing while minimizing the potential risk of superficial feedback. The combination of Coffee and CoffeePots marks a significant advancement, achieving state-of-the-art performance on HumanEvalFix benchmark.

Introduction

While Large Language Models (LLMs) have become remarkably good at writing code, they still frequently produce snippets with subtle logic errors or "bugs." Fixing these bugs—a task known as code editing—is the next frontier in automated programming. While closed-source giants like GPT-4 are decent at self-correction when prompted with feedback, open-source models typically struggle to identify their own mistakes, let alone suggest meaningful fixes.

Current open-source code LLMs (like Code Llama or StarCoder) are often "blind" to their own errors. When asked to provide feedback on a buggy script, they tend to give vague or misleading advice that doesn't help an "editor" model actually fix the code. This "alignment gap" means standard supervised training makes a model sound like a human explainer without making it a good debugger.

Example of buggy code with logic errors and incorrect indexing.

The COFFEEPOTS Framework

To address these challenges, we introduce COFFEEPOTS (COde Fixing with FEEdback via Preference-Optimized Tuning and Selection), a two-phase framework designed to empower smaller, open-source models to generate high-quality, corrective feedback.

Phase I: Supervised Fine-Tuning (SFT)

We train two separate models based on Code Llama 7B:

  • The Critic: Tasked with generating natural language feedback describing a bug.
  • The Editor: Tasked with fixing the code, conditioned on the Critic’s feedback.

Phase II: Preference Alignment

Simply training on "correct" feedback isn't enough because the Critic might still miss the most "critical" errors. We employ Direct Preference Optimization (DPO) using synthetic test cases to evaluate the feedback. If the Editor uses a piece of feedback and successfully passes the tests, that feedback is marked as "preferred." The Critic is then tuned to favor generating feedback that leads to a successful fix. Additionally, at inference time, a trained Feedback Selector picks the candidate most likely to result in a correct edit.

Successfully corrected code after feedback-driven editing.

Data and Evaluation

We released COFFEE, a high-quality dataset specifically for this task, containing 44,782 instances across 742 distinct problem sets. Each instance includes a problem description, buggy code from real user submissions, correct code, natural language feedback, and synthetic test cases.

Our models were tested on the HumanEvalFix benchmark. COFFEEPOTS (7B) achieved a 51.2% Pass@1 rate, surpassing GPT-4 (47.0%) and the previous best open-source model, WizardCoder 16B (31.8%).

Key Insights

  • Feedback Quality > Model Size: A 7B model provided with aligned feedback can outperform much larger models.
  • Localization is Key: COFFEEPOTS showed the most significant gains in fixing "Excess Logic" and "Operator Misuse," bugs that require pinpointing specific redundant lines or incorrect symbols.
  • Iterative Success: When allowed to edit code iteratively, COFFEEPOTS showed a consistent upward trend in accuracy, whereas models without feedback guidance plateaued quickly.

Conclusion and Future Work

COFFEE and COFFEEPOTS represent a significant advancement in open-source code editing. While currently limited to Python and competitive programming domains, future work will expand to multilingual settings and complex software engineering tasks. The framework's reliance on synthetic test cases also suggests a path toward integration with more rigorous formal verification methods.

Summary updated

BibTeX
@misc{moon2023coffee,
  author = {Seungjun Moon and Yongho Song and Hyungjoo Chae and Dongjin Kang and Taeyoon Kwon and Kai Tzu-iunn Ong and Seung-won Hwang and Jinyoung Yeo},
  title = {{Coffee: Boost Your Code LLMs by Fixing Bugs with Feedback}},
  year = {2023},
  eprint = {2311.07215},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.07215},
}
Figure