
系列:AI 论文精读与复现训练营
日期:2026-08-17
适合读者:研究生、LLM 系统入门研究者、有工程背景的 AI 读者
检索日期:2026-08-17
摘要
Efficient Inference 研究的核心不是“让模型跑得快一点”,而是理解自回归生成的成本结构:prefill 阶段通常更像大矩阵计算,decode 阶段则被 KV cache 读写、显存带宽、调度和 batch 形态限制。KV cache、PagedAttention、continuous batching、speculative decoding、量化、prefix cache、prefill/decode disaggregation 和 serving runtime,都是围绕这条成本链条做手术。
本文给出一条论文精读路线:先把推理拆成 TTFT、ITL、throughput、显存、质量和调度六本账,再按 KV cache、speculative decoding、quantization、kernel/runtime、serving system 五条线读代表论文。最后给出可复现的小实验设计,帮助研究生判断一个推理优化方法到底省掉了什么、牺牲了什么、能不能在自己的模型和负载上成立。
目录
- 为什么这个主题重要
- 核心阅读方法
- 代表论文路线图
- 方法与实验对比表
- 复现建议
- 常见误区
- 适合研究生继续做的选题
- 总结与参考资料
为什么这个主题重要
训练效率回答“模型如何被做出来”,推理效率回答“模型如何被反复使用”。对研究生而言,后者同样是严肃研究问题:同一个开源模型,在不同 serving engine、batch policy、cache policy、quantization recipe 和 decoding strategy 下,TTFT、ITL、吞吐、显存峰值和输出质量可能完全不同。论文如果只报告“快了几倍”,但没有说明 prompt 长度、输出长度、batch 到达过程、GPU 型号、并发、sampling 设置和质量检查,结论很难复用。
现代 LLM 推理的第一条物理约束是自回归。生成 100 个 token 不是一次 forward,而是 100 次带状态的迭代。prefill 先处理输入 prompt,生成并保存每层 attention 的 key/value;decode 每步只新增一个或少量 token,但要读取已有 KV cache。长上下文、多轮对话、RAG 和 agent 任务会把 KV cache 变成主要显存资产。TMLR 2025 的 KV cache survey 将相关方法分成 token-level、model-level 和 system-level 优化,说明这个方向已经从单个 trick 变成独立研究地图。
第二条约束是 workload。离线批处理追求 tokens/sec;交互式问答关注 TTFT 和 ITL;代码补全关注短延迟和取消请求;RAG 关注 prefix reuse;agent 工作流关注多次小请求和结构化输出;MoE 模型还多出 expert routing 和跨卡通信。Efficient Inference 论文必须和负载绑定阅读,不能把一个场景里的速度结论直接外推到另一个场景。
核心阅读方法
读推理论文,先画六本账。
第一是 latency 账。TTFT 是从请求到第一个 token 的时间,主要受 prefill、排队、调度和 cache 命中影响;ITL 是连续输出 token 之间的间隔,decode、显存带宽、KV cache 读取和 sampling kernel 更关键。只报告平均延迟不够,最好看 p50/p95/p99。
第二是 throughput 账。tokens/sec 要区分 prompt tokens、generated tokens、总 tokens 和每 GPU tokens/sec。批量越大吞吐通常越高,但用户等待可能变长。continuous batching、chunked prefill、request preemption 和 admission control 都是在吞吐与延迟之间做调度。
第三是 memory 账。模型权重、KV cache、activation 临时量、CUDA graph、workspace、fragmentation、LoRA adapter、paged blocks 都要分开看。PagedAttention 的贡献就在于把 KV cache 从连续分配改成类似虚拟内存的 block 管理,减少碎片和重复存储,从而允许更大的有效 batch。
第四是 quality 账。量化、speculative decoding、cache eviction、prefix reuse、structured decoding 都可能影响输出分布或任务指标。Leviathan 等人的 speculative decoding 明确追求不改变目标模型分布;Medusa-2、近似 cache 复用或低比特量化则需要额外质量评估,不能只看速度。
第五是 implementation 账。FlashAttention、FlashInfer、TensorRT-LLM、vLLM、SGLang、TGI、Transformers cache classes 的结论都依赖 CUDA、ROCm、GPU 架构、kernel 版本、模型结构、dtype 和框架版本。正式复现实验必须写清楚 commit、镜像、驱动和启动参数。
第六是 workload 账。用固定 batch 的 synthetic benchmark 不能代表线上 Poisson 到达;用 128-token prompt 不能代表长上下文;用 greedy decoding 不能代表 top-p sampling;用单轮 QA 不能代表 RAG 或 agent。读论文时要把作者的负载生成器复刻出来,否则速度数字没有坐标系。

代表论文路线图
1. KV Cache 与 PagedAttention:推理显存的基本账本
KV cache 的直觉很简单:自回归模型每步都需要过去 token 的 key/value,如果每次重新计算,代价不可接受;保存并复用 KV 可以减少重复计算,但会占用大量显存。Hugging Face Transformers 文档把 cache strategy 区分为 dynamic、static、offloaded、quantized 等类型,强调不同 cache 在速度、显存和编译兼容性之间有取舍。
PagedAttention 是这条线的关键论文。Kwon 等人在 SOSP 2023 / arXiv 2309.06180 中指出,LLM serving 要高吞吐就要 batching,但每个 request 的 KV cache 巨大且动态变化,低效管理会造成碎片和重复。PagedAttention 借鉴操作系统 paging,把 KV cache 存在非连续 blocks 中;vLLM 在此基础上做 serving system。精读这篇时,不要只记“2-4x throughput”这样的摘要数字,而要追问:baseline 是什么,prompt/output 长度如何分布,latency constraint 怎样固定,beam search 或 parallel sampling 为什么更受益。
2025 之后的 KV cache 研究继续向三类扩展。第一类是压缩和量化,例如 KIVI 研究 key cache 和 value cache 的分布差异,提出 tuning-free asymmetric 2-bit KV cache quantization。第二类是选择、丢弃、合并和预算分配,试图在长上下文里保留最有用的 KV。第三类是系统化复用,例如 LMCache 将 KV cache 从单次请求状态变成可跨请求、跨 engine、跨存储层级复用的基础设施;SGLang 的 RadixAttention 也服务于复杂程序里的 prefix/cache reuse。
2. Speculative Decoding:减少串行 decode 步数
speculative decoding 的问题设定是:decode 必须逐 token 串行,但 GPU 在单 token decode 时利用率低。Leviathan、Kalman 和 Matias 在 ICML 2023 中提出用小 draft model 先猜多个 token,再由大 target model 并行验证;如果验收通过,就一次前进多个 token。该论文的重要约束是“不改变输出分布”,因此它不只是 heuristic acceleration,而是带采样校正的算法。
读 speculative decoding 要抓三点。第一,draft model 的质量决定 acceptance rate;draft 太弱会浪费验证,draft 太强又可能抵消速度收益。第二,速度受 batch size、sequence length、sampling temperature、target/draft 比例影响,不是固定常数。第三,系统实现很关键:两个模型如何放置、KV cache 如何管理、draft 与 target 是否共享 tokenizer、通信和调度是否抵消收益。
Medusa 和 EAGLE 是后续代表。Medusa 不维护独立 draft model,而是在同一 backbone 上加多个 decoding heads,用 tree attention 验证候选;其 arXiv 版本报告了 Medusa-1/Medusa-2 两种训练设置。EAGLE 则把草稿生成转到 feature level,并在 2025 修订版中继续完善。读这些论文时,尤其要区分“lossless acceleration”“保持质量近似不变”和“需要额外训练”的边界。
3. Quantization:权重、激活和 KV Cache 的低精度推理
量化论文最容易被误读成“bit 越低越好”。实际要分清 weight-only、weight+activation、KV cache quantization、FP8/FP4、INT8/INT4、per-channel/per-token/group-wise、calibration set 和 kernel 支持。
GPTQ 是 post-training weight quantization 的经典起点,使用近似二阶信息做 one-shot quantization。SmoothQuant 针对 activation outlier,把量化困难从 activation 平滑迁移到 weights,从而支持 W8A8 推理。AWQ 则观察到保护少量 salient weights 可以显著降低误差,使用 activation-aware scaling 做低比特 weight-only quantization,并在 MLSys 2024 发表。KIVI 把注意力转向 KV cache,指出 key cache 更适合 per-channel,value cache 更适合 per-token。
读量化论文时必须同时检查三张表:质量表、速度表、硬件表。质量表要看任务是否覆盖困惑度、问答、代码、数学、长上下文和多模态;速度表要确认是端到端 serving 还是单 kernel microbenchmark;硬件表要确认 A100/H100/4090/Jetson/MI300X/CPU 的差异。TensorRT-LLM 和 vLLM 文档显示,FP8 KV cache、AWQ、GPTQ、FP4/NVFP4、不同 GPU 后端支持都在持续变化,因此引用时要标注版本和检索日期。
4. Kernel 与 Runtime:从 FlashAttention 到 FlashInfer
推理优化不是只在论文公式里发生。attention kernel、GEMM kernel、sampling kernel、CUDA graph、torch.compile、paged/ragged KV layout、MoE grouped GEMM 和 fused operators 都会决定论文方法是否真的更快。
FlashAttention 系列解决的是 IO-aware attention,训练和 prefill 都受益。FlashInfer 更直接面向 LLM serving kernel,官方仓库列出 prefill、decode、append、paged/ragged KV cache、MLA attention、cascade attention、sparse attention、FP8/FP4、fused MoE、sorting-free sampling 和 speculative decoding 等能力。读 kernel/runtime 文档时,研究问题不是“哪个库最快”,而是弄清楚为什么某个 workload 落到某个 kernel:batch 是否 ragged,KV blocks 是否 paged,是否混合 prefill/decode,是否 MoE,是否 structured output,是否需要低精度。
5. Serving System:vLLM、SGLang、TensorRT-LLM、TGI、LMCache
serving system 论文和文档要按“请求生命周期”来读:入队、tokenize、prefill、KV block 分配、decode step scheduling、sampling、detokenize、streaming、finish、释放 cache、指标上报。vLLM 官网强调 PagedAttention、advanced scheduling 和 continuous batching;SGLang 的 NeurIPS 2024 论文把 structured language model programs 作为对象,使用 RadixAttention 和 runtime 优化支持 agent、few-shot、JSON decoding、RAG、多轮对话等复杂程序;LMCache 把 KV cache 管理独立出来,支持 GPU/CPU/disk/remote storage、非 prefix 复用、prefill/decode disaggregation 和观测指标;TensorRT-LLM 提供量化、speculative decoding、KV cache connector/offloading 等生产级功能;Hugging Face TGI 文档则显示早期 optimized inference engine 的 common feature:continuous batching、Flash/Paged Attention、tensor parallelism、streaming、quantization 和 metrics。
这一类资料更新非常快。阅读时不要把官网宣传语当成论文结论,而要回到 release note、benchmark 脚本、commit、配置文件和可复现实验。尤其是“支持某模型”“支持某量化格式”“支持某 GPU 架构”会随版本变化,文章中只能写检索日期下的状态,正式发布前应重新核对。
方法与实验对比表
| 分支 | 代表资料 | 主要节省对象 | 主要代价 | 精读检查 |
|---|---|---|---|---|
| PagedAttention / vLLM | PagedAttention, vLLM | KV cache 碎片、重复存储、有效 batch | block 管理与调度复杂度 | prompt/output 分布、latency constraint、baseline |
| KV cache quantization | KIVI, Transformers QuantizedCache | KV cache 显存、长上下文 batch | 量化误差、额外 dequant 开销 | key/value 分布、长短上下文、质量指标 |
| Speculative decoding | Leviathan et al., Medusa, EAGLE | 串行 decode 步数 | draft/heads 训练、验收率、系统复杂度 | acceptance rate、distribution/quality、batch size |
| Weight/activation quantization | GPTQ, SmoothQuant, AWQ, TensorRT-LLM | 权重显存、带宽、GEMM 成本 | 校准、kernel 支持、精度下降 | W/A/KV 位宽、校准集、端到端吞吐 |
| Kernel runtime | FlashAttention, FlashInfer | HBM IO、attention/sampling/MoE kernel 开销 | 硬件和版本依赖 | kernel benchmark vs serving benchmark |
| Serving framework | vLLM, SGLang, TGI, TensorRT-LLM | 调度、batch、并行、streaming | 配置复杂、负载敏感 | TTFT、ITL、p95、取消请求、监控 |
| KV reuse layer | LMCache, RadixAttention | 重复 prefill、长上下文复用 | cache 一致性、存储和传输开销 | cache hit rate、reuse 粒度、质量恢复 |
复现建议
第一,做一个最小 serving benchmark。选 7B-8B 级模型,固定 GPU、dtype、prompt 长度分布和 output 长度分布,比较 Transformers generate、vLLM、SGLang 或 TGI。至少记录 TTFT、ITL、request/sec、prompt tokens/sec、decode tokens/sec、GPU memory、GPU utilization、p50/p95。不要只记录单条请求时间。
第二,复现 KV cache 账本。改变 max context、batch size、output length,打开/关闭 paged attention、prefix caching、offloading 或 quantized cache。把显存拆成 model weights、KV cache、其他 runtime workspace。长上下文实验要额外记录 OOM 边界和是否出现 cache eviction。
第三,复现 speculative decoding。用一个 target model 和一个小 draft model,比较 greedy 与 sampling 两种设置。记录 acceptance rate、平均每步接受 token 数、target forward 次数、draft forward 次数、TTFT、ITL、输出一致性或任务指标。如果使用 Medusa/EAGLE,要说明 heads 或 feature predictor 是否重新训练。
第四,复现量化。选择 GPTQ/AWQ/SmoothQuant/FP8 中一个 recipe,固定同一模型和同一评测集。报告 perplexity 或任务指标、端到端 latency、吞吐、显存和加载时间。不要把单个 GEMM kernel 的加速直接等同于应用端到端加速。
第五,做 serving workload ablation。生成三类请求:短 prompt 短输出、长 prompt 短输出、长 prompt 长输出。再分别用低并发、高并发、burst 到达。观察 continuous batching、chunked prefill、prefix cache 和 P/D disaggregation 在不同场景下的变化。负结果要保留,因为推理系统的边界条件比单次最高吞吐更重要。
常见误区
- 把 prefill 和 decode 混成一个指标。TTFT 和 ITL 反映不同瓶颈,优化方向也不同。
- 只看 tokens/sec。高吞吐可能来自大 batch,但 p95 latency 可能不可接受。
- 把 KV cache 当成免费状态。长上下文和高并发下,KV cache 往往比权重更决定 batch 上限。
- 只引用速度倍数,不引用 workload。prompt/output 长度、并发、sampling、GPU、dtype、框架版本缺一不可。
- 忽略质量。量化、近似 cache、structured decoding、non-lossless speculative heads 都需要质量或分布检查。
- 把官网支持矩阵当永久事实。vLLM、SGLang、TensorRT-LLM、FlashInfer、Transformers 和 LMCache 都在快速更新,模型、GPU、量化格式和 API 行为必须按检索日期核对。
适合研究生继续做的选题
- 长上下文 KV cache 策略比较:在 LongBench 或自建长文档 QA 上比较 full cache、quantized cache、offload、selection 和 eviction。
- Speculative decoding workload map:系统研究 draft size、temperature、batch size、输出长度与 acceptance rate 的关系。
- 端到端量化复现报告:比较 AWQ/GPTQ/FP8 在同一 serving engine 下的质量、显存和延迟。
- Prefix cache for RAG:构造多文档复用负载,测量 prefix hit rate、TTFT 和质量。
- P/D disaggregation 小型实验:在两张或多张 GPU 上模拟 prefill worker 与 decode worker,分析传输瓶颈。
- Serving benchmark 可信度研究:比较 synthetic benchmark、真实 trace 和 agent workload 对系统排名的影响。
- Structured output decoding 成本分析:比较 JSON schema、tool call、grammar decoding 在不同 runtime 中的延迟和失败率。
总结
Efficient Inference 的正确读法,是把“更快”拆成可复现的成本账本。KV cache 决定长上下文和并发的显存边界;PagedAttention 和 serving scheduler 决定 batch 是否真正有效;speculative decoding 试图减少串行 decode 步数;quantization 减少权重、激活或 KV 的字节流;kernel/runtime 决定算法能否落到硬件;LMCache、SGLang、vLLM、TensorRT-LLM 等系统则把这些技术组合成请求生命周期。
科研新人可以从一个小模型和一张 GPU 开始训练能力:固定 workload,改变一个推理开关,记录 TTFT、ITL、吞吐、显存、质量和失败案例。只要账本足够清楚,一次“没有加速”的复现实验也可能比一张漂亮的速度表更有研究价值。
参考资料
检索日期:2026-08-17。以下链接优先使用论文页、官方项目页、官方文档、GitHub、PMLR、MLSys、TMLR/ML Anthology、Stanford MAST Lab、Hugging Face 和 NVIDIA 文档。模型支持、GPU 架构、量化格式、benchmark 数字、仓库 commit、API 行为和文档内容变化很快,正式发布前请重新核对;未在一手资料中确认的细节应标注“待人工核验”。
- Efficient Memory Management for Large Language Model Serving with PagedAttention, arXiv 2309.06180 / SOSP 2023: https://arxiv.org/abs/2309.06180
- Efficient Memory Management for Large Language Model Serving with PagedAttention, ACM SOSP 2023: https://doi.org/10.1145/3600006.3613165
- vLLM official website: https://vllm.ai/
- vLLM GitHub repository: https://github.com/vllm-project/vllm
- vLLM quantization documentation: https://docs.vllm.ai/en/latest/features/quantization/
- A Survey on Large Language Model Acceleration Based on KV Cache Management, TMLR 2025 / ML Anthology: https://mlanthology.org/tmlr/2025/li2025tmlr-survey/
- Hugging Face Transformers cache strategies documentation: https://huggingface.co/docs/transformers/main/kv_cache
- KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache, arXiv 2402.02750: https://arxiv.org/abs/2402.02750
- KIVI official GitHub repository: https://github.com/jy-yuan/KIVI
- Fast Inference from Transformers via Speculative Decoding, ICML 2023 / PMLR: https://proceedings.mlr.press/v202/leviathan23a.html
- Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads, arXiv 2401.10774: https://arxiv.org/abs/2401.10774
- Medusa official GitHub repository: https://github.com/FasterDecoding/Medusa
- EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty, arXiv 2401.15077: https://arxiv.org/abs/2401.15077
- GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers, ICLR 2023 / OpenReview record: https://openreview.net/forum?id=tcbBPnfwxS
- GPTQ publication record, ETH Research Collection: https://www.research-collection.ethz.ch/entities/publication/00736213-37b2-4e99-b015-141349b71413
- SmoothQuant official GitHub repository: https://github.com/mit-han-lab/smoothquant
- AWQ: Activation-aware Weight Quantization for On-Device LLM Compression and Acceleration, MLSys 2024: https://proceedings.mlsys.org/paper_files/paper/2024/hash/42a452cbafa9dd64e9ba4aa95cc1ef21-Abstract-Conference.html
- AWQ official GitHub repository: https://github.com/mit-han-lab/llm-awq
- TensorRT-LLM official documentation: https://nvidia.github.io/TensorRT-LLM/
- TensorRT-LLM quantization documentation: https://github.com/NVIDIA/TensorRT-LLM/blob/main/docs/source/features/quantization.md
- TensorRT-LLM speculative decoding documentation: https://github.com/NVIDIA/TensorRT-LLM/blob/main/docs/source/features/speculative-decoding.md
- FlashInfer official GitHub repository: https://github.com/flashinfer-ai/flashinfer
- SGLang: Efficient Execution of Structured Language Model Programs, NeurIPS 2024 / Stanford MAST Lab: https://mast.stanford.edu/pubs/sglang_efficient_execution_of_structured_language_model_programs/
- SGLang official documentation: https://docs.sglang.io/
- LMCache official documentation: https://docs.lmcache.ai/index.html
- LMCache official GitHub repository: https://github.com/LMCache/LMCache
- Hugging Face Text Generation Inference documentation: https://huggingface.co/docs/text-generation-inference/index