atlas

Research map / Large language models / Reasoning and chain of thought

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

ICML 2025 · Large language models › Reasoning and chain of thought · approach: Chain-of-thought training and analysis

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Synthesizes a 50K code-generation SFT dataset with separate CoT and code, and finds that training models to output code first and then a CoT explanation ("code precede CoT") beats the traditional reasoning-first order.

Problem

Whether classic chain-of-thought ordering (reasoning before code) helps supervised fine-tuning of LLMs for code generation, and how the position of CoT relative to code affects learning.

Approach

Builds a dataset where NL problem, CoT reasoning, and code are separated and compares four SFT strategies, finding that placing code before the CoT explanation yields better code generation than CoT-first, treating CoT as an explanation rather than a reasoning process.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Put code before CoT instead of putting CoT before code (ablation)SFT of DeepSeek-Coder-Base-6.7B · EvalPlus averagePass@1: 65.43 -> 71.88Helped
Train on code without CoT rather than the Seed dataset (ablation)SFT of DeepSeek-Coder-Base-6.7B · EvalPlus averagePass@1: 68.40 -> 70.88Helped
Put CoT before code rather than using the Seed dataset (ablation)SFT of DeepSeek-Coder-Base-6.7B · EvalPlus averagePass@1: 68.40 -> 65.43Hurt
Put code before CoT rather than using the Seed dataset (ablation)SFT of DeepSeek-Coder-Base-6.7B · EvalPlus averagePass@1: 68.40 -> 71.88Helped
Put code before CoT rather than putting CoT before code (ablation)SFT of DeepSeek-Coder-Base-6.7B · LiveCodeBenchPass@1: 20.69 -> 21.08; 22.31 -> 22.56; 23.07 -> 24.16Helped
Put code before CoT rather than putting CoT before code (ablation)SFT of DeepSeek-Coder-Base-6.7B · BigCodeBenchPass@1: 36.05 -> 38.33; 15.54 -> 16.22Helped
Use a GPT-4o-0806-synthesized dataset (ablation)SFT strategies · EvalPlus averagePass@1: 65.95 -> 71.33Helped
Synthesize training data in an alternate order without reference code (ablation)SFT strategies · EvalPlus averagePass@1: 61.74 -> 67.35Helped
Synthesize training data from Stack code (ablation)SFT strategies · EvalPlus averagePass@1: 63.13 -> 68.65Helped
Remove function or class signatures from the code (ablation)SFT training data · EvalPlus averagePass@1Hurt
Mix Cfollow and Cprecede training patterns (ablation)SFT of the base model · EvalPlus averagePass@1Hurt
Replace code variable names with random, meaningless strings (ablation)SFT training data · EvalPlus averagePass@1Hurt

Surprising findings

Limitations

Experimental setup

Datasets: Magicoder-OSS-Instruct ShareGPT Python subset Evol-CodeAlpaca Evol-Instruct-Code CodeExercise-Python Codefuse-Evol-Instruct Stack

Benchmarks: HumanEval HumanEval+ MBPP MBPP+ LiveCodeBench BigCodeBench EvalPerf MultiPL-E LeetCode Contest

Metrics: Pass@1 Pass@k DPS CodeBLEU BLEU win rate

Baselines: Seed dataset SFT Code without CoT Code follow CoT

Builds on: chain-of-thought prompting context distillation STaR SelfCodeAlign

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy