Inference optimization
运行 LLM 只是起点。要让它更快、更高效并具备可扩展性,就需要进行 inference optimization。
为什么需要优化 inference?
在演示中能够运行的配置,面对真实 traffic 时可能会失败。随着请求排队,latency 可能上升;throughput 可能在尚未达到硬件容量时就陷入停滞;成本也可能比预期增长得更快。在生产环境中,优化可以帮助你以产品能够承受的成本实现 latency 和 throughput 目标。
优化还能让你更好地控制各种权衡。一些 workload 需要为交互式用户提供低 latency,另一些则需要为 batch job 提供最大的 throughput。Long-context 应用需要谨慎管理 KV cache。Multi-tenant 系统需要合理的 routing 和 scheduling policy,避免一种 workload 影响另一种 workload。
如果你使用 serverless endpoint(例如 OpenAI API),其中许多工作都被抽象掉了,但相关权衡仍会影响价格、rate limit 和响应时间。如果你自行托管 open-source model 或自定义模型,应用合适的优化技术可以让 serving stack 适应实际 workload,而不是被动接受默认 runtime 提供的能力。
LLM performance benchmark
LLM performance benchmark 是衡量 LLM 在特定条件下表现的标准化测试,重点关注 throughput、latency、成本效率和 resource utilization 等实用 metric。
Static、dynamic 与 continuous batching
使用 static batching、dynamic batching 和 continuous batching 优化 LLM inference,以提高 GPU utilization。
PagedAttention
通过 PagedAttention 使用基于 block 的 KV cache storage,改善 LLM 的内存使用效率。
Speculative decoding
Speculative decoding 使用由 target model 验证的 draft model prediction,加速 LLM inference。
Prefill-decode disaggregation
将 prefill 与 decode 分离,以改善并行执行、resource allocation 和 scaling。
Prefix caching
Prefix caching 通过跨请求复用共享的 prompt KV cache,加速 LLM inference。
Inference routing
根据 cache locality、queue depth、KV cache pressure 和 worker state 对 LLM 请求进行 routing,以降低 latency 并提高利用率。
KV cache offloading
了解 KV cache offloading 如何通过减少 GPU memory 占用、降低 latency 和削减 compute 成本来改善 LLM inference。
Data、tensor、pipeline、expert 与 hybrid parallelism
了解 data parallelism、tensor parallelism、pipeline parallelism、expert parallelism 和 hybrid parallelism 之间的区别。
Offline batch inference
使用 offline batch inference 大规模运行 prediction,实现高效的非实时处理。