ChatPaper.aiChatPaper

Prompt Cache: Riutilizzo Modulare dell'Attenzione per Inferenza a Bassa Latenza

Prompt Cache: Modular Attention Reuse for Low-Latency Inference

November 7, 2023
Autori: In Gim, Guojun Chen, Seung-seob Lee, Nikhil Sarda, Anurag Khandelwal, Lin Zhong
cs.AI

Abstract

Presentiamo Prompt Cache, un approccio per accelerare l'inferenza nei grandi modelli linguistici (LLM) riutilizzando gli stati di attenzione tra diversi prompt di LLM. Molti prompt di input contengono segmenti di testo sovrapposti, come messaggi di sistema, modelli di prompt e documenti forniti come contesto. La nostra intuizione chiave è che precalcolando e memorizzando gli stati di attenzione di questi segmenti di testo ricorrenti sul server di inferenza, possiamo riutilizzarli in modo efficiente quando questi segmenti compaiono nei prompt degli utenti. Prompt Cache utilizza uno schema per definire esplicitamente tali segmenti di testo riutilizzabili, chiamati moduli di prompt. Lo schema garantisce l'accuratezza posizionale durante il riutilizzo degli stati di attenzione e fornisce agli utenti un'interfaccia per accedere agli stati memorizzati nella cache nei loro prompt. Utilizzando un'implementazione prototipo, valutiamo Prompt Cache su diversi LLM. Dimostriamo che Prompt Cache riduce significativamente la latenza nel tempo al primo token, specialmente per prompt più lunghi come risposte a domande basate su documenti e raccomandazioni. I miglioramenti vanno da 8x per l'inferenza basata su GPU a 60x per l'inferenza basata su CPU, mantenendo l'accuratezza dell'output e senza la necessità di modifiche ai parametri del modello.
English
We present Prompt Cache, an approach for accelerating inference for large language models (LLM) by reusing attention states across different LLM prompts. Many input prompts have overlapping text segments, such as system messages, prompt templates, and documents provided for context. Our key insight is that by precomputing and storing the attention states of these frequently occurring text segments on the inference server, we can efficiently reuse them when these segments appear in user prompts. Prompt Cache employs a schema to explicitly define such reusable text segments, called prompt modules. The schema ensures positional accuracy during attention state reuse and provides users with an interface to access cached states in their prompt. Using a prototype implementation, we evaluate Prompt Cache across several LLMs. We show that Prompt Cache significantly reduce latency in time-to-first-token, especially for longer prompts such as document-based question answering and recommendations. The improvements range from 8x for GPU-based inference to 60x for CPU-based inference, all while maintaining output accuracy and without the need for model parameter modifications.
PDF322February 7, 2026