AI Dictionary › Modelli AI
The KV cache is an optimization technique used during text generation with attention-based models, which consists of saving and reusing the key and value vectors computed for already-processed tokens, instead of recomputing them every time a new token is generated. It drastically reduces the amount of repeated computation needed during sequential text generation.
The KV cache is an optimization technique used during text generation with attention-based models, which consists of saving and reusing the key and value vectors computed for already-processed tokens, instead of recomputing them every time a new token is generated. It drastically reduces the amount of repeated computation needed during sequential text generation.
When a model generates text one token at a time, computing the new token requires relating, through attention, its representation to that of every preceding token in the sequence. Without caching, this would require recomputing from scratch the keys and values of all previously generated tokens for every single new token produced. With the KV cache, these vectors are computed only once per token and kept in memory, allowing them to be reused directly in subsequent steps.
It is an essential component of every efficient inference system for large language models: it largely determines the amount of memory needed to serve requests with long contexts and directly affects the latency and throughput of text generation systems. Techniques such as sharing keys and values across multiple attention heads were developed specifically to reduce the KV cache's memory footprint in more recent models.
The name comes directly from the elements being cached, the keys and values of the attention mechanism, and it is a technique that became central with the large-scale spread of generative language models based on attention architectures.
La KV cache è una tecnica di ottimizzazione usata durante la generazione di testo con modelli basati su attenzione, che consiste nel salvare e riutilizzare i vettori chiave (key) e valore (value) calcolati per i token già elaborati, invece di ricalcolarli ogni volta che si genera un nuovo token. Riduce drasticamente la quantità di calcolo ripetuto necessario durante la generazione sequenziale del testo.
Quando un modello genera testo un token alla volta, per calcolare il nuovo token deve far interagire, tramite attenzione, la sua rappresentazione con quella di tutti i token precedenti nella sequenza. Senza memorizzazione, questo richiederebbe di ricalcolare da zero le chiavi e i valori di tutti i token già generati a ogni singolo nuovo token prodotto. Con la KV cache, questi vettori vengono calcolati una sola volta per ciascun token e conservati in memoria, permettendo di riutilizzarli direttamente nei passi successivi.
È una componente essenziale di ogni sistema di inferenza efficiente per modelli linguistici di grandi dimensioni: determina in larga parte la quantità di memoria necessaria per servire richieste con contesti lunghi e influenza direttamente la latenza e il throughput dei sistemi di generazione di testo. Tecniche come la condivisione delle chiavi e dei valori tra più teste di attenzione sono state sviluppate proprio per ridurre l'impronta di memoria della KV cache nei modelli più recenti.
Il nome deriva direttamente dagli elementi che vengono memorizzati, le chiavi (key) e i valori (value) del meccanismo di attenzione, ed è un accorgimento diventato centrale con la diffusione su larga scala dei modelli linguistici generativi basati su architetture ad attenzione.
From our network
Kaimaki Web — Websites That Win Customers
Custom websites, web apps and digital marketing for growing businesses.
Visit kaimakiweb.com →From the Agora Intelligence blog
📱 Download the Android app (beta) iOS coming soon
Say what you mean. Get what you need.
Grace Certified — the AI coach that trains and certifies your prompt engineering — by Agora Intelligence.