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. * Equal senior contribution. Preprint. Under review.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 03b7e3eb-82fc-43cc-9967-b2bb42de08b6Cited by top-tier papers15
- Transformers Provably Learn Chain-of-Thought Reasoning with Length GeneralizationYu Huang, Zixin Wen, Aarti Singh, Yuejie Chi et al.NeurIPS 2025 · 22 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
- To Infinity and Beyond: Tool-Use Unlocks Length Generalization in State Space ModelsEran Malach, Omid Saremi, Sinead Williamson, Arwen Bradley et al.ICLR 2026 · 3 citations
Builds on24
- 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
- Softmax Transformers are Turing-CompleteHongjian Jiang, Michael Hahn, Georg Zetzsche, Anthony W. LinICLR 2026 · 12 citations
- 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
