Segmented Recurrent Transformer: An Efficient Sequence-to-Sequence Model

Yinghan Long, Sayeed Shafayet Chowdhury, Kaushik Roy

Abstract

Transformers have shown dominant performance across a range of domains including language and vision. However, their computational cost grows quadratically with the sequence length, making their usage prohibitive for resource-constrained applications. To counter this, our approach is to divide the whole sequence into segments and apply attention to the individual segments. We propose a segmented recurrent transformer (SRformer) that combines segmented (local) attention with recurrent attention. The loss caused by reducing the attention window length is compensated by aggregating information across segments with recurrent attention. SRformer leverages Recurrent Accumulate-and-Fire (RAF) neurons' inherent memory to update the cumulative product of keys and values. The segmented attention and lightweight RAF neurons ensure the efficiency of the proposed transformer. Such an approach leads to models with sequential processing capability at a lower computation/memory cost. We apply the proposed method to T5 and BART transformers. The modified models are tested on summarization datasets including CNN-dailymail, XSUM, ArXiv, and MediaSUM. Notably, using segmented inputs of varied sizes, the proposed model achieves 6-22% higher ROUGE1 scores than a segmented transformer and outperforms other recurrent transformer approaches. Furthermore, compared to full attention, the proposed model reduces the computational complexity of cross attention by around 40%.

Introduction

While Transformers have revolutionized natural language processing, they suffer from a "quadratic problem": computational and memory costs scale with the square of the input sequence length ($O(n^2)$). This bottleneck is particularly acute in sequence-to-sequence (Seq2Seq) tasks like summarization, where the cross-attention mechanism requires the decoder to attend to the entire encoded input for every generated token.

Existing solutions often involve "segmenting" the input into smaller chunks to reduce the attention window. However, this typically results in "context loss," where the model loses track of global information from previous segments. The Segmented Recurrent Transformer (SRformer) addresses this by combining local segmented attention with a novel, bio-inspired recurrent mechanism that preserves long-range context at a fraction of the cost.

The SRformer Architecture

The SRformer replaces standard cross-attention with a hybrid approach that balances local precision with global awareness. The input sequence is divided into segments, and the decoder query performs high-resolution attention only on the current corresponding segment. To maintain global context, the model employs a recurrent path that aggregates information from all previous segments.

The SRformer decoder architecture featuring Segmented Recurrent Cross Attention.

This architecture is powered by Recurrent Accumulate-and-Fire (RAF) neurons. Inspired by biological spiking neural networks, these neurons store a running product of Keys ($K$) and Values ($V$) from past segments. By utilizing an associativity trick—multiplying $K$ and $V$ before applying the Query ($Q$)—the attention calculation is transformed from quadratic to linear complexity. The RAF neurons include leak and threshold mechanisms to manage memory, ensuring that only relevant, accumulated evidence is propagated to subsequent layers.

Experimental Evaluation and Efficiency

The SRformer was evaluated using T5-small and BART-base architectures across four major summarization benchmarks: CNN-DailyMail, XSUM, ArXiv, and MediaSUM. A key finding was the model's remarkable stability across different segment sizes. While standard segmented Transformers experience a performance collapse when segment sizes are reduced (e.g., to 8 tokens), SRformer maintains high ROUGE scores because the recurrent RAF neurons effectively "fill in" the missing context.

Comparison of ROUGE1 scores across varying segment sizes, demonstrating SRformer's stability.

Beyond performance, SRformer offers significant hardware advantages. In tests on Nvidia A40 GPUs, a BART-based SRformer consumed only 81% of the power and required 60% of the memory access time compared to the vanilla version. Furthermore, the model exhibits linear scaling relative to summary length. For a generated summary of 1024 tokens, SRformer represents a 93% reduction in computation compared to standard full-attention Transformers.

Conclusion

SRformer demonstrates that it is possible to achieve the efficiency of segmented attention without sacrificing the global context necessary for high-quality sequence generation. By reducing cross-attention complexity by approximately 40% and outperforming existing recurrent models like Transformer-XL, SRformer provides a viable path for deploying powerful Seq2Seq models in resource-constrained environments. Future work will explore extending this architecture to encoder-only and decoder-only models, as well as optimizing RAF parameters for specialized hardware backends.

Summary updated

BibTeX
@inproceedings{long2023segmented,
  author = {Yinghan Long and Sayeed Shafayet Chowdhury and Kaushik Roy},
  title = {{Segmented Recurrent Transformer: An Efficient Sequence-to-Sequence Model}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  url = {https://openreview.net/forum?id=TvTwz12BZN},
}
Figure