Exploring Length Generalization in Large Language Models
Cem Anil, Yuhuai Wu, Anders Andreassen, Aitor Lewkowycz, Vedant Misra, Vinay V. Ramasesh, Ambrose Slone, Guy Gur-Ari, Ethan Dyer, Behnam Neyshabur
Abstract
The ability to extrapolate from short problem instances to longer ones is an important form of out-of-distribution generalization in reasoning tasks, and is crucial when learning from datasets where longer problem instances are rare. These include theorem proving, solving quantitative mathematics problems, and reading/summarizing novels. In this paper, we run careful empirical studies exploring the length generalization capabilities of transformer-based language models. We first establish that naively finetuning transformers on length generalization tasks shows significant generalization deficiencies independent of model scale. We then show that combining pretrained large language models' in-context learning abilities with scratchpad prompting (asking the model to output solution steps before producing an answer) results in a dramatic improvement in length generalization. We run careful failure analyses on each of the learning modalities and identify common sources of mistakes that highlight opportunities in equipping language models with the ability to generalize to longer problems.
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.
120 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
- Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation cites Language Models are Few-Shot Learners
- The Impact of Positional Encoding on Length Generalization in Transformers cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- The Impact of Positional Encoding on Length Generalization in Transformers cites Language Models are Few-Shot Learners
- The Impact of Positional Encoding on Length Generalization in Transformers cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- The Alignment Problem from a Deep Learning Perspective cites Language Models are Few-Shot Learners
- Hidden Progress in Deep Learning: SGD Learns Parities Near the Computational Limit 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
- 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 papers120
- Faith and Fate: Limits of Transformers on CompositionalityNouha Dziri, Ximing Lu, Melanie Sclar, Xiang Lorraine Li et al.NeurIPS 2023 · 728 citations
- The Impact of Positional Encoding on Length Generalization in TransformersAmirhossein Kazemnejad, Inkit Padhi, Karthikeyan Natesan Ramamurthy, Payel Das et al.NeurIPS 2023 · 444 citations
- Titans: Learning to Memorize at Test TimeAli Behrouz, Peilin Zhong, Vahab MirrokniNeurIPS 2025 · 368 citations
- The Alignment Problem from a Deep Learning PerspectiveRichard Ngo, Lawrence Chan, Sören MindermannICLR 2024 · 296 citations
- Hidden Progress in Deep Learning: SGD Learns Parities Near the Computational LimitBoaz Barak, Benjamin L. Edelman, Surbhi Goel, Sham M. Kakade et al.NeurIPS 2022 · 220 citations
Builds on11
- 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
- Understanding the failure modes of out-of-distribution generalizationVaishnavh Nagarajan, Anders Andreassen, Behnam NeyshaburICLR 2021 · 205 citations
Related papers
- Extrapolation by Association: Length Generalization Transfer In TransformersZiyang Cai, Nayoung Lee, Avi Schwarzschild, Samet Oymak et al.NeurIPS 2025 · 13 citations
- Generalizing Reasoning Problems to Longer LengthsChangnan Xiao, Bing LiuICLR 2025
- Language Models Need Inductive Biases to Count InductivelyYingshan Chang, Yonatan BiskICLR 2025
- Case-Based or Rule-Based: How Do Transformers Do the Math?Yi Hu, Xiaojuan Tang, Haotong Yang, Muhan ZhangICML 2024 · 34 citations
- How Do Position Encodings Affect Length Generalization? Case Studies On In-Context Function LearningDi-Nan Lin, Jui-Feng Yao, Kun-Da Wu, Hao Xu et al.AAAI 2025 · 1 citation
