[Paper Review] NExT: Teaching Large Language Models to Reason about Code Execution
NExT finetunes LLMs to reason about program execution traces in natural language via self-training with unit-test feedback, improving Python program repair accuracy and rationale quality, even when traces are absent at test time.
A fundamental skill among human developers is the ability to understand and reason about program execution. As an example, a programmer can mentally simulate code execution in natural language to debug and repair code (aka. rubber duck debugging). However, large language models (LLMs) of code are typically trained on the surface textual form of programs, thus may lack a semantic understanding of how programs execute at run-time. To address this issue, we propose NExT, a method to teach LLMs to inspect the execution traces of programs (variable states of executed lines) and reason about their run-time behavior through chain-of-thought (CoT) rationales. Specifically, NExT uses self-training to bootstrap a synthetic training set of execution-aware rationales that lead to correct task solutions (e.g., fixed programs) without laborious manual annotation. Experiments on program repair tasks based on MBPP and HumanEval demonstrate that NExT improves the fix rate of a PaLM 2 model, by 26.1% and 14.3% absolute, respectively, with significantly improved rationale quality as verified by automated metrics and human raters. Our model can also generalize to scenarios where program traces are absent at test-time.
Motivation & Objective
- Motivate the need for reasoning about program runtime behavior in LLM-based code tasks.
- Propose Naturalized Execution Tuning (NExT) to teach LLMs to reason with execution traces using CoT rationales.
- Develop a weakly-supervised self-training loop that samples, filters by unit tests, and finetunes on execution-aware rationales and fixes.
- Represent execution traces as compact inline code comments to aid LLM comprehension without disrupting code structure.
- Evaluate NExT on Python program repair benchmarks Mbpp-R and HumanEvalFix-Plus, and analyze rationale quality both intrinsically and extrinsically.
Proposed method
- Represent program execution traces as inline comments indexed by execution order to capture runtime states.
- Use a prompt-based CoT reasoning approach to generate natural language rationales and fixes.
- Apply a weak supervision loop (sample → filter by unit tests → train) to create synthetic training data from hard problems.
- Fine-tune the base LLM (PaLM 2-L) with the synthetic data across multiple iterations and select the best checkpoint by dev pass@1.
- Evaluate rationale quality with proxy-based metrics using smaller LMs conditioned on the rationales.
- Test generalization in test-time scenarios with traces absent and across out-of-distribution repair tasks.
Experimental results
Research questions
- RQ1Can LLMs reason effectively about program execution when given execution traces?
- RQ2Does adding execution-aware CoT rationales during training improve repair accuracy and rationale quality?
- RQ3How does NExT generalize when traces are unavailable at test time or on out-of-distribution tasks?
- RQ4Do the generated rationales meaningfully explain bugs and suggest fixes, as judged by humans and proxy metrics?
Key findings
- NExT yields substantial end-to-end fix-rate gains for PaLM 2-L (e.g., 26.1% absolute on Mbpp-R pass@1).
- Rationale quality improves with NExT, as shown by proxy-based metrics and human ratings.
- PaLM 2-L+NExT outperforms several strong LLMs and is competitive with GPT-3.5 on end-to-end repair metrics.
- Even without traces at test time, PaLM 2-L+NExT maintains a notable improvement over the baseline.
- NExT generalizes to HeFix+ and demonstrates higher-quality rationales than base models.
- Ablation studies show that reasoning with traces and CoT is critical for gains; removing traces or rationales degrades performance.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.