|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Shared benchmarking utilities for InferenceMAX |
| 4 | + |
| 5 | +# Run benchmark serving with standardized parameters |
| 6 | +# All parameters are required |
| 7 | +# Parameters: |
| 8 | +# --model: Model name |
| 9 | +# --port: Server port |
| 10 | +# --backend: Backend type - 'vllm' or 'openai' |
| 11 | +# --input-len: Random input sequence length |
| 12 | +# --output-len: Random output sequence length |
| 13 | +# --random-range-ratio: Random range ratio |
| 14 | +# --num-prompts: Number of prompts |
| 15 | +# --max-concurrency: Max concurrency |
| 16 | +# --result-filename: Result filename without extension |
| 17 | +# --result-dir: Result directory |
| 18 | +run_benchmark_serving() { |
| 19 | + local model="" |
| 20 | + local port="" |
| 21 | + local backend="" |
| 22 | + local input_len="" |
| 23 | + local output_len="" |
| 24 | + local random_range_ratio="" |
| 25 | + local num_prompts="" |
| 26 | + local max_concurrency="" |
| 27 | + local result_filename="" |
| 28 | + local result_dir="" |
| 29 | + |
| 30 | + # Parse arguments |
| 31 | + while [[ $# -gt 0 ]]; do |
| 32 | + case $1 in |
| 33 | + --model) |
| 34 | + model="$2" |
| 35 | + shift 2 |
| 36 | + ;; |
| 37 | + --port) |
| 38 | + port="$2" |
| 39 | + shift 2 |
| 40 | + ;; |
| 41 | + --backend) |
| 42 | + backend="$2" |
| 43 | + shift 2 |
| 44 | + ;; |
| 45 | + --input-len) |
| 46 | + input_len="$2" |
| 47 | + shift 2 |
| 48 | + ;; |
| 49 | + --output-len) |
| 50 | + output_len="$2" |
| 51 | + shift 2 |
| 52 | + ;; |
| 53 | + --random-range-ratio) |
| 54 | + random_range_ratio="$2" |
| 55 | + shift 2 |
| 56 | + ;; |
| 57 | + --num-prompts) |
| 58 | + num_prompts="$2" |
| 59 | + shift 2 |
| 60 | + ;; |
| 61 | + --max-concurrency) |
| 62 | + max_concurrency="$2" |
| 63 | + shift 2 |
| 64 | + ;; |
| 65 | + --result-filename) |
| 66 | + result_filename="$2" |
| 67 | + shift 2 |
| 68 | + ;; |
| 69 | + --result-dir) |
| 70 | + result_dir="$2" |
| 71 | + shift 2 |
| 72 | + ;; |
| 73 | + *) |
| 74 | + echo "Unknown parameter: $1" |
| 75 | + return 1 |
| 76 | + ;; |
| 77 | + esac |
| 78 | + done |
| 79 | + |
| 80 | + # Validate all required parameters |
| 81 | + if [[ -z "$model" ]]; then |
| 82 | + echo "Error: --model is required" |
| 83 | + return 1 |
| 84 | + fi |
| 85 | + if [[ -z "$port" ]]; then |
| 86 | + echo "Error: --port is required" |
| 87 | + return 1 |
| 88 | + fi |
| 89 | + if [[ -z "$backend" ]]; then |
| 90 | + echo "Error: --backend is required" |
| 91 | + return 1 |
| 92 | + fi |
| 93 | + if [[ -z "$input_len" ]]; then |
| 94 | + echo "Error: --input-len is required" |
| 95 | + return 1 |
| 96 | + fi |
| 97 | + if [[ -z "$output_len" ]]; then |
| 98 | + echo "Error: --output-len is required" |
| 99 | + return 1 |
| 100 | + fi |
| 101 | + if [[ -z "$random_range_ratio" ]]; then |
| 102 | + echo "Error: --random-range-ratio is required" |
| 103 | + return 1 |
| 104 | + fi |
| 105 | + if [[ -z "$num_prompts" ]]; then |
| 106 | + echo "Error: --num-prompts is required" |
| 107 | + return 1 |
| 108 | + fi |
| 109 | + if [[ -z "$max_concurrency" ]]; then |
| 110 | + echo "Error: --max-concurrency is required" |
| 111 | + return 1 |
| 112 | + fi |
| 113 | + if [[ -z "$result_filename" ]]; then |
| 114 | + echo "Error: --result-filename is required" |
| 115 | + return 1 |
| 116 | + fi |
| 117 | + if [[ -z "$result_dir" ]]; then |
| 118 | + echo "Error: --result-dir is required" |
| 119 | + return 1 |
| 120 | + fi |
| 121 | + |
| 122 | + # Clone benchmark serving repo |
| 123 | + local BENCH_SERVING_DIR=$(mktemp -d /tmp/bmk-XXXXXX) |
| 124 | + git clone https://github.com/kimbochen/bench_serving.git "$BENCH_SERVING_DIR" |
| 125 | + |
| 126 | + # Run benchmark |
| 127 | + python3 "$BENCH_SERVING_DIR/benchmark_serving.py" \ |
| 128 | + --model "$model" \ |
| 129 | + --backend "$backend" \ |
| 130 | + --base-url "http://0.0.0.0:$port" \ |
| 131 | + --dataset-name random \ |
| 132 | + --random-input-len "$input_len" \ |
| 133 | + --random-output-len "$output_len" \ |
| 134 | + --random-range-ratio "$random_range_ratio" \ |
| 135 | + --num-prompts "$num_prompts" \ |
| 136 | + --max-concurrency "$max_concurrency" \ |
| 137 | + --request-rate inf \ |
| 138 | + --ignore-eos \ |
| 139 | + --save-result \ |
| 140 | + --percentile-metrics 'ttft,tpot,itl,e2el' \ |
| 141 | + --result-dir "$result_dir" \ |
| 142 | + --result-filename "$result_filename.json" |
| 143 | +} |
0 commit comments