On Vanishing Variance in Transformer Length Generalization

Ruining Li, Gabrijel Boduljak, Jensen, Zhou
4/3/2025
cs.LGcs.AI

No confident code implementation found for this paper.

Abstract

It is a widely known issue that Transformers, when trained on shorter sequences, fail to generalize robustly to longer ones at test time. This raises the question of whether Transformer models are real reasoning engines, despite their impressive abilities in mathematical problem solving and code synthesis. In this paper, we offer a vanishing variance perspective on this issue. To the best of our knowledge, we are the first to demonstrate that even for today's frontier models, a longer sequence length results in a decrease in variance in the output of the multi-head attention modules. On the argmax retrieval and dictionary lookup tasks, our experiments show that applying layer normalization after the attention outputs leads to significantly better length generalization. Our analyses attribute this improvement to a reduction-though not a complete elimination-of the distribution shift caused by vanishing variance.

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{li2025vanishing,
  title  = {On Vanishing Variance in Transformer Length Generalization},
  author = {Ruining Li and Gabrijel Boduljak and Jensen and Zhou},
  year   = {2025},
  eprint = {2504.02827},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2504.02827v1}
}

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/2504.02827.svg)](https://codeofpaper.com/paper/2504.02827)

Discussion