Gated Associative Memory: A Parallel O(N) Architecture for Efficient Sequence Modeling

Rishiraj Acharya
8/30/2025
cs.CLcs.LG

No official code found. Best implementation: rishiraj/gam (15 stars, Apache-2.0, last commit 2025-09-03).

Abstract

The Transformer architecture, underpinned by the self-attention mechanism, has become the de facto standard for sequence modeling tasks. However, its core computational primitive scales quadratically with sequence length (O(N^2)), creating a significant bottleneck for processing long contexts. In this paper, we propose the Gated Associative Memory (GAM) network, a novel, fully parallel architecture for sequence modeling that exhibits linear complexity (O(N)) with respect to sequence length. The GAM block replaces the self-attention layer with two parallel pathways: a causal convolution to efficiently capture local, position-dependent context, and a parallel associative memory retrieval mechanism to model global, content-based patterns. These pathways are dynamically fused using a gating mechanism, allowing the model to flexibly combine local and global information for each token. We implement GAM from scratch and conduct a rigorous comparative analysis against a standard Transformer model and a modern linear-time baseline (Mamba) on the WikiText-2 benchmark, as well as against the Transformer on the TinyStories dataset. Our experiments demonstrate that GAM is consistently faster, outperforming both baselines on training speed, and achieves a superior or competitive final validation perplexity across all datasets, establishing it as a promising and efficient alternative for sequence modeling.

View on arXivView PDF

Code Implementations(1)

rishiraj/gamCommunity69%
Apache-2.0

This is the official PyTorch implementation for the paper "Gated Associative Memory: A Parallel O(N) Architecture for Efficient Sequence Modeling" by Rishiraj Acharya.

154PythonAug 30, 20251 years agoApache-2.0

Cite this paper

@article{acharya2025gated,
  title  = {Gated Associative Memory: A Parallel O(N) Architecture for Efficient Sequence Modeling},
  author = {Rishiraj Acharya},
  year   = {2025},
  eprint = {2509.00605},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2509.00605v1}
}

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

Discussion