Abstract
This paper establishes a theoretical foundation for Length Generalization (LG)—the ability of a model trained on short reasoning problems to solve significantly longer ones. By modeling reasoning as a Directed Acyclic Graph (DAG), the authors identify two critical conditions for perfect generalization: a finite input space for reasoning steps and a property termed $(n, r)$-consistency. The study proves that with appropriately structured Chain-of-Thought (CoT) representations, a vanilla Transformer can achieve 100% accuracy on tasks like multi-digit addition and multiplication, regardless of the problem length.
Introduction
Large Language Models (LLMs) have demonstrated impressive reasoning capabilities, yet they frequently encounter a "length generalization gap." A model proficient at 4-digit multiplication often fails when presented with 10-digit numbers. While techniques like Chain-of-Thought (CoT) or "scratchpads" provide intermediate steps, they do not inherently guarantee extrapolation to unseen lengths. This research moves beyond empirical observation to define the mathematical conditions under which a model can learn to reason in a way that scales universally.
Theoretical Framework: Reasoning as a DAG
The authors conceptualize the reasoning process as a Directed Acyclic Graph (DAG). In this model, each node represents a discrete reasoning step, and edges represent dependencies between these steps. The process is decomposed into three components:
- The Causal Function: The logic governing a single reasoning step (e.g., $2 + 3 = 5$).
- The Structure: The mechanism for identifying which elements must be processed next.
- The Recursive Formula: The iterative application of the causal function until a solution is reached.
Conditions for Generalization
To achieve perfect LG, the theory introduces two pivotal concepts regarding the spatial relationship of data in the reasoning sequence:
- Maximal Input Element Distance ($R$): This is the maximum distance between any two elements involved in a single reasoning step. If $R$ is finite, the model only requires a local "window" to determine the subsequent step.
- $(n, r)$-consistency: This condition addresses scenarios where $R$ might be infinite (e.g., in standard addition where the operator and operands are far apart). It posits that if an element's role in the next step can be uniquely determined by observing $n$ small windows of size $r$, the problem remains learnable with perfect LG.
Experimental Validation
The authors tested their theory using five synthetic benchmarks: continuous functions (Arctan), finite field arithmetic ($F_7$), Parity, and multi-digit Addition/Multiplication.
Key Insights
- Finiteness is Mandatory: Models fail on continuous tasks like
arctanbecause the input space is infinite, preventing the causal function from being "well-learned." - Representation is the Bottleneck: LG failure is often a consequence of data formatting rather than model capacity. Standard 1-line addition (e.g.,
123+456=...) has an infinite $R$ and lacks $(n, r)$-consistency because the distance between digits grows with length. - Designing for Consistency: By adopting multi-line CoT formats with position indicators, the authors successfully reduced $R$ to a finite value or satisfied $(n, r)$-consistency. Under these conditions, vanilla Transformers with relative position encoding achieved 100% accuracy on extrapolated lengths.
Conclusion
The study demonstrates that standard Transformer architectures are sufficient for length generalization, provided the training data is structured to meet specific consistency conditions. While the current theory is limited to DAG-representable reasoning and supervised CoT, it provides a rigorous roadmap for designing data formats that enable models to extrapolate beyond their training distribution. Future work will explore how models might autonomously discover these consistent reasoning structures.
Summary updated