← 回到 Reading
Daily Dose of DS 2026-11-26

Rethinking KV Caching for Production LLM Inference

Daily Dose of Data Science 正在舉辦為期四天的 Thanksgiving 特賣,提供終身平台存取權限,價格僅為年費的兩倍,而非標準的三倍。該訂閱提供超過 140 門專為 AI engineering 職涯量身打造的技術課程與資源,並附帶每週深度探討。主要主題領域包括 reinforcement learning、agentic architectures、MLOps、LLMOps、RAG 系統與 tool integration。AI agents 消耗的 token 數量是標準 query 的 5 到 30 倍,因為傳輸內容中約有 62% 是由重複的 system prompt、tool definition 與文件組成。傳統的 prefix caching 雖能節省成本,但受限於嚴格的 byte-for-byte prefix 匹配要求,且因在 inference engine process 內部執行 cache management 而導致推論降速。為克服這些限制,開源專案 LMCache 將 cache management 解耦為與 engine 並行執行的獨立 process,使 time-to-first-token 提升高達 14 倍。此外,LMCache 還整合了 CacheBlend 技術,透過選擇性重新計算 cross-document attention,將 multi-document RAG query 的速度提升 2 到 4 倍。Large language models 透過預測 next-token 的機率分佈以 autoregressive 方式生成文字,而非一次輸出完整句子。為了決定選取哪些 token,會使用不同的 decoding strategies 來平衡連貫性、隨機性與 sequence likelihood。常見方法包括 greedy decoding、基於 temperature 的 probabilistic sampling 以及 beam search。Beam search 維護多條候選路徑以更好地最大化整體 sequence probability,而 repetition-penalizing 方法則有助於防止在長文本生成期間出現重複循環。

目錄 3 段
  1. 01最後 4 天] 終身帳號 Thanksgiving 特賣
  2. 02重新思考適用於 production inference 的 KV caching
  3. 034 種 LLM 文字生成策略
THANKSGIVING SALE

最後 4 天] 終身帳號 Thanksgiving 特賣

Daily Dose of Data Science 正在舉辦為期四天的 Thanksgiving 特賣,提供終身平台存取權限,價格僅為年費的兩倍,而非標準的三倍。該訂閱提供超過 140 門專為 AI engineering 職涯量身打造的技術課程與資源,並附帶每週深度探討。主要主題領域包括 reinforcement learning、agentic architectures、MLOps、LLMOps、RAG 系統與 tool integration。

  • 為期四天的 Thanksgiving 促銷活動將 Daily Dose of Data Science 終身會員資格打折至年費的 2 倍。
  • 終身存取權限包含 140 多項現有的技術資源,以及持續每週涵蓋 data science 與 AI engineering 的深度探討。
  • 核心課程領域涵蓋 reinforcement learning、agentic systems、MLOps、LLMOps 和 RAG 的多篇系列課程。
  • 該學習平台包含針對開發者工具與框架的實作模組,例如 LangChain、LangGraph、MCP 與 PySpark。
DEEP DIVE

重新思考適用於 production inference 的 KV caching

AI agents 消耗的 token 數量是標準 query 的 5 到 30 倍,因為傳輸內容中約有 62% 是由重複的 system prompt、tool definition 與文件組成。傳統的 prefix caching 雖能節省成本,但受限於嚴格的 byte-for-byte prefix 匹配要求,且因在 inference engine process 內部執行 cache management 而導致推論降速。為克服這些限制,開源專案 LMCache 將 cache management 解耦為與 engine 並行執行的獨立 process,使 time-to-first-token 提升高達 14 倍。此外,LMCache 還整合了 CacheBlend 技術,透過選擇性重新計算 cross-document attention,將 multi-document RAG query 的速度提升 2 到 4 倍。

  • 一項 Stanford 的研究發現,每次呼叫傳送給 AI agents 的內容中,約有 62% 是由重複的 prompt、tool definition 與 context 組成。
  • Prefix caching 需要完全一致的 byte-for-byte prefix 匹配,當文件順序改變或在 RAG 工作流程中組合多份文件時,會導致完全 cache miss。
  • Alibaba Cloud 的 production 數據顯示,10% 的 KV cache blocks 貢獻了 77% 的 cache hits,而在嚴格的 prefix 規則下,大部分已快取的內容從未被重複使用。
  • 在 inference engine process 內部執行 cache management 與 quantization 會導致 resource contention,例如在 Google TurboQuant 中觀察到推論速度減慢超過 20%。
  • LMCache 使用 shared GPU memory 在獨立 process 中運作 cache management,消除了 resource contention,並實現了跨 GPU、CPU、SSD 及 remote storage 的 multi-tier 平行載入。
  • 榮獲 EuroSys 2025 Best Paper Award 的 CacheBlend 技術,透過選擇性地僅重新計算 cross-document token interactions,將 multi-document 處理速度提升了 2 到 4 倍。
LLMs

4 種 LLM 文字生成策略

Large language models 透過預測 next-token 的機率分佈以 autoregressive 方式生成文字,而非一次輸出完整句子。為了決定選取哪些 token,會使用不同的 decoding strategies 來平衡連貫性、隨機性與 sequence likelihood。常見方法包括 greedy decoding、基於 temperature 的 probabilistic sampling 以及 beam search。Beam search 維護多條候選路徑以更好地最大化整體 sequence probability,而 repetition-penalizing 方法則有助於防止在長文本生成期間出現重複循環。

  • LLMs 透過預測候選 next tokens 的機率來逐步生成文字,而非預先知道完整的句子。
  • Greedy decoding 在每一步都選取機率最高的 token,但經常會產生重複的輸出。
  • Sampling 從機率分佈中選取 token,並由 temperature 參數控制隨機程度。
  • Greedy selection 和 sampling 都僅針對緊接的下一個 token 進行最佳化,而非針對 sequence-level 的機率。
  • Beam search 在每一步展開前 k 個候選序列以逼近 global sequence probability 的最大化,這使其在機器翻譯中廣受歡迎。
  • 根據候選 token 與先前 token 的相似度給予懲罰(penalizing),可提高輸出的多樣性,並防止在較長文本生成時陷入重複循環。