Squeezed Attention: Accelerating Long Context Length LLM Inference

Fuente: arXiv
Salvato in:
Dettagli Bibliografici
Autori principali: Hooper, Coleman, Kim, Sehoon, Mohammadzadeh, Hiva, Maheswaran, Monishwaran, Zhao, Sebastian, Paik, June, Mahoney, Michael W., Keutzer, Kurt, Gholami, Amir
Natura: Preprint
Pubblicazione: 2024
Soggetti:
Accesso online:
Tags: Aggiungi Tag
Nessun Tag, puoi essere il primo ad aggiungerne!!
_version_ 1866915556290985984
author Hooper, Coleman
Kim, Sehoon
Mohammadzadeh, Hiva
Maheswaran, Monishwaran
Zhao, Sebastian
Paik, June
Mahoney, Michael W.
Keutzer, Kurt
Gholami, Amir
author_facet Hooper, Coleman
Kim, Sehoon
Mohammadzadeh, Hiva
Maheswaran, Monishwaran
Zhao, Sebastian
Paik, June
Mahoney, Michael W.
Keutzer, Kurt
Gholami, Amir
contents Emerging Large Language Model (LLM) applications require long input context in order to perform complex tasks like document analysis and code generation. For these long context length applications, the length of the input prompt poses a significant challenge in terms of inference efficiency since the inference costs increase linearly with sequence length. However, for many of these applications, much of the context in the prompt is fixed across different user inputs, thereby providing the opportunity to perform offline optimizations in order to process user inputs quickly, as they are received. We propose Squeezed Attention to accelerate LLM applications where a large portion of the input context is fixed. We first leverage K-means clustering offline to group the keys for the fixed context based on semantic similarity and represent each cluster with a single centroid value. During inference, we compare query tokens from the user input with the centroids to predict which keys from the fixed context are semantically relevant, and then compute exact attention using only the important keys, thereby reducing bandwidth and computational costs. We also present a hierarchical version of our algorithm which can reduce the complexity of attention from linear to logarithmic with respect to the fixed context length. We evaluate our method on long-context benchmarks including LongBench, where it achieves a 3.1$\times$ reduction in KV budget with no noticeable accuracy loss and up to an 8$\times$ reduction with only a 0.5 point accuracy gap for the LLaMA-2-7B-32K, LWM-Text-Chat-1M, and Longchat-7B-v1.5-32K models. Futhermore, we implement kernels for centroid comparison and sparse FlashAttention with important keys, achieving more than 4$\times$ speedups during both the prefill and generation phases for long-context inference. Our code is available at https://github.com/SqueezeAILab/SqueezedAttention.
format Preprint
id arxiv_https___arxiv_org_abs_2411_09688
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Squeezed Attention: Accelerating Long Context Length LLM Inference
Hooper, Coleman
Kim, Sehoon
Mohammadzadeh, Hiva
Maheswaran, Monishwaran
Zhao, Sebastian
Paik, June
Mahoney, Michael W.
Keutzer, Kurt
Gholami, Amir
Computation and Language
Emerging Large Language Model (LLM) applications require long input context in order to perform complex tasks like document analysis and code generation. For these long context length applications, the length of the input prompt poses a significant challenge in terms of inference efficiency since the inference costs increase linearly with sequence length. However, for many of these applications, much of the context in the prompt is fixed across different user inputs, thereby providing the opportunity to perform offline optimizations in order to process user inputs quickly, as they are received. We propose Squeezed Attention to accelerate LLM applications where a large portion of the input context is fixed. We first leverage K-means clustering offline to group the keys for the fixed context based on semantic similarity and represent each cluster with a single centroid value. During inference, we compare query tokens from the user input with the centroids to predict which keys from the fixed context are semantically relevant, and then compute exact attention using only the important keys, thereby reducing bandwidth and computational costs. We also present a hierarchical version of our algorithm which can reduce the complexity of attention from linear to logarithmic with respect to the fixed context length. We evaluate our method on long-context benchmarks including LongBench, where it achieves a 3.1$\times$ reduction in KV budget with no noticeable accuracy loss and up to an 8$\times$ reduction with only a 0.5 point accuracy gap for the LLaMA-2-7B-32K, LWM-Text-Chat-1M, and Longchat-7B-v1.5-32K models. Futhermore, we implement kernels for centroid comparison and sparse FlashAttention with important keys, achieving more than 4$\times$ speedups during both the prefill and generation phases for long-context inference. Our code is available at https://github.com/SqueezeAILab/SqueezedAttention.
title Squeezed Attention: Accelerating Long Context Length LLM Inference
topic Computation and Language
url https://arxiv.org/abs/2411.09688