Abstract
Transformers frequently fail to generalize to sequence lengths beyond their training distribution. This paper introduces length generalization transfer, a phenomenon where a model learns to handle longer inputs for a target "main" task by being concurrently trained on a structurally related "auxiliary" task at those extended lengths. We demonstrate that this transfer relies on task association and internal circuit sharing, suggesting that large-scale pretraining may provide the necessary computational scaffolding for emergent reasoning at scale.
Introduction
Standard Transformer architectures are notorious for their inability to extrapolate from short training examples to longer test cases. For instance, a model trained on 10-digit addition often fails catastrophically when presented with 20-digit problems. While previous efforts have focused on architectural modifications like advanced positional encodings, this work investigates task association. We ask: can a model "borrow" the ability to process long sequences from one task and apply it to another?
Experimental Setup and Tasks
The researchers utilized a multitask training regime pairing a Main Task (short sequences) with Auxiliary Tasks (longer sequences). The architecture consisted of Llama-style decoder-only Transformers equipped with Rotary Positional Embeddings (RoPE).
The study evaluated three primary categories of algorithmic tasks designed to test specific logic:
- Arithmetic: Including
reverse add,reverse subtract, and Chain-of-Thought (CoT) multiplication. - String Manipulation: Tasks such as
string copy,Multi-Query Associative Recall (MQAR), and capitalization/reversal. - Maze Navigation: Simulating
DFS traceandshortest pathalgorithms.
Key Insights: Extrapolation by Association
The core finding is that length generalization is heavily dependent on data composition. If two tasks share a similar algorithmic structure, the model can learn "how-to-scale" logic from the long auxiliary task and apply it to the short main task.
Task Relatedness and Structural Alignment
Transfer is not a universal byproduct of multitask training. When paired with unrelated tasks, models fail to generalize. Successful transfer requires "structural alignment"—for example, pairing reverse add with reverse subtract works, while pairing it with a simple copy task does not.
Pretraining as a Universal Scaffolder
Analysis using SmolLM-360M checkpoints revealed that natural language pretraining acts as an implicit auxiliary task. As pretraining progresses, the model's ability to extrapolate on synthetic tasks (like arithmetic or mazes) improves significantly, even without direct exposure to those formats.
Mechanistic Evidence: Circuit Sharing
Using activation patching, the authors found that successful transfer correlates with the reuse of specific attention heads. When the model employs the same internal "machinery" for both the main and auxiliary tasks, the length-handling capabilities of the auxiliary task are effectively inherited by the main task.
Results and Discussion
In arithmetic, a model trained on reverse add up to length 16 typically fails at length 17. However, when co-trained with reverse subtract at length 32, the reverse add performance remains high up to length 32. Similar results were observed in maze navigation, where training on shortest path (length 64) enabled the model to solve DFS trace at length 64.
The study also highlights the importance of positional encoding; RoPE significantly outperformed "No Positional Encoding" (NoPE) in facilitating this transfer. However, the effect is sensitive to the length ratio between tasks (ideally between 0.5 and 2) and can be unstable across different random seeds.
Conclusion
Length generalization transfer suggests that the "reasoning" capabilities of large language models may emerge from the structural overlap between diverse tasks encountered during pretraining. Future work should investigate if this scaffolding effect extends to more complex, non-deterministic reasoning challenges and shifts in task complexity.
Summary updated