RecurFormer: Not All Transformer Heads Need Self-Attention

Ruiqing Yan, Linghan Zheng, Xingbo Du, Han Zou, Yufeng Guo +1 more
10/10/2024
cs.CLcs.AIcs.LG

No confident code implementation found for this paper. 2 possible matches can be shown below.

Abstract

Transformer-based large language models (LLMs) excel in modeling complex language patterns but face significant computational costs during inference, especially with long inputs due to the attention mechanism's memory overhead. We observe that certain attention heads exhibit a distribution where the attention weights concentrate on tokens near the query token, termed as recency aware, which focuses on local and short-range dependencies. Leveraging this insight, we propose RecurFormer, a novel architecture that replaces these attention heads with linear recurrent neural networks (RNNs), specifically the Mamba architecture. This replacement reduces the cache size without evicting tokens, thus maintaining generation quality. RecurFormer retains the ability to model long-range dependencies through the remaining attention heads and allows for reusing pre-trained Transformer-based LLMs weights with continual training. Experiments demonstrate that RecurFormer matches the original model's performance while significantly enhancing inference efficiency. Our approach provides a practical solution to the computational challenges of Transformer-based LLMs inference, making it highly attractive for tasks involving long inputs.

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. 2 weaker matches are hidden by default — 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{yan2024recurformer,
  title  = {RecurFormer: Not All Transformer Heads Need Self-Attention},
  author = {Ruiqing Yan and Linghan Zheng and Xingbo Du and Han Zou and Yufeng Guo and Jianfei Yang},
  year   = {2024},
  eprint = {2410.12850},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2410.12850v1}
}

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

Discussion