Introduction
Why do Transformers master counting but fail at basic addition when the numbers get longer? This paper introduces the RASP-Generalization Conjecture, proposing that Transformers are biased toward learning the "shortest" program possible in a specialized language called RASP-L. If a task admits a short, parallelizable RASP-L solution, the Transformer will likely learn it and generalize to any length; if not, it resorts to "shortcut" patterns that break on longer inputs.
The Challenge of Length Generalization
Transformers are the backbone of modern AI, yet they exhibit a frustrating "brittleness" in algorithmic reasoning. While a model might be perfect at adding two-digit numbers, its accuracy often plummets when asked to add five-digit numbers—a phenomenon known as a failure in length generalization.
The core question is: Is this failure an inherent flaw of the Transformer architecture, or is it a property of the algorithms we expect them to learn? Previous research offered scattered evidence, sometimes showing success (like in "induction heads") and sometimes total failure (like in parity or addition). This paper seeks a unifying framework to predict when and why a Transformer will successfully generalize to longer sequences.
The RASP-L Framework
To understand Transformer capabilities, the authors leverage RASP (Restricted Access Sequence Processing), a domain-specific programming language designed to mirror the computational constraints of a Transformer (where each line of code roughly corresponds to one attention layer).
They refine this into RASP-L, a "learnable" subset of the language that enforces:
- Bounded Integers: To avoid arbitrary precision issues.
- Restricted Index Arithmetic: Forbidding complex operations on positions (like division) that Transformers struggle to decode from positional embeddings.
The researchers trained standard decoder-only Transformers from scratch on various algorithmic tasks. Crucially, they used a "packing and shifting" training strategy to ensure the models didn't overfit to specific absolute positions, forcing them to learn relative, algorithmic relationships.
Key Insights: Simplicity Bias and Parallelism
- The Simplicity Bias: Transformers don't just learn any function that fits the data; they have a "simplicity bias" toward the shortest RASP-L program. If the shortest program that fits the training data also happens to be the "true" algorithm that works for all lengths, the model generalizes.
- Parallelism is the Bottleneck: Transformers are inherently parallel. Tasks that require sequential "state updates"—like carrying a one in addition or keeping a running tally in parity—are fundamentally "unnatural" for the architecture.
- The "Outer Loop" of Autoregression: The authors point out that while a single forward pass of a Transformer is parallel and constant-depth, the autoregressive process (predicting one token at a time) acts as an "outer loop." This is why scratchpads work: they allow the model to use the context as a temporary memory to perform sequential steps.
Experimental Results
The study uses several synthetic algorithmic benchmarks to test these hypotheses, categorizing tasks by their RASP-L complexity.
- Easy Tasks (Short RASP-L programs): Models trained on sequences up to length 50 generalized nearly perfectly to length 100 and beyond for tasks like Counting and finding the Mode. These tasks have very short RASP-L representations. Similarly, copying sequences of unique tokens generalizes well, whereas copying repeating tokens fails.
- When Scratchpads Hurt: Not all intermediate reasoning helps. If a scratchpad format requires the model to perform more complex indexing or internal sorting (increasing the RASP-L complexity), it can actually hinder generalization compared to no scratchpad at all. As seen in the Mode task results, adding a scratchpad drastically reduced test accuracy.
- The Addition Breakthrough: Standard addition fails length generalization (0% accuracy). However, by reversing the output order (to handle carries causally) and adding "index hints," the authors achieved the first known instance of a Transformer trained from scratch generalizing to long-form decimal addition.
- Parity: By using a scratchpad that "unrolls" the parity calculation into a step-by-step running total, the model achieved 100% generalization on length-50 sequences after being trained only on lengths up to 30.
- Data Diversity Matters: Generalization only occurred when the training set included a diverse range of lengths. Training on a single fixed length led the model to learn "shortcuts" that failed immediately on out-of-distribution lengths.
Limitations and Future Work
The authors acknowledge that RASP-L is a heuristic tool, not a perfect mathematical mapping. It currently struggles to represent numerical algorithms like gradient descent or linear regression, which involve continuous values rather than discrete symbols.
Additionally, while "program length" is a powerful predictor, finding the minimal RASP-L program for a task is computationally hard (related to Kolmogorov complexity). Future work could involve formalizing the "Transformer-complexity" of tasks and exploring how these insights apply to the massive, multi-task training of LLMs.
Summary updated