A Practical Workflow for Optimizing LLM Inference
A deployment guide explains how Prefill, Decode, and KV Cache relate to time to first token, throughput, and concurrent serving capacity. It recommends evaluating quantization, Prefix Cache, PagedAttention and Continuous Batching, scheduling parameters, chunked prefill, and speculative decoding in stages. The author also provides a single-card A100-80G comparison for a 7B model, while noting that results vary with the model and hardware and that gains should be validated with workload-specific tests and quality evaluations.
The guide gives inference-service teams an actionable optimization sequence, connecting caching, batching, quantization, and scheduling to specific latency, memory, and throughput constraints while emphasizing measurement and quality regression testing.
大模型推理为什么这么贵?从 KV Cache 到投机解码的一线优化实录
一、先把账单拆开
做过线上大模型服务的人都会经历同一个瞬间:Demo 跑得挺好,一算账单吓一跳。
一次 7B 模型、2048 输入 + 512 输出的请求,看起来只是"跑了个模型",但显存、算力、带宽三样东西同时在烧。想优化,先得分清钱花在哪:
| 阶段 | 主要开销 | 是否可优化 | 优化手段 |
|---|---|---|---|
| Prefill(预填充) | 算力密集,一次性处理全部输入 | 可缓存、可复用 | Prefix Cache、Prompt 压缩 |
| Decode(逐字生成) | 访存密集,每生成一个 token 都要读一遍权重 | 可并行、可批处理 | Continuous Batching、KV Cache、投机解码 |
| 显存 | KV Cache 随并发线性增长 | 可压缩 | PagedAttention、量化、GQA |
一句话结论:Prefill 决定首 token 延迟(TTFT),Decode 决定吞吐(TPS),KV Cache 决定你能同时服务多少人。