GMAT: Global Memory Augmentation for Transformers

Ankit Gupta, Jonathan BerantarXiv 2020

Abstract

Transformer-based models have become ubiquitous in natural language processing thanks to their large capacity, innate parallelism and high performance. The contextualizing component of a Transformer block is the pairwise dot-product attention that has a large $\Omega(L^2)$ memory requirement for length $L$ sequences, limiting its ability to process long documents. This has been the subject of substantial interest recently, where multiple approximations were proposed to reduce the quadratic memory requirement using sparse attention matrices. In this work, we propose to augment sparse Transformer blocks with a dense attention-based global memory of length $M$ ($M \ll L$) which provides an aggregate global view of the entire input sequence to each position. Our augmentation has a manageable $O(M \cdot (L + M))$ memory overhead, and can be seamlessly integrated with prior sparse solutions. Moreover, global memory can also be used for sequence compression, by representing a long input sequence with the memory representations only. We empirically show that our method leads to substantial improvement on a range of tasks, including (a) synthetic tasks that require global reasoning, (b) masked language modeling, and (c) reading comprehension.

Introduction

The standard Transformer architecture is a powerhouse in NLP, but it faces a significant scaling challenge: its self-attention mechanism scales quadratically ($O(L^2)$) with sequence length $L$. To process long documents, researchers often turn to sparse attention mechanisms, such as chunking or sliding windows, where tokens only interact with a small neighborhood of nearby tokens.

While efficient, this approach introduces a locality bias. If a token can only see its immediate neighbors, it struggles with tasks requiring global reasoning—such as connecting a fact on page 1 to a question on page 100. Information must "hop" through many layers to travel across the sequence, leading to context fragmentation and inefficiency. GMAT (Global Memory Augmentation for Transformers) addresses this by providing a global "scratchpad" for long-range reasoning.

Methodology: Global Memory Augmentation

The core of GMAT is the introduction of $M$ "memory tokens" ($X_M$) that are prefixed to the main input sequence $X$. This architecture enables three distinct interaction patterns:

  1. Main Sequence to Main Sequence: Tokens use efficient sparse attention to communicate locally.
  2. Main Sequence to Memory: Every token in the main sequence can attend to all memory tokens using standard dense attention.
  3. Memory to Everything: Memory tokens attend to the entire input (both $X$ and $X_M$) using dense attention.
GMAT architecture overview showing memory interaction (a), sparse local attention (b), and the sequence compression/decompression pipeline (c).

This setup allows memory tokens to aggregate global information and broadcast it back to every position in the sequence. The memory overhead is only $O(M \cdot (L + M))$, which remains manageable since $M$ is typically much smaller than $L$.

Sequence Compression

GMAT also enables sequence compression. By utilizing a set of "compression layers," the model squashes a long input into just the $M$ memory vectors. Subsequently, "decompression layers" use positional embeddings as queries to reconstruct the original sequence's contextual representations from that compact memory footprint. This allows for significant reductions in storage and computation for pre-computed document embeddings.

Experimental Results

The authors evaluated GMAT across synthetic tasks, language modeling, and reading comprehension.

Synthetic and Reasoning Tasks

On the "Majority Tagging" task (identifying the most frequent element in a list of 8192 tokens), a standard sparse Transformer (Reformer) achieved only 15% accuracy. In contrast, GMAT achieved 98% accuracy, demonstrating its ability to break the locality barrier. For complex reasoning, the authors found that "untying" parameters—giving the memory its own dedicated projection matrices—was essential for high performance.

Reading Comprehension and Language Modeling

In reading comprehension, GMAT outperformed BERT on the "gold-separated" setting of HotpotQA (68.3 vs 66.3 F1), proving its utility in connecting disparate pieces of information. On the PG19 book dataset, GMAT improved perplexity from 4.40 to 4.35, effectively closing half the gap between short-context and full-context models.

Evaluation Exact Match (EM) scores over training steps for 2-layer and 12-layer models, demonstrating the performance boost provided by global memory (M=8) compared to baseline sparse models (M=0).

Compression Efficiency

The sequence compression results were particularly notable. The model compressed a sequence of 512 tokens into just 64 memory vectors (an 8x reduction) while maintaining an F1 score of 87.1 on SQuAD (compared to BERT's 88.6). This suggests that much of the information in contextualized sequences is redundant and can be efficiently summarized.

Conclusion

GMAT provides a simple yet powerful architectural tweak to overcome the limitations of sparse Transformers. By maintaining a dense global memory buffer, models can achieve long-range reasoning with minimal overhead. Future work may explore task-aware memory (e.g., using question tokens as memory) and hierarchical memory structures for even longer contexts.

Summary updated

BibTeX
@misc{gupta2020gmat,
  author = {Ankit Gupta and Jonathan Berant},
  title = {{GMAT: Global Memory Augmentation for Transformers}},
  year = {2020},
  eprint = {2006.03274},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2006.03274},
}
Figure