目标
通过调整 vLLM 的 batch 策略,观察吞吐量和延迟的变化。
背景
vLLM 默认使用 Continuous Batching(持续批处理),但有几个关键参数影响性能:
实验步骤
1. 基准测试
# 默认配置vllm serve Qwen/Qwen2.5-7B-Instruct \ --gpu-memory-utilization 0.90 \ --max-num-seqs 256 \ --max-model-len 4096
用 vLLM 自带的 benchmark 工具测试:
python -m vllm.entrypoints.openai.benchmark \ --backend vllm \ --model Qwen/Qwen2.5-7B-Instruct \ --dataset-name random \ --random-input 1024 \ --random-output 128 \ --max-num-seqs 256
2. 调整 max-num-seqs
3. 调整 gpu-memory-utilization
4. 分析结果
结论: - 吞吐随 batch size 增加而提升,但不是线性的 - 延迟也随 batch size 增加而增加 - 最优值取决于请求长度分布 - 需要根据实际业务的 QPS 和延迟要求找到平衡点
思考题