Lune

ICML2024Top-tier venue

NExT: Teaching Large Language Models to Reason about Code Execution

Ansong Ni, Miltiadis Allamanis, Arman Cohan, Yinlin Deng, Kensen Shi, Charles Sutton, Pengcheng Yin

Abstract

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 M bp p and H u man E val 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.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

28 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • STaR: Bootstrapping Reasoning With Reasoning cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • Mitigating Overthinking in Large Reasoning Models via Manifold Steering cites Let's Verify Step by Step
  • Mitigating Overthinking in Large Reasoning Models via Manifold Steering cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • CodeCrash: Exposing LLM Fragility to Misleading Natural Language in Code Reasoning cites Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation
  • Self-Refine: Iterative Refinement with Self-Feedback cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • Is Programming by Example Solved by LLMs? cites Self-Refine: Iterative Refinement with Self-Feedback
  • Is Programming by Example Solved by LLMs? cites Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation
  • Let's Verify Step by Step cites STaR: Bootstrapping Reasoning With Reasoning
  • Let's Verify Step by Step cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • SemCoder: Training Code Language Models with Comprehensive Semantics Reasoning cites Let's Verify Step by Step
  • SemCoder: Training Code Language Models with Comprehensive Semantics Reasoning cites Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation
  • SemCoder: Training Code Language Models with Comprehensive Semantics Reasoning cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • Learning to Edit Visual Programs with Self-Supervision cites Self-Refine: Iterative Refinement with Self-Feedback
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers28

  1. Mitigating Overthinking in Large Reasoning Models via Manifold SteeringYao Huang, Huanran Chen, Shouwei Ruan, Yichi Zhang et al.NeurIPS 2025 · 45 citations
  2. Is Programming by Example Solved by LLMs?Wen-Ding Li, Kevin EllisNeurIPS 2024 · 45 citations
  3. CodeCrash: Exposing LLM Fragility to Misleading Natural Language in Code ReasoningMan Ho Lam, Chaozheng Wang, Jen-Tse Huang, Michael R. LyuNeurIPS 2025 · 16 citations
  4. SemCoder: Training Code Language Models with Comprehensive Semantics ReasoningYangruibo Ding, Jinjun Peng, Marcus J. Min, Gail E. Kaiser et al.NeurIPS 2024 · 13 citations
  5. Learning to Edit Visual Programs with Self-SupervisionR. Kenny Jones, Renhao Zhang, Aditya Ganeshan, Daniel RitchieNeurIPS 2024 · 9 citations

Builds on30

  1. Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
  2. Self-Refine: Iterative Refinement with Self-FeedbackAman Madaan, Niket Tandon, Prakhar Gupta, Skyler Hallinan et al.NeurIPS 2023 · 4,972 citations
  3. Let's Verify Step by StepHunter Lightman, Vineet Kosaraju, Yuri Burda, Harrison Edwards et al.ICLR 2024 · 3,045 citations
  4. Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code GenerationJiawei Liu, Chunqiu Steven Xia, Yuyao Wang, Lingming ZhangNeurIPS 2023 · 2,317 citations
  5. STaR: Bootstrapping Reasoning With ReasoningEric Zelikman, Yuhuai Wu, Jesse Mu, Noah D. GoodmanNeurIPS 2022 · 1,126 citations

Related papers

  1. Teaching Large Language Models to Self-DebugXinyun Chen, Maxwell Lin, Nathanael Schärli, Denny ZhouICLR 2024 · 1,085 citations
  2. LeDex: Training LLMs to Better Self-Debug and Explain CodeNan Jiang, Xiaopeng Li, Shiqi Wang, Qiang Zhou et al.NeurIPS 2024 · 6 citations
  3. T-REX: Teaching Large Language Models to Reason with Verbalized Execution SemanticsYan Wang, Ling Ding, Jiechen Sun, Tien N. Nguyen et al.OOPSLA 2026
  4. ThinkRepair: Self-Directed Automated Program RepairXin Yin, Chao Ni, Shaohua Wang, Zhenhao Li et al.ISSTA 2024 · 37 citations
  5. Revisiting Chain-of-Thought in Code Generation: Do Language Models Need to Learn Reasoning before Coding?Renbiao Liu, Anqi Li, Chaoding Yang, Hui Sun et al.ICML 2025
Dusk over the sea between two cliffs drawn in fine vertical lines