vllm自动化压测脚本

生成结果benchmark_summary.txt如下所示:

bash 复制代码
input_len,output_len,num_prompts,concurrency,output_throughput,total_throughput,duration_sec,mean_ttft_ms,mean_tpot_ms,mean_itl_ms
2048,2048,4,1,523.4,1046.8,12.3,21.5,11.2,9.7
32768,2048,16,4,487.1,982.6,35.6,48.3,13.9,10.4

日志保存在logs/下,result-filename保存在results/下,自动化压测脚本如下:

bash 复制代码
#!/usr/bin/env bash

set -euo pipefail

###############################
# ===== 参数配置区 =====
###############################
BACKEND="vllm"
BASE_URL="http://127.0.0.1:30734"
ENDPOINT="/v1/completions"
DATASET_NAME="random"
MODEL="qwen3.5"
TOKENIZER="/model/Qwen3.5-27B"
SEED="12345"

RANDOM_INPUT_LENS=(2048 32768 65536 131072)
RANDOM_OUTPUT_LENS=(2048)
MAX_CONCURRENCY_LIST=(1 4 8 16)

LOG_DIR="logs"
RESULT_DIR="results"
SUMMARY_TXT="benchmark_summary.txt"

mkdir -p "${LOG_DIR}" "${RESULT_DIR}"

if [[ ! -f "${SUMMARY_TXT}" ]]; then
  cat > "${SUMMARY_TXT}" <<EOF
input_len,output_len,num_prompts,concurrency,output_throughput,total_throughput,duration_sec,mean_ttft_ms,mean_tpot_ms,mean_itl_ms
EOF
fi

###############################
# ===== 工具函数 =====
###############################
parse_metric() {
  local json_file="$1"
  local key="$2"
  jq -r ".${key} // \"0\"" "$json_file"
}

###############################
# ===== 主循环 =====
###############################
for input_len in "${RANDOM_INPUT_LENS[@]}"; do
  for output_len in "${RANDOM_OUTPUT_LENS[@]}"; do
    for max_concurrency in "${MAX_CONCURRENCY_LIST[@]}"; do

      num_prompts=$((max_concurrency * 4))

      base_name="input=${input_len},output=${output_len},num_prompts=${num_prompts},concurrency=${max_concurrency}"
      log_path="${LOG_DIR}/${base_name}.log"
      result_json="${RESULT_DIR}/${base_name}.json"

      echo "=========================================="
      echo "RUNNING:"
      echo "  input_len=${input_len}"
      echo "  output_len=${output_len}"
      echo "  max_concurrency=${max_concurrency}"
      echo "  num_prompts=${num_prompts}"
      echo "  log=${log_path}"
      echo "  result=${result_json}"
      echo "=========================================="

      vllm bench serve \
        --backend "${BACKEND}" \
        --base-url "${BASE_URL}" \
        --endpoint "${ENDPOINT}" \
        --dataset-name "${DATASET_NAME}" \
        --model "${MODEL}" \
        --tokenizer "${TOKENIZER}" \
        --seed "${SEED}" \
        --random-input-len "${input_len}" \
        --random-output-len "${output_len}" \
        --num-prompts "${num_prompts}" \
        --max-concurrency "${max_concurrency}" \
        --save-result \
        --result-dir "${RESULT_DIR}" \
        --result-filename "$(basename "${result_json}")" \
        > "${log_path}" 2>&1

      echo "DONE: ${log_path}"
      echo

      # =========================
      # 解析指标
      # =========================
      if [[ -f "${result_json}" ]]; then
        output_throughput=$(parse_metric "${result_json}" "output_throughput")
        total_throughput=$(parse_metric "${result_json}" "total_token_throughput")
        duration=$(parse_metric "${result_json}" "duration")
        mean_ttft=$(parse_metric "${result_json}" "mean_ttft_ms")
        mean_tpot=$(parse_metric "${result_json}" "mean_tpot_ms")
        mean_itl=$(parse_metric "${result_json}" "mean_itl_ms")

        # ✅ 使用 printf 统一保留一位小数
        printf "%d,%d,%d,%d,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f\n" \
          "${input_len}" \
          "${output_len}" \
          "${num_prompts}" \
          "${max_concurrency}" \
          "${output_throughput}" \
          "${total_throughput}" \
          "${duration}" \
          "${mean_ttft}" \
          "${mean_tpot}" \
          "${mean_itl}" \
          >> "${SUMMARY_TXT}"
      else
        echo "WARNING: Result JSON not found: ${result_json}"
      fi

    done
  done
done

echo "=========================================="
echo "All benchmarks finished."
echo "Logs are stored in: ${LOG_DIR}"
echo "Results are stored in: ${RESULT_DIR}"
echo "Summary TXT: ${SUMMARY_TXT}"
echo "=========================================="
相关推荐
是Dream呀7 天前
从零到一:Triton实现CELU激活函数优化之路
ai·vllm·openclaw
花间相见8 天前
【大模型推理01】—— 初探VLLM:高性能LLM推理引擎,让开源模型跑起来更快更省
开源·vllm
Flying pigs~~8 天前
大模型训练框架 ➕ 推理部署框架
模型训练·deepspeed·vllm·模型推理·zero·pageattention
AI木马人9 天前
2.人工智能实战:大模型接口并发低、GPU利用率上不去?基于 vLLM 重构推理服务的完整工程方案
人工智能·transformer·vllm
AIDF202611 天前
我们看一份报告的时候主要看什么
运维·服务器·推理·vllm
张忠琳11 天前
【vllm】(八)vLLM v1 Simple KV Offload — 系统级架构深度分析之二
ai·架构·vllm
一只独角兽12 天前
DeepSeek-V4-Pro 部署实战指南:H100/H200/B200/B300/GB200/GB300 全硬件配置详解
自然语言处理·gru·transformer·vllm
张忠琳12 天前
【vllm】(六)vLLM v1 Sample — 模块超深度分析之一
ai·架构·vllm
蛐蛐蛐12 天前
在昇腾Atlas 300I Duo+openEuler上部署vLLM并进行推理的流程(一)
vllm