CRPE: Expanding The Reasoning Capability of Large Language Model for Code Generation

Ningxin Gui, Qianghuai Jia, Feijun Jiang, Yuling Jiao, Dechun Wang, Jerry Zhijian YangarXiv 2025 · DOI

Introduction

While Large Language Models (LLMs) have demonstrated significant proficiency in generating simple code snippets, they frequently falter when confronted with complex, multi-step programming challenges. This limitation is often attributed to a reliance on "System 1" thinking—fast and intuitive, but prone to logical errors in intricate tasks. To address "hard" problems, models require "System 2" capabilities: the capacity to slow down, reason through logic, reflect on errors, and verify intermediate steps.

Current training paradigms predominantly focus on "final answer" correctness. This outcome-based approach often overlooks the reasoning process. Without high-quality data illustrating how to navigate a problem, models struggle to generalize their logic to novel, difficult scenarios. To bridge this gap, researchers have introduced CRPE (Code Reasoning Process Enhancer), a three-stage framework designed to shift the focus of LLM training from mere code production to mastering the step-by-step reasoning process.

The CRPE Framework

The CRPE framework employs a sophisticated three-stage pipeline to cultivate reasoning capabilities:

  1. Problem Generation: A massive library of challenging problems is constructed by synthesizing new, self-contained programming tasks from open-source code snippets using "seed" models (e.g., Llama-3, Mistral).
  2. COT Solution Generation: To generate "expert" reasoning data, a multi-agent system is utilized. This system includes a Thinking Agent for step generation, a Reflection Agent for logical critique, and an Execution Agent for sandbox code verification. This collaborative process produces high-quality Chain-of-Thought (CoT) data for Supervised Fine-Tuning (SFT).
  3. Self-explore & Self-improve: The model undergoes self-improvement via a tree-search algorithm that explores various reasoning paths. By identifying successful and failed paths, the system creates "step-wise preference pairs" for Step-DPO (Direct Preference Optimization), training the model to prioritize correct reasoning steps.
The three-stage CRPE framework: Problem Generation, COT Solution Generation, and Self-explore & Self-improve.

Multi-Agent Collaboration and Reflection

A core component of the COT Solution Generation stage is the interaction between agents. The Reflection Agent plays a critical role by evaluating the reasoning steps provided by the Thinking Agent and the feedback from the Execution Agent. It determines whether to continue the reasoning process, provide a final answer, or correct previous errors based on execution failures. This iterative feedback loop is essential for generating the high-quality CoT data required for effective model training.

Detailed logic of the Reflection Agent within the multi-agent system.

Datasets and Evaluation

The researchers synthesized a specialized Code-COT dataset consisting of 2,810 high-quality reasoning entries for the SFT phase, followed by a larger set of step-wise preference pairs for DPO.

Evaluation was primarily conducted on LiveCodeBench (July to Sept 2024) to ensure the models were tested on problems not present in their training data. Classic benchmarks like HumanEval and MBPP were also used to assess general coding proficiency.

Key Insights

  • Process Over Product: Teaching a model how to think is more effective than simply providing more correct code. Incorporating reasoning steps into training data yields significant performance gains.
  • LLMs as Effective Teachers: Models trained on LLM-generated, verified reasoning outperformed those trained on raw programmer-written code. The structured and verbose nature of LLM explanations provides a superior learning signal.
  • Fine-Grained Feedback: Step-DPO allows for feedback on individual logical transitions rather than just the final output, preventing the reinforcement of "lucky" correct answers derived from faulty logic.

Results

The COT-Coder models demonstrated state-of-the-art performance:

  • COT-Coder-7B-StepDPO achieved a pass@1 accuracy of 21.88 on LiveCodeBench, outperforming many models twice its size.
  • COT-Coder-32B-StepDPO reached a pass@1 of 35.08, surpassing GPT-4o (33.6) and performing competitively with Claude-3.5-Sonnet (35.4).
  • On HumanEval, the 7B model achieved a score of 74.4, demonstrating strong generalization across different coding tasks.

Limitations and Future Work

The authors identified two primary challenges: inference loops, where agents cycle indefinitely, and a heavy dependency on the initial problem set's quality. Future research will focus on optimizing token length for more efficient "thinking" and streamlining the self-improvement cycle to reduce the computational overhead of tree-search data synthesis.

Summary updated

BibTeX
@misc{gui2025crpe,
  author = {Ningxin Gui and Qianghuai Jia and Feijun Jiang and Yuling Jiao and Dechun Wang and Jerry Zhijian Yang},
  title = {{CRPE: Expanding The Reasoning Capability of Large Language Model for Code Generation}},
  year = {2025},
  eprint = {2505.10594},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.10594},
}
Figure