Generalizing Reasoning Problems to Longer Lengths

Changnan Xiao, Bing LiuICLR 2025

Large Language Models (LLMs) are surprisingly adept at reasoning, but they frequently hit a notorious "glass ceiling": Length Generalization (LG). If you train a model to add 4-digit numbers, it often fails miserably when asked to add 20-digit numbers. While Chain-of-Thought (CoT) prompting helps models solve complex problems by breaking them down into steps, it has historically failed to solve this extrapolation problem.

In this paper, researchers present a theoretical framework and a practical "tagging" method to ensure Transformers can generalize reasoning tasks to arbitrary lengths. By identifying the root cause of length generalization failure as a lack of "sufficient bias" in learning, the authors propose a condition called $(n, r)$-consistency for CoT schemes. They prove that if a reasoning problem meets this condition, a Transformer can be guaranteed to achieve perfect length generalization.

The Extrapolation Problem

The core issue in length generalization is extrapolation. Standard machine learning assumes training and testing data come from the same distribution. However, in reasoning, we want a model to learn a rule (like addition) on small instances and apply it to much larger ones.

Existing research shows that while CoT helps a model "interpolate" (solve problems of the same length as training), it fails to extrapolate. For example, a model might learn to use positional embeddings as a shortcut to solve 5-digit multiplication. When it encounters a 50-digit number, those positional shortcuts no longer exist or point to the wrong data, causing the reasoning chain to break entirely.

Theoretical Framework and Methods

The paper approaches the problem through both a theoretical lens and architectural construction:

  1. The Root Cause Theorem: The authors mathematically prove that for any function learned on length $N$, there are infinite ways to extend it to length $N' > N$. Without a specific "bias" to guide the model toward the logically correct extension, the model is almost certain to fail.
  2. $(n, r)$-Consistency: This is the paper's primary innovation. It defines a class of CoT schemes where the next reasoning step is determined solely by a local context of $n$ intervals, each of length $r$. Crucially, this context must be consistent: the same local pattern must always lead to the same output, regardless of where it appears in a sequence or how long that sequence is.
  3. Tagging as a Solution: To achieve this consistency, the authors introduce "tags" into the CoT steps. For addition, instead of just showing the carry, they use tags (e.g., $I, J, K$) to explicitly point the model to which digits are being operated on. This forces the model to learn the rule of the operation rather than relying on a positional shortcut.
  4. Transformer Construction: They provide a proof-of-existence showing that an $n$-layer Transformer can implement the logic required to follow these $(n, r)$-consistent rules.

Datasets & Experimental Setup

The authors evaluated their theory on five fundamental reasoning tasks, creating specific CoT schemes for each:

  • Arithmetic in $F_7$: Calculations within a finite prime field (mod 7).
  • Parity: Determining if a bitstring has an even or odd number of 1s.
  • Addition: Standard integer addition.
  • Multiplication: Multi-line integer multiplication.
  • Division: Integer division (a particularly difficult task for LLMs).

They compared "standard" CoT against their proposed consistent CoT across progressively longer test sets to stress-test extrapolation capabilities.

Experimental setup for training and length generalization tests.

Key Insights

  • The Death of Positional Shortcuts: Models fail LG because they rely on absolute or relative positions that shift when the input grows. By using $(n, r)$-consistent CoT, the model is forced to rely on pattern-matching rather than position-counting.
  • Local Rules, Global Results: Reasoning is essentially the application of local rules. If the CoT is designed so that every single token prediction is based on a fixed-size local "window" of information, the total length of the string becomes irrelevant to the model's logic.
  • Tags are "Pointers": The tags act as a form of hard-coded attention guidance. They tell the model exactly what to look at, effectively turning a global reasoning problem into a series of local, consistent lookups.

Key Results

The results are striking, particularly for tasks that have historically stumped Transformers:

  • Perfect Generalization: On tasks like addition, parity, and arithmetic, the $(n, r)$-consistent models achieved 100% accuracy on test sets significantly longer than the training sets (e.g., training on 8 digits, testing on 100).
  • Multiplication and Division: The authors report the first known instance of a Transformer achieving perfect LG for multiplication and near-perfect LG for division at these extended lengths.
  • Failure of Standard CoT: In stark contrast, models trained with standard CoT (without the consistency-ensuring tags) saw their accuracy drop to near zero as soon as the test length exceeded the training length.

Limitations and Future Work

While the theoretical guarantees are strong, the authors note a few practical limitations:

  • Manual CoT Design: Currently, the "consistent" CoT schemes (the tags and formatting) must be designed manually for each problem. Automating the discovery of these schemes is a major next step.
  • Attention Dilution: As sequences get extremely long (e.g., 1000+ tokens), the "dense" nature of standard attention means the model's focus can become diluted by noise from irrelevant tokens, leading to slight performance drops in extreme stress tests.
  • Complexity vs. Capacity: The proof shows that an $n$-layer Transformer can solve an $(n, r)$-consistent problem, but it doesn't guarantee that a model will always learn the optimal parameters via standard SGD without careful initialization or a data curriculum.

Summary updated

BibTeX
@inproceedings{xiao2025generalizing,
  author = {Changnan Xiao and Bing Liu},
  title = {{Generalizing Reasoning Problems to Longer Lengths}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=zpENPcQSj1},
}
Figure