目标
学会用工具定位推理服务的性能瓶颈。
工具链
步骤
1. 实时监控
# 终端 1:监控 GPUwatch -n 1 nvidia-smi# 终端 2:启动推理服务vllm serve Qwen/Qwen2.5-7B-Instruct# 终端 3:发起请求curl http://localhost:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"model": "Qwen/Qwen2.5-7B-Instruct", "messages": [{"role": "user", "content": "讲一个故事"}], "max_tokens": 500}'
观察:
2. 系统级 Profiling
# 使用 nsys 分析推理服务nsys profile --stats=true \ --sample=cpu \ --trace=cuda,nvtx \ python -m vllm.entrypoints.openai.api_server \ --model Qwen/Qwen2.5-7B-Instruct
生成报告后,查看:
3. 判断瓶颈类型
GPU 利用率 > 80% → Compute-bound GPU 利用率 < 50%,显存带宽满 → Memory-bound GPU 利用率 < 50%,带宽也空闲 → IO-bound 或 batch 太小 对应优化: Compute-bound → Flash Attention、更大的模型 Memory-bound → 量化、减少显存读写 IO-bound → 批量传输、Pin Memory
思考题