Profiling vLLM#
警告
Profiling 仅供 vLLM 开发者和维护者了解代码库不同部分所花费的时间比例。vLLM 最终用户绝不应启用 Profiling,因为它会显著降低推理速度。
我们支持使用 torch.profiler
模块跟踪 vLLM 工作进程。您可以通过将 VLLM_TORCH_PROFILER_DIR
环境变量设置为您想要保存跟踪的目录来启用跟踪:VLLM_TORCH_PROFILER_DIR=/mnt/traces/
OpenAI 服务器也需要使用设置了 VLLM_TORCH_PROFILER_DIR
环境变量来启动。
当使用 benchmarks/benchmark_serving.py
时,您可以通过传递 --profile
标志来启用 profiling。
可以使用 https://ui.perfetto.dev/ 可视化跟踪结果。
提示
在进行 profiling 时,仅通过 vLLM 发送少量请求,因为跟踪文件可能会变得非常大。此外,无需解压跟踪文件,它们可以直接查看。
提示
要停止 profiler - 它会将所有 profiling 跟踪文件刷新到目录。这需要时间,例如对于大约 100 个请求的 llama 70b 数据,在 H100 上大约需要 10 分钟才能刷新完成。在启动服务器之前,将环境变量 VLLM_RPC_TIMEOUT 设置为一个较大的数字。例如设置为 30 分钟。export VLLM_RPC_TIMEOUT=1800000
命令和用法示例#
离线推理#
OpenAI 服务器#
VLLM_TORCH_PROFILER_DIR=./vllm_profile python -m vllm.entrypoints.openai.api_server --model meta-llama/Meta-Llama-3-70B
benchmark_serving.py
python benchmarks/benchmark_serving.py --backend vllm --model meta-llama/Meta-Llama-3-70B --dataset-name sharegpt --dataset-path sharegpt.json --profile --num-prompts 2