SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.04667 · ICLR · 2025

Compositional Generalization from Learned Skills via CoT Training: A Theoretical and Structural Analysis for Reasoning

Yong Liu, Xinhao Yao, Yun Liao, Ruifeng Ren, Lizhong Ding

arXiv · PDF · Open in the Atlas

Code that ran

9 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 4 failures of our instrument; 1 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2502.04667.json · badge: /api/ran/2502.04667.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
chen123ctrls/t-cotmechanism canonical (classifier label)
classifier basis not recorded on the link
9 ran · 1 no recorded run
FunctionStatusWhere it lives
add_step_noise_to_gsm_fobar Ran
ran on a synthesized input
chen123ctrls/t-cotmechanism/RealisticDataVerification/data_process.py
code served (permissive licence) · get_code("cabf394868b62573")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import random
import re

random.seed(42)

ARGS = {
    'data': {
        'output': """Step 1: Calculate 5 + 3 = 8
Step 2: Multiply 8 * 2 = 16
Step 3: Divide 16 / 4 = 4
#### The answer is 4
The answer is 4""",
        'instruction': 'Solve this math problem',
        'type': 'gsm',
        'input': 'What is (5 + 3) * 2 / 4?'
    },
    'error_prob': 0.8
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
batch_data Ran
ran; our contract draft was wrong, not the code
chen123ctrls/t-cotmechanism/RealisticDataVerification/utils/gen_vllm.py
pointer only (licence: MIT); the stored copy get_code serves, from Rambo-Yi/TLora, is pointer only (licence: NONE) · get_code("d49412b3a690206e")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from Rambo-Yi/TLora, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

eval_items Ran
ran on a synthesized input
chen123ctrls/t-cotmechanism/ControlledExperiments/eval_qa.py
code served (permissive licence) · get_code("a3ae250c1e40eeef")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

def eval_res(a, b):
    assert b.count('</a>') in [0, 1]
    if b.count('</a>') == 0:
        return int(a.startswith(b))
    b = b.split('</a>')[0]
    a = a.split('</a>')[0]
    if b.count('<a>') == 1:
        if a.count('<a>') != 1:
            return 0
        a = a.split('<a>')[1]
        b = b.split('<a>')[1]
        return int(a == b)
    if b.count('<a>') == 0:
        return int(a == b)
    assert False

def eval_items(all_items, partition_atomic=False, test_entities=None):
    i = 0
    acc = dict()
    for item in all_items:
        if 'type' not in item:
            t = 'test_inferred'
        else:
            t = item['type']
        if 'model_output' in item:
            pred, gold = (item['model_output'], item['target_text'])
        else:
            pred, gold = (item['model output'], item['target text'])
        if t == 'train_atomic' and partition_atomic:
            head, rel, _ = gold.split('<a>')[0].strip('><').split('><')[1:-1]
            if rel in test_entities:
                if head in test_entities[rel]:
                    t = 'test_atomic'
                else:
                    t = 'train_atomic'
        if t not in acc:
            acc[t] = []
        acc[t].append(eval_res(pred, gold))
    return acc

# Build minimal valid arguments
all_items = [
    {
        'type': 'test_inferred',
        'model_output': 'prediction1',
        'target_text': 'target1'
    },
    {
        'type': 'test_inferred',
        'model_output': 'prefix_match',
        'target_text': 'prefix_match_extended'
    },
    {
        'type': 'train_atomic',
        'model_output': 'pred<a>inner</a>',
        'target_text': 'gold<a>inner</a>'
    }
]

partition_atomic = False
test_entities = None

ARGS = {
    'all_items': all_items,
    'partition_atomic': partition_atomic,
    'test_entities': test_entities
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
eval_res Ran
ran, honoured the contract we drafted
chen123ctrls/t-cotmechanism/ControlledExperiments/eval_qa.py
code served (permissive licence) · get_code("bedd2bb861320f0e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function eval_res takes two string parameters: a and b
# It performs string operations and comparisons on them
# No complex objects needed - just strings

ARGS = {
    'a': 'hello</a>world',
    'b': 'hello</a>'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_config_class_from_processor_class Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
chen123ctrls/t-cotmechanism/ControlledExperiments/transformers/utils/create_dummy_models.py
pointer only (licence: MIT); the stored copy get_code serves, from takagi97/OXA-Fine-tuning, is pointer only (licence: NONE) · get_code("3d999b95009c7537")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from takagi97/OXA-Fine-tuning, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_processor_types_from_config_class Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
chen123ctrls/t-cotmechanism/ControlledExperiments/transformers/utils/create_dummy_models.py
pointer only (licence: MIT); the stored copy get_code serves, from takagi97/OXA-Fine-tuning, is pointer only (licence: NONE) · get_code("0c0b81b081919d8e")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from takagi97/OXA-Fine-tuning, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

modify_output Ran
ran on a synthesized input
chen123ctrls/t-cotmechanism/RealisticDataVerification/data_process.py
code served (permissive licence) · get_code("bc440fba1f01ba1e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

def modify_output(example):
    output = example['output']
    ans = output.split('The answer is: ')[-1]
    example['output'] = 'The answer is: {}'.format(ans)
    return example

ARGS = {
    'example': {
        'output': 'Some text here. The answer is: 42'
    }
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
parse_target Ran
ran; our contract draft was wrong, not the code
chen123ctrls/t-cotmechanism/ControlledExperiments/eval_qa.py
code served (permissive licence) · get_code("62ef5378e10da132")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

def parse_target(target_text):
    temp = target_text.split('</a>')[0]
    q, a = temp.split('<a>')
    attr, q = q.split('<q>')
    q = q.split('</q>')[0]
    attr = attr.strip('><')
    h, _, t = q.strip('><').split('><')
    return (attr, h, t)

# Construct a valid target_text string that matches the expected format
# Format: <attr><q><h><><t></q><a>...</a>
target_text = "<color><q><head><><tail></q><a>answer</a>"

ARGS = {
    "target_text": target_text
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
read_data_source_target Ran
ran on a synthesized input
chen123ctrls/t-cotmechanism/ControlledExperiments/utils.py
code served (permissive licence) · get_code("aea562a62336c08f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned DataFrame. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import pandas as pd
import json
import tempfile
import os

# Create a temporary JSON file with test data
temp_dir = tempfile.gettempdir()
test_file = os.path.join(temp_dir, "test_data_source_target.json")

test_data = [
    {"input_text": "Hello world", "target_text": "Hi there"},
    {"input_text": "How are you", "target_text": "I'm fine"},
    {"input_text": "Good morning", "target_text": "Good day"}
]

with open(test_file, 'w', encoding='utf-8') as f:
    json.dump(test_data, f)

ARGS = {
    "file_name": test_file,
    "return_num": False,
    "return_json": False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
pandas — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type DataFrame — a DataFrame output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DataFrame output the recorded ndim 2 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_architectures_from_config_class Not yet run
unverified (harvested, no recorded run)
chen123ctrls/t-cotmechanism/ControlledExperiments/transformers/utils/create_dummy_models.py
pointer only (licence: MIT); the stored copy get_code serves, from takagi97/OXA-Fine-tuning, is pointer only (licence: NONE) · get_code("b176efb26f72e507")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from takagi97/OXA-Fine-tuning, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 6 are also present in other papers whose code we hold (6 with at least one paper dated earlier, 0 the same month, 4 later) and 4 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_config_class_from_processor_class 27 other papers
22 dated earlier, 5 later
2007.07779 (2020-07)
AdapterHub: A Framework for Adapting Transformers
2308.12219 (2023-08)
Diffusion Language Models Can Perform Many Tasks with Scaling and Instruction-Finetuning
2311.07468 (2023-11)
An Analysis and Mitigation of the Reversal Curse
and 24 more not named here
get_architectures_from_config_class 25 other papers
20 dated earlier, 5 later
2308.12219 (2023-08)
Diffusion Language Models Can Perform Many Tasks with Scaling and Instruction-Finetuning
2311.07468 (2023-11)
An Analysis and Mitigation of the Reversal Curse
2312.15710 (2023-12)
Alleviating Hallucinations of Large Language Models through Induced Hallucinations
and 22 more not named here
get_processor_types_from_config_class 25 other papers
20 dated earlier, 5 later
2308.12219 (2023-08)
Diffusion Language Models Can Perform Many Tasks with Scaling and Instruction-Finetuning
2311.07468 (2023-11)
An Analysis and Mitigation of the Reversal Curse
2312.15710 (2023-12)
Alleviating Hallucinations of Large Language Models through Induced Hallucinations
and 22 more not named here
batch_data 6 other papers
5 dated earlier, 1 later
2311.03099 (2023-11)
Language Models are Super Mario: Absorbing Abilities from Homologous Models as a Free Lunch
2406.09044 (2024-06)
MiLoRA: Harnessing Minor Singular Components for Parameter-Efficient LLM Finetuning
2406.11617 (2024-06)
DELLA-Merging: Reducing Interference in Model Merging through Magnitude-Based Sampling
and 3 more not named here
eval_res 1 other paper
1 dated earlier
2405.15071 (2024-05)
Grokked Transformers are Implicit Reasoners: A Mechanistic Journey to the Edge of Generalization
parse_target 1 other paper
1 dated earlier
2405.15071 (2024-05)
Grokked Transformers are Implicit Reasoners: A Mechanistic Journey to the Edge of Generalization

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Chain-of-Thought (CoT) training has markedly advanced the reasoning capabilities of large language models (LLMs), yet the mechanisms by which CoT training enhances generalization remain inadequately understood. In this work, we demonstrate that compositional generalization is fundamental: models systematically combine simpler learned skills during CoT training to address novel and more complex problems. Through a theoretical and structural analysis, we formalize this process: ❶ Theoretically, the information-theoretic generalization bounds through distributional divergence can be decomposed into in-distribution (ID) and out-of-distribution (OOD) components. Specifically, the non-CoT models fail on OOD tasks due to unseen compositional patterns, whereas CoT-trained models achieve strong generalization by composing previously learned skills. In addition, controlled experiments and real-world validation confirm that CoT training accelerates convergence and enhances generalization from ID to both ID and OOD scenarios while maintaining robust performance even with tolerable noise. ❷ Structurally, CoT training internalizes reasoning into a two-stage compositional circuit, where the number of stages corresponds to the explicit reasoning steps during training. Notably, CoT-trained models resolve intermediate results at shallower layers compared to non-CoT counterparts, freeing up deeper layers to specialize in subsequent reasoning steps. A key insight is that CoT training teaches models how to think-by fostering compositional reasoning-rather than merely what to think, through the provision of correct answers alone. This paper offers valuable insights for designing CoT strategies to enhance LLMs' reasoning robustness 1 .

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2502.04667")
get_code_for_paper("2502.04667")
have("2502.04667")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2502.04667.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2502.04667.svg)](https://syntology.ai/paper/2502.04667)

Connect an agent — have() is free.