Prefix Caching and Prompt Reuse

Adrian Tam · 2026年11月26日

AI 摘要 AI 生成,可能有误

本文解释了前缀缓存如何让大语言模型推理系统跨请求复用预填充阶段的工作——具体来说,就是为提示词 token 执行的键(key)和值(value)计算。文章介绍了识别最长已缓存前缀的技术,包括块哈希和基数树,以及相关的兼容性考量。文章还讨论了如何设计提示词以最大化缓存复用,以及如何管理缓存容量并衡量其效果。

Overview This post is divided into five parts; they are: • Reusing Prefill Work • Finding the Longest Cached Prefix • Block Hashes, Radix Trees, and Compatibility • Designing Prompts for Reuse • Capacity and Measurement Reusing Prefill Work During prefill, every layer computes keys and values for every prompt token.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Machine Learning Mastery

Build a Lightweight LLM Evaluation Harness in Python

In this article, you will learn how to build a lightweight, reusable LLM evaluation harness in Python that combines exact-match scoring, an LLM-as-a-judge, and versioned...

Anatomy of an LLM Serving Engine

Overview This post is divided into four parts; they are: • The Request Path • A Minimal Asynchronous Engine • Cancellation, Backpressure, and Failure • Metrics and Production Interfaces The Request Path A text-generation workflow from reque

LLM Inference Engineering Roadmap

Decode sits on the left.

Building an MCP Client in Python from Scratch

In this article, you will learn how to build a working MCP client in Python with the official MCP Python SDK 2.0, connect it to...

Long-Context Inference

AI 摘要The article discusses long-context inference, structured in four parts: the cost of a long context, chunked prefill, managing long-lived KV state, and selecting useful context. It begins by explaining that for full causal attention over a prompt of N tokens, prefill attention computes a triangular portion of an N×N score matrix.