arXiv:2610.35715cs.LGOct 2026

Manuscript Offprint

arXiv:2610.35715

Quantitative Generalization Bounds for Multi-Layer Transformers: A Few Long Strings can Beat Many Short Ones

Marius Henry, Michael Rizvi-Martel, Michael Hahn

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Transformer-based language models exhibit an astonishing capacity to generalize to longer and more difficult problem instances than those seen in training. However, theoretical understanding of this phenomenon still lags behind. Unlike most machine learning models, the generalisation abilities of transformers inherently require considering two axes. On one hand, one must examine in-distribution statistical generalisation, which concerns the ability of a model to broaden a function from training samples to novel samples of the same distribution. On the other hand, given the sequential nature of language data, one must also consider length generalisation, which reflects whether a model trained on inputs of a given length can extrapolate to longer ones. These two notions have mostly been studied separately, leaving open how they interact. In this work, we give a joint treatment of both axes for fixed-precision transformers. We give generalisation guarantees in terms of the parameter sizes of the involved models, as well as the quantization space and the alphabet size that supply the sequences. Finally, we illustrate how the requirements in the sample count and training length trade off. In particular, we find that increasing training length can be exponentially more efficient than increasing the sample size. Experiments support predictions of the theory.

1 INTRODUCTION

The success of large language models (LLMs) has prompted research into the learning and generalization properties of the underlying transformer architecture. Classical statistical learning theory provides a wealth of techniques that bound the generalization error as a function of the data size and the complexity of the hypothesis class. Recent work has brought these to bear on transformers (Covering numbers: Edelman et al. (2022); Trauger & Tewari (2024), Bayesian methods: Lintilhac & Shaikh (2026); Rizvi-Martel et al. (2026), VC Dimension: Yang et al. (2026c), inter alia). These results primarily address the i.i.d. regime – for transformers, this in particular implies that the test inputs are drawn from the same length distribution as the training inputs.

However, for transformer learning theory, the i.i.d. paradigm is arguably insufficient: it is highly desirable to understand when transformers can extrapolate to sequences longer than seen during training. This phenomenon is referred to as length-generalization (e.g. Bhattamishra et al., 2020; Anil

Figure

Token Budget: 3k 5k 7k 9k 11k

Figure 1: Our results predict that increasing the length of the training words can be much more token-efficient than increasing their number; test accuracy for the language A15A_{15} (Sec. 5) on words five times longer than the training length. We highlight in red the highest-accuracy cell at five different training token budgets.

et al., 2022; Kazemnejad et al., 2023), and is understood to be diagnostic of when a transformer actually learns an underlying algorithmic solution, as opposed to length-dependent heuristics (e.g. Zhou et al., 2024; Huang et al., 2026). It also indicates when LLMs can be expected to perform a task reliably across long contexts (Jobanputra et al., 2025).

Length generalization is governed by two quantities: the number of training samples, and their length. Sample count determines how reliably the training data pins down the target function, as in classical statistical learning theory; sample length determines how well the model extrapolates, since the longest input length at which the target function's behavior is observed dictates to which point a model will extrapolate beyond it. For a given target function and learning procedure, we thus need to consider not only its sample complexity (the required number of training samples), but also its length complexity (the required length of training samples).

Here, we take up the question of providing quantitative bounds on generalization along both axes for multi-layer transformers in the fixed-precision regime. We study the questions:

How do properties of a target function influence the length complexity and data complexity of the task?

When both sample size and length are bounded, how do they trade off? In particular, under a fixed token budget, how to best allocate sample size and length?

and address these by providing generalization bounds depending on both sample size and input length. The main idea is that training length determines which behaviors become observable; sample size determines how reliably those behaviors are learned. Below a task-dependent length threshold, some competing behaviors cannot be distinguished. Around the relevant transition, longer examples can make informative events much more common; increasing length can thus strongly reduce sample complexity in this regime. Beyond that transition, the benefit of additional length diminishes and additional independent examples matter more.