Universal Length Generalization with Turing Programs
Kaiying Hou, David Brandfonbrener, Sham M. Kakade, Samy Jelassi, Eran Malach
Abstract
Length generalization refers to the ability to extrapolate from short training sequences to long test sequences and is a challenge for current large language models. While prior work has proposed some architecture or data format changes to achieve length generalization, these proposals typically apply to a limited set of tasks. Building on prior scratchpad and Chain-of-Thought (CoT) techniques, we propose Turing Programs, a novel CoT strategy that decomposes an algorithmic task into steps mimicking the computation of a Turing Machine. This framework is both universal, as it can accommodate any algorithmic task, and simple, requiring only copying text from the context with small modifications. We show that by using Turing Programs, we obtain robust length generalization on a range of algorithmic tasks: addition, multiplication and in-context SGD. We then demonstrate that transformers achieve length generalization on random Turing Programs, suggesting that length generalization is possible for any algorithmic task. Finally, we theoretically prove that transformers can implement Turing Programs, constructing a simple RASP (Weiss et al. [53]) program that simulates an arbitrary Turing machine.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
16 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Transformers Provably Learn Chain-of-Thought Reasoning with Length Generalization cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Transformers Provably Learn Chain-of-Thought Reasoning with Length Generalization cites Faith and Fate: Limits of Transformers on Compositionality
- Softmax Transformers are Turing-Complete cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Softmax Transformers are Turing-Complete cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Beyond Single-Task: Robust Multi-Task Length Generalization for LLMs cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Beyond Single-Task: Robust Multi-Task Length Generalization for LLMs cites Faith and Fate: Limits of Transformers on Compositionality
- Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation cites Language Models are Few-Shot Learners
- Solving Quantitative Reasoning Problems with Language Models cites Language Models are Few-Shot Learners
- Solving Quantitative Reasoning Problems with Language Models cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Born a Transformer - Always a Transformer? On the Effect of Pretraining on Architectural Abilities cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Born a Transformer - Always a Transformer? On the Effect of Pretraining on Architectural Abilities cites Language Models are Few-Shot Learners
- Born a Transformer - Always a Transformer? On the Effect of Pretraining on Architectural Abilities cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- The Imitation Game: Turing Machine Imitator is Length Generalizable Reasoner cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- The Imitation Game: Turing Machine Imitator is Length Generalizable Reasoner cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Faith and Fate: Limits of Transformers on Compositionality cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Faith and Fate: Limits of Transformers on Compositionality cites Language Models are Few-Shot Learners
- Faith and Fate: Limits of Transformers on Compositionality cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
Cited by top-tier papers16
- Transformers Provably Learn Chain-of-Thought Reasoning with Length GeneralizationYu Huang, Zixin Wen, Aarti Singh, Yuejie Chi et al.NeurIPS 2025 · 22 citations
- Softmax Transformers are Turing-CompleteHongjian Jiang, Michael Hahn, Georg Zetzsche, Anthony W. LinICLR 2026 · 12 citations
- Beyond Single-Task: Robust Multi-Task Length Generalization for LLMsYi Hu, Shijia Kang, Haotong Yang, Haotian Xu et al.NeurIPS 2025 · 6 citations
- Born a Transformer - Always a Transformer? On the Effect of Pretraining on Architectural AbilitiesMayank Jobanputra, Yana Veitsman, Yash Raj Sarrof, Aleksandra Bakalova et al.NeurIPS 2025 · 6 citations
- The Imitation Game: Turing Machine Imitator is Length Generalizable ReasonerZhouqi Hua, Wenwei Zhang, Chengqi Lyu, Yuzhe Gu et al.ICLR 2026 · 4 citations
Builds on25
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
- Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
- Solving Quantitative Reasoning Problems with Language ModelsAitor Lewkowycz, Anders Andreassen, David Dohan, Ethan Dyer et al.NeurIPS 2022 · 2,039 citations
- Train Short, Test Long: Attention with Linear Biases Enables Input Length ExtrapolationOfir Press, Noah A. Smith, Mike LewisICLR 2022 · 1,168 citations
- Faith and Fate: Limits of Transformers on CompositionalityNouha Dziri, Ximing Lu, Melanie Sclar, Xiang Lorraine Li et al.NeurIPS 2023 · 728 citations
Related papers
- What Algorithms can Transformers Learn? A Study in Length GeneralizationHattie Zhou, Arwen Bradley, Etai Littwin, Noam Razin et al.ICLR 2024 · 189 citations
- Generalizing Reasoning Problems to Longer LengthsChangnan Xiao, Bing LiuICLR 2025
- Exploring Length Generalization in Large Language ModelsCem Anil, Yuhuai Wu, Anders Andreassen, Aitor Lewkowycz et al.NeurIPS 2022 · 267 citations
- Arithmetic Transformers Can Length-Generalize in Both Operand Length and CountHanseul Cho, Jaeyoung Cha, Srinadh Bhojanapalli, Chulhee YunICLR 2025
- Looped Transformers for Length GeneralizationYing Fan, Yilun Du, Kannan Ramchandran, Kangwook LeeICLR 2025
