Simple linear attention language models balance the recall-throughput tradeoff

Published: 21 Jun 2024, Last Modified: 26 Jul 2024ES-FoMo-II 2024 OralEveryoneRevisionsBibTeXCC BY 4.0
Keywords: efficient language models, in context learning, linear attention
TL;DR: We show that simple linear attention models can expand the Pareto frontier of the recall-throughput tradeoff space.
Abstract: Abstract Recent work has shown that attention-based language models excel at "recall", the ability to ground generations in tokens previously seen in context. However, the efficiency of attention-based models is bottle-necked during inference by the KV-cache's aggressive memory consumption. In this work, we explore whether we can improve language model efficiency (e.g. by reducing memory consumption) without compromising on recall. By applying experiments and theory to a broad set of architectures, we identify a key tradeoff between a model's recurrent state size and recall ability. We show that efficient alternatives to attention (e.g. H3, Mamba, RWKV) maintain a fixed-size recurrent state, but struggle at recall. We propose BASED a simple architecture combining linear and sliding window attention. By varying BASED window size and linear attention feature dimension, we can dial the state size and traverse the Pareto frontier of the recall-memory tradeoff curve, recovering the full quality of attention on one end and the small state size of attention-alternatives on the other. We train language models up to $1.3$b parameters and show that BASED matches the strongest sub-quadratic models (e.g. Mamba) in perplexity and outperforms them on real-world recall-intensive tasks by 10.36 accuracy points. Implementations of linear attention are often less efficient than optimized standard attention implementations. To make BASED competitive, we develop IO-aware algorithms that enable $24\times$ higher throughput on language generation than FlashAttention-2, when generating 1024 tokens using $1.3$b parameter models. Overall, BASED extends the Pareto frontier of the throughput-recall tradeoff space. Our code is available at: https://github.com/HazyResearch/based
Submission Number: 81
Loading