[Paper Review] Prompt Cache: Modular Attention Reuse for Low-Latency Inference
Prompt Cache reuses precomputed attention states for reusable prompt modules, achieving 8×–60× TTFT speedups across GPUs/CPUs with no accuracy loss.
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.
Motivation & Objective
- Motivate reduction of inference latency for large language models by exploiting repeated prompt segments such as system messages, templates, or documents.
- Introduce a formal prompt module schema (PML) to explicitly define reusable prompt components and their positions.
- Precompute and cache attention states for prompt modules and reuse them across prompts to minimize attention computations.
- Demonstrate that modular attention reuse maintains output quality while delivering substantial latency reductions on multiple models/datasets.
Proposed method
- Define prompt modules with a Prompt Markup Language (PML) and a schema to enable modular attention reuse.
- Encode and cache attention states for prompt modules on CPU or GPU memory.
- Concatenate cached prompt-module states with newly computed segments to form the full prompt attention state at inference time.
- Adapt transformer architectures to support discontinuous position IDs required by modular attention reuse.
- Prototype implementation built on HuggingFace Transformers and evaluated on Llama2, Falcon, and MPT across LongBench datasets.
Experimental results
Research questions
- RQ1Can attention states be reused across different prompts that share common text segments?
- RQ2How to encode and manage reusable prompt modules to maximize attention reuse without sacrificing correctness?
- RQ3What is the impact of Prompt Cache on latency (time-to-first-token) and end-to-end generation across CPU and GPU deployments?
- RQ4What is the memory overhead of storing precomputed attention states for prompt modules, and how does it scale with model size and prompt length?
- RQ5Does Prompt Cache preserve output quality across diverse LongBench tasks (QA, summarization, code, etc.)?
Key findings
- Prompt Cache reduces time-to-first-token latency significantly, with 8×–10× gains on GPUs and up to 20×–70× on CPUs depending on memory arrangement.
- Output accuracy remains comparable to baseline KV Cache across LongBench tasks and multiple model architectures (Llama2, MPT, Falcon).
- Latency benefits grow with longer prompts and larger cached segments, due to quadratic self-attention costs vs linear cache memory copy costs.
- Storing prompt modules in GPU memory yields higher speedups than CPU memory when possible, but CPU memory offers greater capacity for very large module libraries.
- Parameterizing prompt modules and unions in PML enables flexible, reusable, and composable prompt designs while maintaining reusability of attention states.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.