[Paper Review] Memformer: A Memory-Augmented Transformer for Sequence Modeling
Memformer introduces a memory-augmented Transformer with a fixed-size external dynamic memory to achieve linear time complexity and constant memory space complexity for long sequence modeling. By using a memory writer and reader with a forgetting mechanism, and a novel memory replay back-propagation (MRBP) optimization, it matches Transformer-XL performance with 8.1x less memory and 3.2x faster inference on autoregressive tasks.
Transformers have reached remarkable success in sequence modeling. However, these models have efficiency issues as they need to store all the history token-level representations as memory. We present Memformer, an efficient neural network for sequence modeling, that utilizes an external dynamic memory to encode and retrieve past information. Our model achieves linear time complexity and constant memory space complexity when processing long sequences. We also propose a new optimization scheme, memory replay back-propagation (MRBP), which promotes long-range back-propagation through time with a significantly reduced memory requirement. Experimental results show that Memformer has achieved comparable performance compared to the baselines by using 8.1x less memory space and 3.2x faster on inference. Analysis of the attention pattern shows that our external memory slots can encode and retain important information through timesteps.
Motivation & Objective
- Address the quadratic computation and memory complexity of standard Transformers in long sequence modeling.
- Overcome the limitations of recurrent models like RNNs and Transformer-XL in preserving long-range dependencies.
- Enable efficient training and inference for autoregressive models with large memory representations.
- Develop a memory-efficient architecture that maintains high performance while reducing computational and memory costs.
Proposed method
- Introduces an external dynamic memory module that stores compressed representations of past tokens, enabling constant memory space complexity.
- Employs a memory writer to update memory slots based on current input and a forgetting mechanism to control retention of outdated information.
- Uses a memory reader to attend over memory slots during decoding, allowing the model to retrieve relevant historical information.
- Proposes Memory Replay Back-Propagation (MRBP), a novel optimization scheme that reduces memory cost during back-propagation through time.
- Architects Memformer with separate encoder and decoder stacks, where memory is updated only in the encoder and accessed by the decoder.
- Applies a compression mechanism to reduce memory size while preserving long-range dependencies, improving efficiency without sacrificing performance.
Experimental results
Research questions
- RQ1Can a fixed-size external memory improve long-range sequence modeling efficiency while maintaining performance comparable to Transformers?
- RQ2How does the memory writer’s attention mechanism enable effective compression and retention of long-range dependencies?
- RQ3To what extent does the proposed MRBP scheme reduce memory consumption during back-propagation in recurrent models with large memory?
- RQ4Does Memformer outperform Transformer-XL and Compressive Transformer in terms of inference speed and memory efficiency on long sequences?
- RQ5How do different memory sizes and memory slot types affect the model’s ability to retain and retrieve information over time?
Key findings
- Memformer achieves comparable performance to Transformer-XL with a memory size of 1,024, while using 8.1x less memory space and 3.2x faster inference.
- With 1,024 memory size, Memformer achieved a perplexity of 20.53 on WikiText-103, outperforming Transformer-XL with 1,024 memory and Compressive Transformer with similar FLOPs.
- Performance dropped significantly when memory size was reduced to 512, and further when the memory module was completely removed, resulting in a perplexity of 25.57.
- Analysis of memory writer attention revealed that ~60–80% of memory slots maintain their content over time, indicating stable long-term memory retention.
- Memory slots of type m^{355} showed high attention on input tokens and had a larger forgetting bias (3.20), indicating rapid updates for dynamic or salient information.
- Visualization confirmed that memory slots learn compressed representations of key elements like named entities and verbs, mimicking human-like memory encoding.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.