HMT: Hierarchical Memory Transformer for Efficient Long Context Language Processing

Zifan He, Yingqi Cao, Zongyue Qin, Neha Prakriya, Yizhou Sun +1 more
5/9/2024
cs.CLcs.LG

Official code: OswaldHe/HMT-pytorch (80 stars, Apache-2.0, last commit 2026-03-12).

Abstract

Transformer-based large language models (LLM) have been widely used in language processing applications. However, due to the memory constraints of the devices, most of them restrict the context window. Even though recurrent models in previous works can memorize past tokens to enable unlimited context and maintain effectiveness, they have ``flat'' memory architectures. Such architectures have limitations in selecting and filtering information. Since humans are good at learning and self-adjustment, we believe that imitating brain memory hierarchy is beneficial for model memorization. Thus, we propose the Hierarchical Memory Transformer (HMT), a novel framework that facilitates a model's long-context processing ability by imitating human memorization behavior. Leveraging memory-augmented segment-level recurrence, we organize the memory hierarchy by preserving tokens from early input segments, passing memory embeddings along the sequence, and recalling relevant information from history. Evaluating general language modeling, question-answering tasks, and the summarization task, we show that HMT consistently improves the long-context processing ability of existing models. Furthermore, HMT achieves a comparable or superior generation quality to long-context LLMs with $2 \sim 57\times$ fewer parameters and $2.5 \sim 116\times$ less inference memory, significantly outperforming previous memory-augmented models. Code on Github: https://github.com/OswaldHe/HMT-pytorch.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

[NAACL 2025] Official Implementation of "HMT: Hierarchical Memory Transformer for Long Context Language Processing"

8012Shell, PythonDec 11, 20237 months agoApache-2.0

Similar Papers

Cite this paper

@article{he2024hmt,
  title  = {HMT: Hierarchical Memory Transformer for Efficient Long Context Language Processing},
  author = {Zifan He and Yingqi Cao and Zongyue Qin and Neha Prakriya and Yizhou Sun and Jason Cong},
  year   = {2024},
  eprint = {2405.06067},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2405.06067v3}
}

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

Discussion