Reasoning is a fundamental capability of Large Language Models (LLMs). While models have become remarkably proficient at narrow skills like math and code generation—thanks to massive, structured datasets—their performance on broader reasoning tasks (such as logical deduction or scientific inference) often lags due to sparse and fragmented supervision signals.
To address this, researchers introduce CodeI/O, a novel training framework that transforms raw code into natural language input-output prediction tasks. By training LLMs to reason through the execution logic of diverse code snippets in plain English, CodeI/O successfully "distills" universal reasoning patterns—like logic flow, recursion, and state-space search—improving model performance across math, logic, science, and commonsense benchmarks.
The Problem: Syntax vs. Logic
Current approaches like "continual pre-training" on raw code help improve reasoning, but they force the model to focus heavily on code-specific syntax rather than the underlying logic. The authors argue that the logic inside code—the decision trees, loops, and modular decompositions—is actually a goldmine for general-purpose reasoning, if only we could decouple it from the "noise" of programming syntax.
The CodeI/O Methodology
The authors propose a systematic pipeline to convert raw code into a "reasoning-centric" format.
- Transformation to Unified Format: Raw Python files are cleaned and refactored into a standard structure featuring a "Main Entrypoint" function, a natural language "Query" describing the task, and a rule-based "Input Generator."
- I/O Instance Sampling: For each function, the system generates multiple input-output pairs by actually executing the code.
- Chain-of-Thought (CoT) Synthesis: Using a strong "teacher" model (DeepSeek-V2.5), the system generates natural language rationales explaining how to get from an input to an output (or vice versa).
- The Prediction Task: Models are trained on two natural language tasks:
- Output Prediction: Given the code, a query, and an input, predict the output.
- Input Prediction: Given the code, a query, and a target output, find a feasible input.
- CodeI/O++ (Multi-turn Revision): Leveraging the fact that code is verifiable, the authors re-execute the code using the model's predicted inputs. If the model is wrong, the execution feedback is provided as a second turn, asking the model to revise its reasoning.
Key Insights
- Decoupling Logic from Syntax: By forcing the model to explain the execution in a natural language Chain-of-Thought, the model learns the procedural rigor of code without being constrained by the strict requirements of generating valid Python syntax.
- Code as a Verifiable Source of Truth: Unlike training on general web text, code provides a "ground truth" through execution. This allows for automated, high-quality feedback loops (CodeI/O++) that are difficult to achieve in pure natural language domains.
- Universal Reasoning Primitives: Code naturally encodes "primitives" like logic flow planning and modular decomposition. Learning these through I/O prediction makes them transferable to non-coding tasks like solving a logic puzzle or a physics problem.
Empirical Results
The researchers curated a massive training set of 3.5 million instances derived from approximately 450k unique functions (sourced from CodeMix, PyEdu-R, and algorithm repositories like LeetCode). They evaluated CodeI/O across four model families (Qwen 2.5, LLaMA 3.1, DeepSeek-V2-Lite, and Gemma 2) on 14 benchmarks covering symbolic/logic, math, science, and code execution.
- Universal Gains: CodeI/O led to consistent improvements across almost all benchmarks, not just code-related ones. Unlike math-specific datasets that often cause performance to "tank" on non-math tasks, CodeI/O provided a balanced boost.
- Superiority over Baselines: It outperformed other massive datasets like WebInstruct (WI) and OpenMathInstruct2. For example, on the Qwen 2.5 7B Coder base, CodeI/O improved the average score across 14 benchmarks from 54.8 to 57.2 (and 57.7 for CodeI/O++).
- Two-Stage Training: The paper finds that a "warm-up" stage on CodeI/O data followed by a second stage of general instruction tuning yields better results than simply mixing the data together.
Limitations and Future Work
While the results are highly promising, the authors acknowledge a few limitations. First, there are inherent data leakage concerns; although strict n-gram overlap filtering was conducted, the boundary between "learning a pattern" and "memorizing a problem" remains blurry. Second, the quality of the training data relies heavily on the teacher model's ability to generate accurate CoTs. Finally, to ensure tasks fit within context windows, excessively complex code was filtered out, potentially leaving advanced reasoning patterns untapped. Future work will explore optimal data-mixing strategies and further refine the "learnability" of converted code samples.
Summary updated