{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/how-to-think-step-by-step-a-mechanistic","title":"How to think step-by-step: A mechanistic understanding of chain-of-thought reasoning","arxiv_id":"2402.18312","date":"2024-02-28","proceeding":null,"authors":["Subhabrata Dutta","Joykirat Singh","Soumen Chakrabarti","Tanmoy Chakraborty"],"abstract":"Despite superior reasoning prowess demonstrated by Large Language Models (LLMs) with Chain-of-Thought (CoT) prompting, a lack of understanding prevails around the internal mechanisms of the models that facilitate CoT generation. This work investigates the neural sub-structures within LLMs that manifest CoT reasoning from a mechanistic point of view. From an analysis of Llama-2 7B applied to multistep reasoning over fictional ontologies, we demonstrate that LLMs deploy multiple parallel pathways of answer generation for step-by-step reasoning. These parallel pathways provide sequential answers from the input question context as well as the generated CoT. We observe a functional rift in the middle layers of the LLM. Token representations in the initial half remain strongly biased towards the pretraining prior, with the in-context prior taking over in the later half. This internal phase shift manifests in different functional components: attention heads that write the answer token appear in the later half, attention heads that move information along ontological relationships appear in the initial half, and so on. To the best of our knowledge, this is the first attempt towards mechanistic investigation of CoT reasoning in LLMs.","url_abs":"https://arxiv.org/abs/2402.18312v2","url_pdf":"https://arxiv.org/pdf/2402.18312v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"how-to-think-step-by-step-a-mechanistic","repo_url":"https://github.com/joykirat18/how-to-think-step-by-step","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"jax","reach":{"status":"ok"}}],"tasks":[{"task_slug":"answer-generation","task_name":"Answer Generation"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2402.18312","atlas_url":"https://app.syntology.ai/?focus=2402.18312","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.18312"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/joykirat18/how-to-think-step-by-step","reach":{"status":"ok"}}],"summary":{"ran":2,"unverified":1},"by_repo_kind":{"official":{"samples":3,"ran":2,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":3,"samples":[{"code_sha256_prefix":"a58ad0b85b8406e6","entry":"patch_head_vector","repo":"joykirat18/how-to-think-step-by-step","repo_kind":"official","path":"AttentionProbability/ALTIDistribution.py","file_url":"https://github.com/joykirat18/how-to-think-step-by-step/blob/HEAD/AttentionProbability/ALTIDistribution.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a58ad0b85b8406e6"}},{"code_sha256_prefix":"ed6e13beb11f144e","entry":"patch_head_vector_avg","repo":"joykirat18/how-to-think-step-by-step","repo_kind":"official","path":"AttentionProbability/ALTIDistribution.py","file_url":"https://github.com/joykirat18/how-to-think-step-by-step/blob/HEAD/AttentionProbability/ALTIDistribution.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ed6e13beb11f144e"}},{"code_sha256_prefix":"f78171b290c65f3c","entry":"loadTransformerModel","repo":"joykirat18/how-to-think-step-by-step","repo_kind":"official","path":"utilsFile/loadModel.py","file_url":"https://github.com/joykirat18/how-to-think-step-by-step/blob/HEAD/utilsFile/loadModel.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f78171b290c65f3c"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}