Critical Sequence Length: A Note on How Document Structure Bounds Gradient-Noise Reduction

Sunny GuhaarXiv 2026

TL;DR

When training Large Language Models (LLMs), practitioners usually assume that doubling the sequence length $S$ lets you halve the batch size $B$ while keeping gradient noise constant. This paper shows that this rule of thumb breaks down past a critical sequence length ($S^*$), because tokens within the same document are correlated and create a noise floor that longer sequences cannot average away. Measuring this boundary in AdamW's update space ($S^*_{\text{adam}}$) yields a stable, practical number that tells you when to stop shrinking your batch size.

What Problem Does This Paper Address?

In LLM pre-training, the standard rule of thumb is that per-step gradient variance scales as $1/(BS)$. This treats every token in a packed training sequence as an independent sample of the gradient.

In reality, autoregressive tokens are not independent: tokens from the same document share context, so their gradients point in similar directions. Beyond a certain sequence length, making $S$ longer adds context but stops reducing gradient noise. If you blindly keep halving $B$ every time you double $S$ past this point, you shrink the batch more than necessary—forcing the run to take more optimizer steps with noisier updates for the same token budget.

Methods

The authors model gradient covariance by splitting it into two parts: a per-token variance $\sigma_h^2$ that averages away as $1/S$, and a cross-token covariance floor $\sigma_{ch}^2$ caused by within-document correlations:

$$\text{Tr}(\text{Cov}(g)) \cdot B = \frac{\sigma_h^2}{S} + \sigma_{ch}^2 \left(1 - \frac{1}{S}\right)$$

The two terms meet at the critical sequence length $S^* = \sigma_h^2 / \sigma_{ch}^2$.

To test this, they train GPT-style Transformer decoders (125M, 350M, and 1B parameters) with AdamW under a fixed per-step token budget ($B \cdot S = 524,288$) across training lengths $S_{\text{train}} \in \{1024, 2048, 4096, 8192\}$ (and $16384$ at 1B). Crucially, they measure the trace covariance $\text{Tr}(\text{Cov}(g))$ at frozen checkpoints in two frames:

  1. Raw-gradient frame ($S^*_{\text{grad}}$): Standard gradient space.
  2. AdamW update frame ($S^*_{\text{adam}}$): Rescaled by AdamW's saved second-moment preconditioner $1/(\sqrt{\hat{v}_i} + \epsilon)^2$, which reflects the actual updates the optimizer applies.
The two-regime decomposition fits measured gradient noise

Datasets

  • FineWeb-Edu: Short web documents (mean length $\approx 1.1\text{k}$ tokens), packed with <|endoftext|>-aligned best-fit packing.
  • Project Gutenberg English: Whole books (mean length $\approx 85\text{k}$ tokens), used as a long-document contrast.
  • Downstream Evaluations (at 1B): MMLU, HellaSwag, and ARC-Easy/Challenge (via lm-eval-harness), plus perplexity on held-out long Gutenberg documents.

Key Insights and Ideas

  • Document structure sets the floor: The noise floor $\sigma_{ch}^2$ depends on how often tokens share a document and how strongly they are correlated. Artificially chopping FineWeb-Edu documents into $K$-token pieces destroys long-range structure and roughly halves $\sigma_{ch}^2$ at $K=1024$ (350M).
  • AdamW's frame is far more stable than raw gradients: $S^*_{\text{grad}}$ drifts during training, varies by up to $10\times$ across corpora, and becomes unreliable to fit at long $S_{\text{train}}$. By dividing out overall gradient scale, $S^*_{\text{adam}}$ settles early (around 15% into training) and stays in a narrow band (~800–3,000 tokens) across well-trained 350M and 1B runs.
  • Loss and capability decouple: Validation loss is lowest near $S^*_{\text{adam}}$ and rises only slightly past it. However, downstream benchmark scores drop modestly as more documents are packed into each sequence (higher boundary count $\nu$) and collapse to chance when documents are chopped into short fragments.
  • Intra-document attention masking fixes heavy packing: Preventing tokens from attending across document boundaries keeps $S^*_{\text{adam}}$ near 1,000 at every training length and lowers validation loss.

Key Results

  • Model fit: The two-regime decomposition fits every FineWeb-Edu run with $R^2 \ge 0.93$ and confirms $1/B$ scaling up to $B=64$.
  • Optimal training length: Lowest validation loss consistently occurs when $S_{\text{train}}$ is within $0.6\times$ to $1.5\times S^*_{\text{adam}}$. Training well past $S^*_{\text{adam}}$ raises loss by less than $0.07\text{ nat}$.
  • Masking gains: At 350M (40 TPP), intra-document attention masking lowers training loss by $0.03$ to $0.17\text{ nat}$, with the largest gain at $S_{\text{train}}=8192$.
  • Regime-aware batch-size rule: The authors propose trading $B \propto 1/S$ only up to $S^*_{\text{adam}}$, then holding $B$ fixed: $$B_{\text{new}} = B_{\text{old}} \cdot \frac{S_{\text{old}}}{\min(S_{\text{new}}, S^*_{\text{adam}})}$$ For a 1B model ($S^*_{\text{adam}} \approx 2000$) moving from $S=1024, B=512$ to $S=4096$, this prescribes $B \approx 260$ instead of the folklore $128$—requiring about half as many optimizer steps.

Limitations and Future Work

The study examines sequence length solely through gradient noise, whereas practical choices also depend on attention cost and target context-window capabilities. Experiments reach only 1B parameters, use a single architecture family and optimizer (AdamW), and mostly use single seeds on single-source corpora rather than realistic multi-source mixtures. Additionally, intra-document masking was tested only at 350M, and the proposed batch-size rule has not yet been validated in full end-to-end training runs.

Summary updated

BibTeX
@misc{guha2026critical,
  author = {Sunny Guha},
  title = {{Critical Sequence Length: A Note on How Document Structure Bounds Gradient-Noise Reduction}},
  year = {2026},
  eprint = {2612.03183},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2612.03183},
}
Figure