The Role of Sparsity for Length Generalization in Transformers

Noah Golowich, Samy Jelassi, David Brandfonbrener, Sham M. Kakade, Eran Malach
2/24/2025
cs.LGcs.AIcs.CL
transformer-attention

No confident code implementation found for this paper.

Abstract

Training large language models to predict beyond their training context lengths has drawn much attention in recent years, yet the principles driving such behavior of length generalization remain underexplored. We propose a new theoretical framework to study length generalization for the next-token prediction task, as performed by decoder-only transformers.

Show full abstract

Conceptually, we show that length generalization occurs as long as each predicted token depends on a small (fixed) number of previous tokens. We formalize such tasks via a notion we call $k$-sparse planted correlation distributions, and show that an idealized model of transformers which generalize attention heads successfully length-generalize on such tasks. As a bonus, our theoretical model justifies certain techniques to modify positional embeddings which have been introduced to improve length generalization, such as position coupling. We support our theoretical results with experiments on synthetic tasks and natural language, which confirm that a key factor driving length generalization is a ``sparse'' dependency structure of each token on the previous ones. Inspired by our theory, we introduce Predictive Position Coupling, which trains the transformer to predict the position IDs used in a positional coupling approach. Predictive Position Coupling thereby allows us to broaden the array of tasks to which position coupling can successfully be applied to achieve length generalization.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{golowich2025role,
  title  = {The Role of Sparsity for Length Generalization in Transformers},
  author = {Noah Golowich and Samy Jelassi and David Brandfonbrener and Sham M. Kakade and Eran Malach},
  year   = {2025},
  eprint = {2502.16792},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2502.16792v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2502.16792.svg)](https://codeofpaper.com/paper/2502.16792)

Discussion