Abstract
Code generation has attracted increasing attention with the rise of Large Language Models (LLMs). Many studies have developed powerful code LLMs by synthesizing code-related instruction data and applying supervised fine-tuning. However, these methods are limited by teacher model distillation and ignore the potential of iterative refinement by self-generated code. In this paper, we propose Adaptive Critique Refinement (ACR), which enables the model to refine itself by self-generated code and external critique, rather than directly imitating the code responses of the teacher model. Concretely, ACR includes a composite scoring system with LLM-as-a-Judge to evaluate the quality of code responses and a selective critique strategy with LLM-as-a-Critic to critique self-generated low-quality code responses. We develop the RefineCoder series by iteratively applying ACR, achieving continuous performance improvement on multiple code generation benchmarks. Compared to the baselines of the same size, our proposed RefineCoder series can achieve comparable or even superior performance using less data.
Introduction
The current paradigm for training code-specific Large Language Models (LLMs) heavily relies on Distillation-based Fine-Tuning (DFT). In DFT, a smaller student model is trained to mimic the outputs of a larger, more capable teacher model. While effective, this approach creates a performance ceiling defined by the teacher's capabilities and overlooks the learning potential inherent in the student's own errors.
RefineCoder addresses this by introducing Adaptive Critique Refinement (ACR). Instead of simple imitation, ACR encourages the model to learn from its own mistakes through a process of self-generation, evaluation, and critique-based refinement. This mimics human learning, where understanding the "why" behind a failure is often more valuable than simply seeing the correct answer.
Methodology: Adaptive Critique Refinement (ACR)
The ACR framework is an iterative loop designed to progressively enhance model performance. The process begins with an initial high-quality dataset ($D_0$) of 80K Python instructions.
The ACR pipeline consists of four main stages:
- Sampling: The current model ($M_t$) generates multiple candidate code responses ($y^1, ..., y^n$) for a given instruction ($x$).
- Ranking: A composite scoring system evaluates these responses. It employs an LLM-as-a-Judge to assess correctness and clarity, alongside a Code Executor for functional verification.
- Refining: This stage uses a selective critique strategy. If a self-generated response is superior to the original teacher response ($y^0$), it is selected as the new training target. If the model's outputs are inferior, an LLM-as-a-Critic generates a detailed critique ($c$) explaining the errors. This transforms the training data into a multi-turn dialogue: Instruction -> Low-quality Code -> Critique -> High-quality Code.
- Training: The model is fine-tuned on this adaptive dataset to produce the next iteration model ($M_{t+1}$).
Experimental Results
The researchers developed the RefineCoder series based on DeepSeek-Coder-6.7B and Qwen2.5-Coder-7B architectures. The models underwent three iterations of the ACR process.
Iterative Performance Gains
A key finding is that performance improves consistently across iterations. As shown in the figure below, both the Qwen and DeepSeek-based models show a clear upward trajectory in average Pass@1 scores from Iteration 0 to Iteration 3.
Benchmark Excellence
RefineCoder-QW-7B (Iter3) achieved state-of-the-art results for its size:
- HumanEval+: Reached a Pass@1 of 83.3.
- LiveCodeBench & BigCodeBench-hard: Achieved an average Pass@1 of 21.7, outperforming the standard Qwen2.5-Coder-7B-Instruct.
- Data Efficiency: RefineCoder-DS-6.7B outperformed baselines trained on significantly larger datasets (up to 2 trillion tokens), demonstrating the power of high-quality, targeted refinement data.
Robustness and Generalization
Beyond raw scores, RefineCoder demonstrated superior "Feedback Mastery," outperforming GPT-4o in its ability to correct code based on external debugging hints. Furthermore, while fine-tuned primarily on Python, the model showed improved performance across multiple languages (C++, Java, JavaScript, etc.) in the MultiPL-E benchmark, indicating that the logic learned through ACR generalizes well.
Conclusion
RefineCoder demonstrates that iterative self-refinement via Adaptive Critique Refinement is a highly effective alternative to traditional teacher distillation. By learning to critique and correct its own mistakes, the model breaks through the performance ceiling of its teacher. Future work will explore automating instruction generation and applying the ACR framework to other reasoning-intensive domains like mathematics.
Summary updated