Abstract
While Large Language Models (LLMs) excel at code generation and comprehension, they often struggle with precise execution reasoning, frequently hallucinating program states. We present CodeReasoner, a framework that enhances the code reasoning capabilities of small-scale LLMs through a combination of high-quality synthetic data, two-way instruction tuning, and Group-relative Policy Optimization (GRPO). Our 7B-parameter model achieves performance parity with GPT-4o, while the 14B variant surpasses it on complex execution benchmarks.
Introduction
Modern LLMs demonstrate impressive proficiency in writing code and explaining logic. However, simulating the exact execution path of a program—tracking variable states through loops or complex manipulations—remains a significant challenge. This deficiency stems from two primary issues: the prevalence of "boilerplate" code in training sets which lacks dense logic, and the limitations of Supervised Fine-Tuning (SFT), which can lead to verbose but incorrect "overthinking" chains.
CodeReasoner addresses these gaps by focusing on "crunchy" logic and utilizing reinforcement learning to refine reasoning paths, enabling smaller models to compete with frontier models in code simulation.
Methodology: The Three Pillars of CodeReasoner
The CodeReasoner framework is built upon three core innovations designed to move beyond simple pattern matching toward true execution simulation.
1. Concise Dataset Construction
Rather than relying on noisy real-world code, the authors synthesized a dataset of ~18,000 "atomic" Python snippets. These snippets focus exclusively on core execution logic, such as built-in types and control structures, while stripping away non-essential boilerplate like class definitions or redundant getters.
2. Two-Way Instruction Tuning
To deepen the model's understanding of control flow, it is trained on two complementary tasks:
- Forward Reasoning: Predicting the program output given a specific input.
- Backward Reasoning: Inferring the necessary input to produce a given output.
3. Reinforcement Learning via GRPO
To mitigate the "overthinking" trap—where models produce long, repetitive reasoning chains that ultimately fail—CodeReasoner employs Group-relative Policy Optimization (GRPO). This RL approach rewards correct answers and implicitly penalizes inefficiency, acting as a "conciseness filter" that forces the model to find the most direct and accurate reasoning path.
Benchmarking and Evaluation
CodeReasoner was evaluated across three rigorous benchmarks: CRUXEval (input/output prediction), LiveCodeBench (competitive programming), and REval. REval is particularly demanding, requiring models to track fine-grained variable states and predict execution paths.
Key Results and Insights
The experimental results demonstrate that specialized training can significantly close the gap between small and large models:
- Performance Gains: CodeReasoner-7B outperformed specialized models like SEMCODER and CODEI/O by 27.1% to 40.2%.
- Frontier Parity: The 7B model matched GPT-4o on input/output and coverage prediction, while the 14B model outperformed GPT-4o on average across all datasets.
- The Power of Backward Reasoning: Training on inverse problems prevents the model from relying on statistical guesses, forcing a deeper simulation of code logic.
- Boilerplate as Noise: The study confirms that for reasoning tasks, realistic code often introduces noise. Stripping code to its logical essentials is more effective for learning execution patterns.
Conclusion
CodeReasoner demonstrates that high-quality, logic-dense data combined with reinforcement learning can dramatically enhance the reasoning capabilities of small LLMs. While currently limited to Python, the framework provides a scalable blueprint for developing models that can truly "think" through code execution. Future work will focus on expanding to multilingual support and reducing dependency on teacher models during the SFT phase.
Summary updated