Lune

ICML2025顶会

Revisiting Chain-of-Thought in Code Generation: Do Language Models Need to Learn Reasoning before Coding?

Renbiao Liu, Anqi Li, Chaoding Yang, Hui Sun, Ming Li

摘要

Large Language Models (LLMs) have demonstrated exceptional performance in code generation, becoming increasingly vital for software engineering and development. Recently, Chain-of-Thought (CoT) has proven effective for complex tasks by prompting LLMs to reason step-by-step and provide a final answer. However, research on how LLMs learn to reason with CoT data for code generation remains limited. In this work, we revisit classic CoT training, which typically learns reasoning steps before the final answer. We synthesize a dataset to separate the CoT process from code solutions and then conduct extensive experiments to study how CoT works in code generation empirically. We observe counterintuitive phenomena, suggesting that the traditional training paradigm may not yield benefits for code generation. Instead, training LLMs to generate code first and then output the CoT to explain reasoning steps for code generation is more effective. Specifically, our results indicate that a 9.86% relative performance improvement can be achieved simply by changing the order between CoT and code. Our findings provide valuable insights into leveraging CoT to enhance the reasoning capabilities of CodeLLMs and improve code generation.

问 Lune

几分钟读透这篇 Paper,不用再花一下午。

Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。

已有 4 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。

可以从这些问题问起

Lune 可以查阅

全文 · 引用它的顶会 Paper · 相关的 Paper

获取答案

免费开始,无需绑卡

脉络

  • FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness 引用了 Language Models are Few-Shot Learners
  • ARBench: Algorithmic Reasoner or API Alchemist? Evaluating LLMs Beyond API Calls 引用了 Language Models are Few-Shot Learners
  • ARBench: Algorithmic Reasoner or API Alchemist? Evaluating LLMs Beyond API Calls 引用了 Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation
  • Random Selection Reveals Implicit Knowledge Consensus in Code Generation 引用了 ARBench: Algorithmic Reasoner or API Alchemist? Evaluating LLMs Beyond API Calls
  • Random Selection Reveals Implicit Knowledge Consensus in Code Generation 引用了 Dynamic-Static Synergistic Selection Method for Candidate Code Solutions with Generated Test Cases
  • Random Selection Reveals Implicit Knowledge Consensus in Code Generation 引用了 Language Models are Few-Shot Learners
  • Dynamic-Static Synergistic Selection Method for Candidate Code Solutions with Generated Test Cases 引用了 Language Models are Few-Shot Learners
  • Dynamic-Static Synergistic Selection Method for Candidate Code Solutions with Generated Test Cases 引用了 Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation
  • SWE-bench: Can Language Models Resolve Real-world Github Issues? 引用了 FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • SWE-bench: Can Language Models Resolve Real-world Github Issues? 引用了 Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation
  • Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation 引用了 Language Models are Few-Shot Learners
  • SEER: Self-Enhancing Chain-of-Thought Compression for Reasoning Models 引用了 Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
它引用的引用它的从左到右按年份排列,引用越多,位置越高。

引用它的顶会 Paper4

  1. Dynamic-Static Synergistic Selection Method for Candidate Code Solutions with Generated Test CasesRenbiao Liu, Jiang-Tian Xue, Chao-Zeng Ma, Hui Sun 等AAAI 2026 · 2 次引用
  2. ARBench: Algorithmic Reasoner or API Alchemist? Evaluating LLMs Beyond API CallsRenbiao Liu, Chao-Zeng Ma, Anqi Li, Hui Sun 等AAAI 2026
  3. Random Selection Reveals Implicit Knowledge Consensus in Code GenerationRen-Biao Liu, Li Xin-Ye, Hui Sun, Yali Du 等ICML 2026
  4. SEER: Self-Enhancing Chain-of-Thought Compression for Reasoning ModelsKerui Huang, Shuhan Liu, Xing Hu, Tongtong Xu 等ISSTA 2026

它引用的 Paper31

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah 等NeurIPS 2020 · 64,255 次引用
  2. Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma 等NeurIPS 2022 · 22,562 次引用
  3. FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessTri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra 等NeurIPS 2022 · 5,493 次引用
  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 次引用
  5. SWE-bench: Can Language Models Resolve Real-world Github Issues?Carlos E. Jimenez, John Yang, Alexander Wettig, Shunyu Yao 等ICLR 2024 · 2,082 次引用

相关 Paper

  1. The Impact of Reasoning Step Length on Large Language ModelsMingyu Jin, Qinkai Yu, Dong Shu, Haiyan Zhao 等ACL Findings 2024 · 39 次引用
  2. Towards Understanding Chain-of-Thought Prompting: An Empirical Study of What MattersBoshi Wang, Sewon Min, Xiang Deng, Jiaming Shen 等ACL 2023 · 100 次引用
  3. Compositional Generalization from Learned Skills via CoT Training: A Theoretical and Structural Analysis for ReasoningXinhao Yao, Ruifeng Ren, Yun Liao, Lizhong Ding 等ICLR 2026 · 6 次引用
  4. Transformers Learn to Implement Multi-step Gradient Descent with Chain of ThoughtJianhao Huang, Zixuan Wang, Jason D. LeeICLR 2025
  5. Rethinking Chain-of-Thought from the Perspective of Self-TrainingZongqian Wu, Baoduo Xu, Ruochen Cui, Mengmeng Zhan 等ICML 2025
黄昏的海面,两侧是细线勾勒的悬崖