Skip to content
🔗 分享本题
查看我的学习进度 →

推理框架专题第3题核心机制与工程取舍图解

🧠 图解记忆: PagedAttention 管 KV 怎么放,RadixAttention 管公共前缀怎么找、怎么复用,两者可以组合。

💡 答案要点

RadixAttention = SGLang 的核心技术创新

核心思想:

  • 多轮对话场景中,前缀(system prompt、few-shot examples)通常是共享的
  • RadixAttention 用基数树(Radix Tree)管理 KV Cache
  • 实现跨请求的前缀复用和自动缓存

工作原理:

请求1: [System] + [User1] → 生成 [Response1]
请求2: [System] + [User2] → 生成 [Response2]
请求3: [System] + [User1追问] → 生成 [Response3]

RadixAttention 的 KV Cache 结构:
         [System]

    [User1] ← → [User2]
      ↓            ↓
  [Response1]  [Response2]

  [User1追问] → [Response3]

→ System prompt 的 KV Cache 被三个请求共享

性能对比:

指标PagedAttention (vLLM)RadixAttention (SGLang)
前缀缓存支持(具体策略随版本变化)支持(基数树管理与复用)
多轮对话效率取决于缓存命中和调度重点优化跨请求前缀复用
主要区别分页 KV 管理是基础机制Radix Tree 同时组织前缀匹配、缓存和淘汰

面试话术:

"RadixAttention 用基数树组织 token 前缀及其 KV Cache,使相同 system prompt、few-shot 或多轮历史可以跨请求匹配和复用。它和 PagedAttention 关注点不同:前者强调前缀缓存的组织与淘汰,后者强调 KV 块的分页内存管理;现代框架可能同时具备分页管理和前缀缓存能力。"

📚 参考:SGLang:RadixAttention(原论文)