Understanding the Out-of-Distribution Generalization of Chain-of-Thought Reasoning in LLMs

Nuojing Liang, Xiaotong Yuan, Pan ZhouNeurIPS 2026

TL;DR

Ask a Large Language Model (LLM) to jump straight from a complex problem to the final answer, and it hits a wall the moment it encounters something unfamiliar. Ask it to "think step-by-step" via Chain-of-Thought (CoT), and it suddenly solves unseen, multi-step puzzles. This paper provides the mathematical blueprint for why this happens: CoT transforms impossible out-of-distribution leaps into chains of familiar, reusable micro-steps, keeping statistical learning errors surprisingly tame as reasoning chains grow longer.

What Problem Does This Paper Address?

Imagine you know how to translate English to French (apple $\rightarrow$ pomme), and French to German (pomme $\rightarrow$ Apfel), but you have never seen an English-to-German dictionary. Without intermediate steps, translating apple directly to Apfel is a complete shot in the dark—an out-of-distribution (OOD) task with zero direct training examples.

Figure 1: CoT as compositional OOD generalization. Left: without CoT, the model must learn a direct mapping from input z0 to final answer ∆zT , whose target distribution may be unavailable during training. With CoT, the same predictor is repeatedly applied to in-distribution step distributions, mapping each state zi−1 to update ∆zi. Right: a two-hop translation example solves an unseen English-to-German query by composing learned English-to-French and French-to-German steps.

Empirically, we know that training or prompting LLMs with Chain-of-Thought allows them to bridge these gaps. Prior theoretical work has shown that CoT increases the "effective depth" or raw computational power of Transformers. However, we still lacked a rigorous generalization theory for modern autoregressive Next-Token Prediction (NTP): if a model only learns simple, atomic transitions during training, why doesn't its statistical error blow up when chaining $T$ of those steps together at test time?

Methods

The authors frame multi-step reasoning as compositional OOD generalization. Instead of learning a direct mapping from initial input ($z_0$) to final answer ($\Delta z_T$), the LLM uses a single, shared predictor over a sliding context window. At each step $i$, it reads the current state, outputs $k$ tokens representing the next incremental update ($\Delta z_i$), appends them to the context, and repeats this $T$ times.

To bound the error of this setup, the authors combine three mathematical tools:

  1. Error Decomposition: They connect "teacher-forced" training (where the model sees ground-truth prefixes) to "free-running" test generation (where the model feeds on its own argmax predictions). Using a clipped cross-entropy loss, they prove a local error floor: any discrete token mistake incurs at least $(\log 2)/k$ loss, allowing them to bound the final OOD risk by the sum of individual in-distribution step risks.
  2. Pooled Rademacher Complexity: Rademacher complexity measures how easily a model class can memorize random noise—a standard gauge of overfitting risk. Instead of analyzing all $T$ steps separately, the authors exploit the fact that the exact same LLM weights execute every step, pooling all $N = nT$ training sequences ($n$ samples per step) together.
  3. Next-Token Prediction Specialization: They adapt matrix-covering bounds for Transformer decoders specifically to the final $k$ target tokens of each atomic step, capturing explicit dependencies on model parameters, layer count, and context length.

Datasets

  • Atom-Task (Newly Introduced): A clean, synthetic benchmark built to isolate pure compositional reasoning from memorized world knowledge. Using a six-symbol Greek alphabet ($\alpha, \beta, \gamma, \delta, \varepsilon, \omega$), models (specifically Qwen3-4B) must sequentially apply combinations of five atomic string operations: Reverse, Substitute, Duplicate, Deduplicate, and Rotate. Models are trained on short chains (1, 3, or constrained 5-step tasks) and tested on held-out sequences up to 9 steps long.
  • GSM8K: A standard benchmark of grade-school math word problems used to verify that the theoretical insights hold up in natural-language mathematical reasoning (detailed in the paper's appendix).

Key Insights and Ideas

  • Weight sharing tames reasoning depth ($\sqrt{T}$ vs. $T$): If you used $T$ separate predictors for a $T$-step chain, your statistical estimation error—the penalty paid for having finite training data—would grow linearly as $\mathcal{O}(T/\sqrt{n})$. Because CoT reuses one shared predictor across all steps, it effectively pools the data across tasks. The estimation error scales sublinearly as $\widetilde{\mathcal{O}}(k\sqrt{T/n})$—and the authors prove via a clever XOR-coupled construction that this $\sqrt{T/n}$ rate is mathematically tight (you can't beat it).
  • The inference penalty is depth-independent: Moving from soft training probabilities to hard token generation across $T$ steps scales the summed step-level risks by a multiplicative factor of $\mathcal{O}(k)$ (where $k$ is tokens per step), not by $T$. (Though, naturally, summing $T$ non-zero step risks means total error still accumulates if individual steps are imperfect).
  • State tracking is the linchpin: Because the model operates like a Markov chain over a sliding context window, CoT only works if each intermediate text state $z_{i-1}$ explicitly preserves all information needed for the next step (e.g., both the updated string and the remaining queue of operations). Drop the state, and the theoretical guarantees—and empirical accuracy—evaporate.

Key Results

On Atom-Task, CoT enables dramatic short-to-long generalization while standard No-CoT training collapses:

Table 1: Accuracy (%) by training data and test steps. All entries are means over 3 seeds (42, 2026, 12345); standard deviations are shown as subscripts.
  • Length Extrapolation: Trained on a mix of 3-step and constrained 5-step chains (Mix 3+5), Qwen3-4B with CoT achieves 90.40% accuracy on unseen 9-step problems. Without CoT, accuracy craters to 5.73%.
  • Unseen Combinations: When specific operations (like Reverse or Rotate) are completely excluded from multi-step training data and shown only in isolated 1-step examples, CoT models still seamlessly weave them into 9-step test chains (achieving 87.13% for Reverse and 80.13% for Rotate, vs. 5.53% and 9.73% without CoT).
  • State Tracking Ablation: When the authors masked out explicit state tracking (hiding the remaining task list and intermediate inputs with [...]), 7-step test accuracy dropped sharply from 85.37% down to 67.56%.

Limitations and Future Work

The theoretical framework models classic, supervised Next-Token Prediction where clean intermediate reasoning steps are explicitly provided during training, and decoding is a deterministic argmax rollout. It does not yet cover modern adaptive reasoning paradigms—such as reinforcement fine-tuning (like DeepSeek-R1), self-correction, or test-time tree search—where models dynamically explore, backtrack, or get rewarded for discovering their own latent trajectories. Extending this compositional risk decomposition to search-and-RL regimes is highlighted as a natural next step.

Summary updated

Abstract

Chain-of-Thought (CoT) reasoning substantially improves Large Language Models (LLMs), yet its out-of-distribution (OOD) generalization mechanism remains theoretically underexplored. We study CoT as compositional OOD generalization: the target task lacks complete reasoning trajectories or direct input-output pairs, while training provides only in-distribution (ID) atomic step data. We show that CoT generalizes by repeatedly applying a shared single-step predictor to compose reusable ID transitions. Theoretically, let $T$ denote the number of reasoning steps in the target task, $n$ the number of training samples per sub-task, and $k$ the number of output tokens per step; then the OOD task risk is controlled by the sum of the ID sub-task risks, scaled by a coefficient of order $\mathcal{O}(k)$ that is independent of $T$, although the summed risk itself may still grow with $T$. A Rademacher-complexity analysis further shows that the estimation term is of order $\mathcal{O}(\sqrt{T/n})$, rather than linear in $T$, due to predictor sharing under a uniform capacity control on the shared class. For autoregressive Next-Token Prediction, the final-task risk is bounded by the best-in-class step-level risk scaled by the same coefficient of order $\mathcal{O}(k)$, plus an estimation term of order $\widetilde{\mathcal{O}}\big(k\sqrt{T/n}\big)$. A parity-coupled construction further shows that, for the sub-task empirical risk minimizer, the expected final-task risk is at least the best in-class risk plus $\Omega(\sqrt{T/n})$ when $T\le n$. Experiments on Atom-Task and GSM8K support the theory: CoT enables short-to-long and compositional generalization, while explicit state tracking is crucial. Our code is available at https://github.com/maxliang114514/CoT-OOD.
BibTeX
@inproceedings{liang2026understanding,
  author = {Nuojing Liang and Xiaotong Yuan and Pan Zhou},
  title = {{Understanding the Out-of-Distribution Generalization of Chain-of-Thought Reasoning in LLMs}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=CwFstPZgCZ},
}
Figure