Long-Short Transformer: Efficient Transformers for Language and Vision

Chen Zhu, Wei Ping, Chaowei Xiao, Mohammad Shoeybi, Tom Goldstein, Anima Anandkumar, Bryan Catanzaro

Abstract

The Long-Short Transformer (Transformer-LS) addresses the quadratic computational complexity of standard self-attention mechanisms, which limits their applicability to long sequences in natural language processing and high-resolution computer vision. By integrating a dynamic low-rank projection for long-range dependencies with a segment-wise sliding window for local context, Transformer-LS achieves linear $O(n)$ time and memory complexity. This hybrid architecture, supported by a novel Dual Normalization (DualLN) strategy, sets new state-of-the-art benchmarks across diverse tasks while maintaining robustness to sequence variations.

Introduction

The "quadratic bottleneck" remains a significant challenge for standard Transformers. As the sequence length $n$ increases, the cost of computing all-to-all attention grows at $O(n^2)$, making the processing of long documents or high-resolution images computationally prohibitive. Existing solutions generally fall into two categories: sparse attention (e.g., sliding windows) and low-rank projections (e.g., Linformer). While sparse attention excels at capturing local details, it often misses global context. Conversely, low-rank projections capture global patterns but lose fine-grained local information and can be sensitive to sequence modifications like insertions.

Methodology: The Transformer-LS Architecture

Transformer-LS introduces a dual-stream attention mechanism designed to capture both local and global correlations efficiently.

The Transformer-LS architecture featuring dual-stream attention: dynamic low-rank projection for long-range context and sliding window for local details.

Dual-Stream Attention

  1. Dynamic Low-Rank Projection (Long-range): Unlike static projection methods, Transformer-LS computes a projection matrix as a function of the input keys. This dynamic approach ensures the model is robust to sequence variations such as paraphrasing or word insertions.
  2. Segment-wise Sliding Window (Short-term): To preserve high-fidelity local details, each query attends to a local neighborhood. Efficiency is maintained by processing these in disjoint segments.

Dual Normalization (DualLN)

A critical finding during development was a "scale mismatch" between local and global streams. Local embeddings typically exhibit higher variance and larger norms than global embeddings, which are essentially weighted averages. To prevent the model from ignoring the global signal, DualLN applies separate LayerNorms to each stream before aggregation, ensuring balanced contributions.

Experimental Results

The model was evaluated across a wide range of benchmarks, including the Long Range Arena (LRA), character-level language modeling (enwik8, text8), and ImageNet-1K classification.

Efficiency and Scaling

Transformer-LS demonstrates superior efficiency, handling sequences up to three times longer than standard Transformers on identical hardware. As shown in the memory analysis, the model maintains linear memory growth relative to sequence length, significantly outperforming the quadratic scaling of standard architectures.

GPU memory consumption comparison between Transformer-XL and Transformer-LS across various batch sizes and sequence lengths.

Performance Benchmarks

  • Language Modeling: On the enwik8 dataset, Transformer-LS achieved a state-of-the-art 0.97 BPC (Bits Per Character) with 110M parameters, matching the performance of models like the Compressive Transformer which use twice the parameter count.
  • Computer Vision: Integrated into vision backbones (such as CvT or ViL), the model reached 84.1% Top-1 accuracy on ImageNet-1K and showed enhanced robustness to common image corruptions and adversarial perturbations compared to standard CNNs.
  • Long Range Arena: Transformer-LS outperformed major efficient variants, including Reformer, Linformer, Performer, and Nyströmformer, across all LRA tasks.

Conclusion

Transformer-LS proves that local and global attention are complementary rather than redundant. By aligning the scales of these specialized streams through DualLN and employing dynamic projections, the architecture achieves an optimal balance of efficiency and representational power. Future work will explore applying this framework to dense vision tasks like object detection and document-level question answering.

Summary updated

BibTeX
@inproceedings{zhu2021long,
  author = {Chen Zhu and Wei Ping and Chaowei Xiao and Mohammad Shoeybi and Tom Goldstein and Anima Anandkumar and Bryan Catanzaro},
  title = {{Long-Short Transformer: Efficient Transformers for Language and Vision}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
}
Figure