Neurocache: Efficient Vector Retrieval for Long-range Language Modeling

Ali Safaya, Deniz Yuret
7/2/2024
cs.CLcs.AIcs.LG

Official code: alisafaya/neurocache (9 stars, Apache-2.0, last commit 2024-08-21).

Abstract

This paper introduces Neurocache, an approach to extend the effective context size of large language models (LLMs) using an external vector cache to store its past states. Like recent vector retrieval approaches, Neurocache uses an efficient k-nearest-neighbor (kNN) algorithm to retrieve relevant past states and incorporate them into the attention process. Neurocache improves upon previous methods by (1) storing compressed states, which reduces cache size; (2) performing a single retrieval operation per token which increases inference speed; and (3) extending the retrieval window to neighboring states, which improves both language modeling and downstream task accuracy. Our experiments show the effectiveness of Neurocache both for models trained from scratch and for pre-trained models such as Llama2-7B and Mistral-7B when enhanced with the cache mechanism. We also compare Neurocache with text retrieval methods and show improvements in single-document question-answering and few-shot learning tasks. We made the source code available under: https://github.com/alisafaya/neurocache

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Neurocache: A library for augmenting language models with external caching mechanisms

91PythonNov 3, 20232 years agoApache-2.0

Similar Papers

Cite this paper

@article{safaya2024neurocache,
  title  = {Neurocache: Efficient Vector Retrieval for Long-range Language Modeling},
  author = {Ali Safaya and Deniz Yuret},
  year   = {2024},
  eprint = {2407.02486},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2407.02486v1}
}

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

Discussion