NormFormer: Improved Transformer Pretraining with Extra Normalization

Sam Shleifer, Jason Weston, Myle Ott
10/18/2021
cs.CLcs.AI
transformer-attention

Official code: facebookresearch/fairseq (32,206 stars, Python, MIT, PyTorch, last commit 2025-09-30).

Abstract

During pretraining, the Pre-LayerNorm transformer suffers from a gradient magnitude mismatch: gradients at early layers are much larger than at later layers. These issues can be alleviated by our proposed NormFormer architecture, which adds three normalization operations to each layer: a Layer Norm after self attention, head-wise scaling of self-attention outputs, and a Layer Norm after the first fully connected layer.

Show full abstract

The extra operations incur negligible compute cost (+0.4% parameter increase), but improve pretraining perplexity and downstream task performance for both causal and masked language models ranging from 125 Million to 2.7 Billion parameters. For example, adding NormFormer on top of our strongest 1.3B parameter baseline can reach equal perplexity 24% faster, or converge 0.27 perplexity better in the same compute budget. This model reaches GPT3-Large (1.3B) zero shot performance 60% faster. For masked language modeling, NormFormer improves fine-tuned GLUE performance by 1.9% on average. Code to train NormFormer models is available in fairseq https://github.com/pytorch/fairseq/tree/main/examples/normformer .

View on arXivView PDF

Code Implementations(1)

PyTorchMIT

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.

32,2066,661Python, CudaAug 29, 20171 years agoMIT
artificial-intelligencepythonpytorch

Similar Papers

Cite this paper

@article{shleifer2021normformer,
  title  = {NormFormer: Improved Transformer Pretraining with Extra Normalization},
  author = {Sam Shleifer and Jason Weston and Myle Ott},
  year   = {2021},
  eprint = {2110.09456},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2110.09456}
}

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

Discussion