Large Language Models (LLMs) excel at linguistic reasoning but often struggle with tasks requiring precise computation, symbolic manipulation, or long-term planning. Integrating a Code Interpreter (CI)—allowing the model to write and execute Python—is a proven solution. However, training models to effectively decide when and how to use this tool across diverse domains remains a significant challenge.
R1-Code-Interpreter introduces a new framework that trains LLMs to autonomously use a Code Interpreter across 144 diverse reasoning and planning tasks. By implementing a multi-stage reinforcement learning curriculum based on "improvement potential," the researchers developed a 14B model that outperforms GPT-4o with Code Interpreter on complex benchmarks.
The Challenge of Task Heterogeneity
The authors identify two major hurdles in training general-purpose code interpreters:
- Task Heterogeneity: Standard Reinforcement Learning (RL) struggles when training on a mix of very easy and very hard tasks simultaneously. The learning signal from successful trials gets diluted, leading to marginal gains.
- Training Efficiency: Executing code during RL training is slow and leaves expensive GPUs idling, making the process computationally prohibitive.
Methodology: A Multi-Stage Curriculum
To overcome these hurdles, the researchers developed a multi-stage pipeline to transform a standard LLM (Qwen-2.5) into a code-augmented reasoning agent.
- Multi-turn SFT: The process begins with Supervised Fine-Tuning using 6.5k high-quality trajectories where the model interleaves textual reasoning with code execution.
- Multi-stage GRPO with Curriculum Learning: They utilized Group Relative Policy Optimization (GRPO) but introduced a novel Curriculum Learning layer. Instead of a traditional "easy-to-hard" progression, samples are ranked by their Improvement Potential (IP). If a model gets a question right 0% or 100% of the time during sampling, it learns nothing. The optimal learning zone is when a model succeeds about 50% of the time. The curriculum prioritizes these "high-potential" samples first and gradually shifts to lower-potential ones.
- Decoupled Execution Sandbox: To address efficiency, they built a specialized sandbox that runs code on CPU nodes while GPUs handle gradient calculations, reducing training time by 39%.
Datasets and Key Discoveries
The framework was trained and evaluated on a curated benchmark of 144 reasoning and planning tasks sourced from SymBench, Big-Bench-Hard (BBH), and Reasoning-Gym. These tasks span logic puzzles, spatial reasoning, math, and algorithmic challenges (107 for training, 37 for testing).
During training, the authors made several fascinating observations:
- The "Vanishing Signal": They mathematically demonstrated why vanilla RL fails on mixed data. In batches dominated by tasks that are too easy or too hard, the policy gradient effectively vanishes, leaving the model governed only by the KL-divergence penalty rather than actual improvement.
- Emergent Self-Checking: RL induced an unexpected "self-checking" behavior. The model began autonomously writing code to verify its own textual reasoning steps—a winning strategy for maximizing rewards that wasn't explicitly in the training data.
- Multi-turn Necessity: Single-turn code generation proved insufficient for complex planning. The model's ability to "execute-and-explore" (e.g., running code, encountering a failure, and trying a different algorithm) was crucial.
Key Results
The resulting model, R1-CI-14B, demonstrated remarkable performance gains, proving the efficacy of the IP-based curriculum.
- Superior Performance: Test accuracy improved from 44.1% (after SFT) to 72.4% (after RL).
- Beating the Giants: Despite its smaller size, R1-CI-14B outperformed both text-only GPT-4o (58.6%) and GPT-4o with Code Interpreter (70.9%).
- Curriculum Wins: The IP-based curriculum was highly effective, increasing average RL gains from a mere +3.4% to a significant +9.3%.
- Generalization: The model exhibited strong Out-of-Distribution (OOD) performance on elite benchmarks like GPQA and AIME, proving it learned generalizable reasoning skills rather than just memorizing training tasks.
Limitations and Future Work
Despite these advances, challenges remain. Training the 14B model still required approximately 1,845 GPU hours, and inference latency is higher due to multi-turn reasoning and code execution. Furthermore, if the base model lacks fundamental "world knowledge" for a specific domain, RL alone cannot bridge the gap. Future work will explore integrating even more complex tools, such as web browsing or specialized solvers, using this multi-stage curriculum framework.
Summary updated