What I cannot execute, I do not understand: Training and Evaluating LLMs on Program Execution Traces

Jordi Armengol-Estapé, Quentin Carbonneaux, Tianjun Zhang, Aram H. Markosyan, Volker Seeker, Chris Cummins, Melanie Kambadur, Michael F. P. O'Boyle, Sida I. Wang, Gabriel Synnaeve, Hugh James LeatherarXiv 2025 · DOI

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:

  1. Data Scarcity: Large-scale datasets of executable code paired with diverse inputs are rare.
  2. Granularity: It is unclear whether models should learn from high-level source code lines or low-level bytecode instructions.
  3. Context Limits: Traditional "scratchpad" techniques, where a model writes out every intermediate step, quickly exhaust the context window in long-running programs.
Comparison of execution methods: Direct prediction and standard scratchpads fail on long-running programs like Collatz, whereas Dynamic Scratchpads succeed by predicting state updates.

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.
The Collatz conjecture implementation used as a benchmark for long-range execution reasoning.

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

BibTeX
@misc{armengolestape2025what,
  author = {Jordi Armengol-Estapé and Quentin Carbonneaux and Tianjun Zhang and Aram H. Markosyan and Volker Seeker and Chris Cummins and Melanie Kambadur and Michael F. P. O'Boyle and Sida I. Wang and Gabriel Synnaeve and Hugh James Leather},
  title = {{What I cannot execute, I do not understand: Training and Evaluating LLMs on Program Execution Traces}},
  year = {2025},
  eprint = {2503.05703},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.05703},
}
Figure