Critical Sequence Length: A Note on How Document Structure Bounds Gradient-Noise Reduction
Abstract
LLM pre-training commonly treats every token in a training sequence as an independent sample of the gradient. Under this assumption, gradient noise scales as 1/(BS) for batch size B and sequence length S, so B is halved whenever S is doubled. We show that this rule breaks down beyond a certain length, and that the point where it breaks down can be measured. Guided by a simple model of how gradient noise arises in next-token training, we split the noise into two parts: a per-token term that averages away as 1/S, and a floor, caused by correlations between tokens of the same document, that does not. The two meet at a critical sequence length S*. Below it, longer sequences reduce gradient noise; above it, they add context but barely reduce the noise. We test this picture on GPT models from 125M to 1B parameters, trained on short web documents (FineWeb-Edu) and on whole books (Project Gutenberg), and find that it fits well, with informative exceptions on books and on artificially chopped data. Three findings stand out. First, S* is set by the data: it depends on the documents and on how they are packed into sequences, and chopping documents into short pieces halves the floor. Second, the critical length measured on the updates that AdamW actually applies is largely stable across model sizes and training time (and, at 1B, across corpora) and grows only with the training length, whereas the raw-gradient version varies widely. Third, validation loss is lowest when training near this length and changes little beyond it, but downstream performance is more fragile: it drops modestly as more documents are packed into each sequence and collapses when documents are chopped into short pieces. Intra-document attention masking keeps the critical length stable under heavy packing and lowers the loss. These results lead to a simple, regime-aware rule for trading batch size against sequence length.
Create a lesson
Metadata
- Categories
- cs.LG, cs.AI
- Comments
- 43 pages, 19 figures. Code: https://github.com/sol0invictus/nanoScaling/tree/main/experiments/sequence_scaling
Related papers
Shorter Sequences, Faster Models: Sequence Length Compression as a Stackable Primitive for LLM Training and Inference
Shared title terminologycs.LGMarc Neumann
Elastic Coding: Robust Maximal Coding Rate Reduction under Label Noise
Shared title terminologycs.LGMenghui Zhou, Vitaveska Lanfranchi, Po Yang
Machine Learning Moment Closure for the Radiative Transfer Equation: Enforcing Hyperbolicity and Wave-Speed Bounds
Shared title terminologycs.LGBongseok Kim, Guang Lin
On the fundamentals of gradient-based SAT solvers
Shared title terminologycs.LGNikolaos Karalias, Saku Peltonen, Nikita Kostin et al.
ReAgent: Closed-Loop Self-Healing for Open-Weight Tool-Calling Agents, from Structural Hallucinations to Decision Errors
Shared title terminologycs.LGCharlie Galvin, Katie Kitchen, Chiara Picardi
Electrode-level artifact simulation and corruption-aware gated reconstruction of the 12-lead ECG, with real-noise and paper-ECG external validation
Shared title terminologycs.LGSanjoy Das Joy, Arfatul Islam Asif, Unayes Ahmed Khan et al.