Introduction
While Large Language Models (LLMs) have demonstrated remarkable proficiency in generating code, their ability to "reason" over that same code remains a significant hurdle. Most models treat code as static text—similar to natural language—rather than dynamic logic. This paper argues that true understanding requires the ability to execute code mentally. To bridge this gap, the authors introduce Execution Tuning (E.T.) and dynamic scratchpads, enabling models to simulate complex program executions for thousands of steps.
The Execution Gap
Most state-of-the-art models fail when asked to predict the output of simple functions. Current research identifies three primary obstacles in teaching LLMs to execute code:
- Data Scarcity: Large-scale datasets of executable code paired with diverse inputs are rare.
- Granularity: It is unclear whether models should learn from high-level source code lines or low-level bytecode instructions.
- Context Limits: Traditional "scratchpad" techniques, where a model writes out every intermediate step, quickly exhaust the context window in long-running programs.
Methodology: Execution Tuning (E.T.)
The researchers fine-tuned a Llama 3.1 8B model on structured execution traces. A custom Python tracer was developed using sys.settrace to capture local and global variables, the call stack, and Python opcodes (bytecode).
Dynamic Scratchpads
A key innovation is the Dynamic Scratchpad. Instead of recording a full history of every variable change, the model updates a single, self-contained JSON-like representation of the current state. This approach prevents "context explosion" and allows the model to handle executions exceeding 14,000 steps. Furthermore, the models were trained to predict states $N$ steps into the future, facilitating more efficient "mental execution."
Datasets and Evaluation
To scale training without manual labeling, the authors generated the E.T. Dataset by taking 300,000 unrestricted Python functions and using synthetic input generation (fuzzing and LLM-assisted). This produced over 1.5 million unique execution traces. Evaluation was conducted on:
- CruxEval & MBPP: Benchmarks for program output prediction and computational complexity.
- Algorithmic Tasks: Long execution chains including the Collatz conjecture and Fibonacci sequences.
Key Results and Insights
- Performance Leap: E.T.-trained models achieved ~80% accuracy on CruxEval and MBPP, compared to just 38% for the base Llama 3.1 8B.
- Bytecode Advantage: Models performed better predicting bytecode (instruction-level) than source code (line-level), likely because bytecode is more explicit and linear.
- Long-Haul Success: Using the Dynamic Scratchpad and a confidence-based search (Dijkstra), the model successfully predicted outputs for programs requiring over 14,000 steps.
- The Tokenization Wall: Despite improvements, models still struggle with arbitrary string manipulation, highlighting a fundamental limitation in how LLMs tokenize text.
Conclusion
Execution Tuning demonstrates that "writing" code and "running" code are distinct skills. While E.T. significantly boosts execution accuracy, its impact on general code generation is modest. Future work will explore extending these techniques to languages like C and addressing the tokenization gap to further unify code generation and execution capabilities.
Summary updated