Forgetting Transformer: Softmax Attention with a Forget Gate

Zhixuan Lin, Evgenii Nikishin, Xu Owen He, Aaron Courville
3/3/2025
cs.LGcs.AIcs.CL

Official code: zhixuan-lin/forgetting-transformer (154 stars, MIT, last commit 2026-02-25).

Abstract

An essential component of modern recurrent sequence models is the forget gate. While Transformers do not have an explicit recurrent form, we show that a forget gate can be naturally incorporated into Transformers by down-weighting the unnormalized attention scores in a data-dependent way. We name this attention mechanism Forgetting Attention and the resulting model the Forgetting Transformer (FoX). We show that FoX outperforms the Transformer on long-context language modeling, length extrapolation, and short-context downstream tasks, while performing on par with the Transformer on long-context downstream tasks. Moreover, it is compatible with the FlashAttention algorithm and does not require any positional embeddings. Several analyses, including the needle-in-the-haystack test, show that FoX also retains the Transformer's superior long-context capabilities over recurrent sequence models such as Mamba-2, HGRN2, and DeltaNet. We also introduce a "Pro" block design that incorporates some common architectural components in recurrent sequence models and find it significantly improves the performance of both FoX and the Transformer. Our code is available at https://github.com/zhixuan-lin/forgetting-transformer.

View on arXivView PDF

Code Implementations(1)

MIT

[ICLR 2025 & COLM 2025] Official PyTorch implementation of the Forgetting Transformer and Adaptive Computation Pruning

1549TeX, PythonMar 2, 20257 months agoMIT

Similar Papers

Cite this paper

@article{lin2025forgetting,
  title  = {Forgetting Transformer: Softmax Attention with a Forget Gate},
  author = {Zhixuan Lin and Evgenii Nikishin and Xu Owen He and Aaron Courville},
  year   = {2025},
  eprint = {2503.02130},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2503.02130v2},
  journal = {ICLR 2025 2025}
}

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

Discussion