Skip to Content
人工智能系统性能工程 (Chinese Edition)
book

人工智能系统性能工程 (Chinese Edition)

by Chris Fregly
November 2025
Intermediate to advanced
1060 pages
14h 20m
Chinese
O'Reilly Media, Inc.
Content preview from 人工智能系统性能工程 (Chinese Edition)

第16章. 大规模推理的性能分析 、调试与优化

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

运营大型LLM推理集群需要监控和调试工具来确保系统按预期运行。当性能偏离目标时,这些工具还能帮助您快速定位瓶颈。

本章将演示如何运用NVIDIA Nsight Systems等性能分析工具及Prometheus/Grafana等集群级遥测工具监控调试复杂系统。同时展示如何收集并解读关键指标,包括GPU利用率、内存压力、尾部延迟百分位数、缓存命中率、单令牌耗时等,这些指标将指导我们优化推理引擎性能。

接下来探讨运维级性能调优,涵盖经生产环境验证的优化方案:通过计算通信重叠、请求调度批处理、高效运用NVLink/NVSwitch/InfiniBand高速互连技术,实现GPU利用率提升、推理延迟降低及大规模集群吞吐量增长。

我们将对比实时推理量化技术,包括通过通用后训练量化(GPTQ)和激活感知权重量化(AWQ)等方案将模型压缩至8位及4位精度的方法。同时探讨仅量化权重与同时量化权重及激活值之间的权衡关系。针对服务管道中的量化应用,我们将提供实操指南,在保持模型精度的同时降低内存占用并提升吞吐量。

最后探讨应用层优化策略以补充底层性能调优,涵盖 prompt 压缩、前缀缓存、去重处理、查询路由(如备用模型)及部分输出流式传输等技术。

推理性能的剖析、调试与优化

现代 LLM 推理引擎存在大量动态组件 ,尤其在解耦预填充与解码机制下。典型请求的生命周期涉及众多组件,如图16-1所示。

Diagram illustrating the lifecycle of a request in a disaggregated prefill and decode LLM inference system, showing interactions between the orchestrator and prefill instances for token management and cache handling.
图16-1. 分解式预填充与解码LLM推理系统中典型请求的生命周期

鉴于此复杂性,推理性能调优工作流具有高度迭代性,需要精细调试与持续验证。

首先需观察指标并识别当前瓶颈,例如GPU未充分利用或延迟超出预期。随后提出优化假设,如"增大批量大小"或"提升操作X的通信-计算重叠度"。接着实施修复方案并验证假设。

理想情况下,应在预发布环境中使用典型工作负载测试修复方案,借助剖析工具验证变更效果是否符合预期。例如可验证操作是否实现了正确的内存与计算重叠。

最后将修复方案部署至生产环境,通过Grafana监控和日志验证其在实际负载下是否提升了吞吐量与降低了延迟。当出现新瓶颈时重复此工作流。

这种观察-假设-调优的循环应持续进行。现代部署通常会自动化这些步骤,例如通过计划性负载测试(配合关键指标异常检测)触发调优工作流。

在将优化方案(包括更新的推理运行时和模型变体)部署至生产环境时,建议采用金丝雀发布策略。通过将优化方案部署到少量服务器处理的小部分流量,可在全面部署前验证优化效果。这种渐进式方法能及早发现意外副作用,在不影响所有用户的前提下缩小其影响范围。

假设因过量分词或推理数据预处理导致主机CPU利用率飙升至100%,这将限制推理引擎的并发流处理能力。解决方案之一是将预处理迁移至GPU,可采用GPU加速分词库或使用CUDA/OpenAI Triton语言编写的自定义GPU内核。

部署新库或内核后,需监控前后CPU利用率变化。若观察到CPU利用率下降且整体吞吐量提升,则表明系统已摆脱基于CPU的输入预处理瓶颈。

还需关注各类缓存(包括前缀缓存、prompt嵌入缓存和键值缓存)的命中率 。需建立"缓存命中"与"缓存未命中"的指标对比。高命中率表明系统有效复用了数据;反之若未命中率偏高,则需调整缓存大小、淘汰策略或缓存机制以提升命中率。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

产品思维工程师 (Chinese Edition)

产品思维工程师 (Chinese Edition)

Drew Hoskins

Publisher Resources

ISBN: 0642572281557