DuoAandacht: Efficiënte inferentie van LLM met lange context met ophaal- en streaming-headers
DuoAttention: Efficient Long-Context LLM Inference with Retrieval and Streaming Heads
October 14, 2024
Auteurs: Guangxuan Xiao, Jiaming Tang, Jingwei Zuo, Junxian Guo, Shang Yang, Haotian Tang, Yao Fu, Song Han
cs.AI
Samenvatting
Het implementeren van lang-context grote taalmodellen (LLMs) is essentieel maar brengt aanzienlijke computationele en geheugen uitdagingen met zich mee. Het cachen van alle Sleutel en Waarde (KV) states over alle aandachtskoppen heen vereist aanzienlijk geheugen. Bestaande KV cache snoeimethoden beschadigen ofwel de lang-context capaciteiten van LLMs of bieden slechts beperkte efficiëntieverbeteringen. In dit artikel identificeren we dat slechts een fractie van aandachtskoppen, ook wel Retrieval Heads genoemd, cruciaal zijn voor het verwerken van lange contexten en volledige aandacht vereisen over alle tokens. Daarentegen vereisen alle andere koppen, die zich voornamelijk richten op recente tokens en aandachtspunten - aangeduid als Streaming Heads - geen volledige aandacht. Op basis van deze inzichten introduceren we DuoAttention, een framework dat alleen een volledige KV-cache toepast op retrieval heads, terwijl het een lichtgewicht, constante lengte KV-cache gebruikt voor streaming heads, wat zowel het decoderen als het vooraf vullen van het geheugen en de latentie van LLM's vermindert zonder de lang-context capaciteiten in gevaar te brengen. DuoAttention maakt gebruik van een lichtgewicht, optimalisatie-gebaseerd algoritme met synthetische data om retrieval heads nauwkeurig te identificeren. Onze methode vermindert de inferentiegeheugen voor lange context aanzienlijk met maximaal 2,55x voor MHA en 1,67x voor GQA-modellen, terwijl het decoderen versneld wordt met maximaal 2,18x en 1,50x en het vooraf vullen versneld wordt met maximaal 1,73x en 1,63x voor respectievelijk MHA en GQA-modellen, met minimaal verlies aan nauwkeurigheid in vergelijking met volledige aandacht. Opmerkelijk is dat DuoAttention in combinatie met kwantisatie Llama-3-8B decodering met een contextlengte van 3,3 miljoen mogelijk maakt op een enkele A100 GPU. De code is beschikbaar op https://github.com/mit-han-lab/duo-attention.
English
Deploying long-context large language models (LLMs) is essential but poses
significant computational and memory challenges. Caching all Key and Value (KV)
states across all attention heads consumes substantial memory. Existing KV
cache pruning methods either damage the long-context capabilities of LLMs or
offer only limited efficiency improvements. In this paper, we identify that
only a fraction of attention heads, a.k.a, Retrieval Heads, are critical for
processing long contexts and require full attention across all tokens. In
contrast, all other heads, which primarily focus on recent tokens and attention
sinks--referred to as Streaming Heads--do not require full attention. Based on
this insight, we introduce DuoAttention, a framework that only applies a full
KV cache to retrieval heads while using a light-weight, constant-length KV
cache for streaming heads, which reduces both LLM's decoding and pre-filling
memory and latency without compromising its long-context abilities.
DuoAttention uses a lightweight, optimization-based algorithm with synthetic
data to identify retrieval heads accurately. Our method significantly reduces
long-context inference memory by up to 2.55x for MHA and 1.67x for GQA models
while speeding up decoding by up to 2.18x and 1.50x and accelerating
pre-filling by up to 1.73x and 1.63x for MHA and GQA models, respectively, with
minimal accuracy loss compared to full attention. Notably, combined with
quantization, DuoAttention enables Llama-3-8B decoding with 3.3 million context
length on a single A100 GPU. Code is provided in
https://github.com/mit-han-lab/duo-attention.Summary
AI-Generated Summary