-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·208 lines (187 loc) · 6.22 KB
/
benchmark.sh
File metadata and controls
executable file
·208 lines (187 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#! /bin/bash
# Default values
host="127.0.0.1"
port=30001
MODEL_ID="meta-llama/Llama-2-7b-chat-hf"
TP_SIZE=4
MAX_SEQ_LEN=4096
BLOCK_SIZE=4096
LENGTH=2048
MAX_NUM_SEQS=8
PLATFORM="torch_compile"
DURATION=1800 # 30 minutes
CHUNK_SIZE=128
# Function to print usage
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -p, --platform <name> Platform to use: 'torch_compile' or 'optimum' (default: $PLATFORM)"
echo " -m, --model-id <name> Model ID (default: $MODEL_ID)"
echo " -t, --tp-size <num> Tensor Parallel size (default: $TP_SIZE)"
echo " -s, --max-seq-len <num> Max sequence length (default: $MAX_SEQ_LEN)"
echo " -b, --block-size <num> Block size (default: $BLOCK_SIZE)"
echo " -n, --max-num-seqs <num> Max number of sequences (default: $MAX_NUM_SEQS)"
echo " -H, --host <ip> Host IP (default: $host)"
echo " -P, --port <num> Port number (default: $port)"
echo " -l, --length <num> Length of the prompt and output tokens (default: $LENGTH)"
echo " -d, --duration <num> Duration of the single benchmark in seconds (default: $DURATION)"
echo " -h, --help Show this help message"
exit 1
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-p|--platform)
PLATFORM="$2"
shift 2
;;
-m|--model-id)
MODEL_ID="$2"
shift 2
;;
-t|--tp-size)
TP_SIZE="$2"
shift 2
;;
-s|--max-seq-len)
MAX_SEQ_LEN="$2"
shift 2
;;
-b|--block-size)
BLOCK_SIZE="$2"
shift 2
;;
-n|--max-num-seqs)
MAX_NUM_SEQS="$2"
shift 2
;;
-H|--host)
host="$2"
shift 2
;;
-P|--port)
port="$2"
shift 2
;;
-l|--length)
LENGTH="$2"
shift 2
;;
-d|--duration)
DURATION="$2"
shift 2
;;
-h|--help)
usage
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done
MODEL_NAME=${MODEL_ID##*/}
# if platform is not in ['torch_compile', 'optimum'], exit
if [ "$PLATFORM" != "torch_compile" ] && [ "$PLATFORM" != "optimum" ]; then
echo "Invalid platform: $PLATFORM, use 'torch_compile' or 'optimum' as platform"
exit 1
fi
# Function to check if server is ready
check_server_health() {
local max_attempts=180 # 30 minutes timeout
local attempt=1
echo "Checking server health..."
while [ $attempt -le $max_attempts ]; do
if curl -s http://${host}:${port}/v1/models > /dev/null 2>&1; then
echo "Server is ready!"
return 0
fi
echo "Attempt $attempt/$max_attempts: Server not ready yet, waiting..."
sleep 10
((attempt++))
done
echo "Server failed to start within timeout"
return 1
}
# Function to cleanup server
cleanup_server() {
echo "Shutting down server..."
if [ ! -z "$SERVER_PID" ]; then
kill $SERVER_PID
fi
# Also kill any remaining vllm processes
pkill -f "vllm serve"
echo "Waiting for server to shutdown..."
if [ ! -z "$SERVER_PID" ]; then
wait $SERVER_PID
fi
sleep 10
echo "Server shutdown completed"
}
output_dir="results/greedy_sample/${MODEL_NAME}/${PLATFORM}-tp_${TP_SIZE}-mb_${MAX_NUM_SEQS}-seq_len_${MAX_SEQ_LEN}-block_${BLOCK_SIZE}-io_len_${LENGTH}"
mkdir -p ${output_dir}
if [ "$PLATFORM" == "optimum" ]; then
if [ $MAX_SEQ_LEN -eq $BLOCK_SIZE ]; then
attn_impl="eager"
else
attn_impl="flash_attn"
fi
USE_VLLM_MODEL=0
OPTIMUM_RBLN_MODEL_PATH="model_optimum-${MODEL_NAME}-tp_${TP_SIZE}-mb_${MAX_NUM_SEQS}-attn_${attn_impl}-seq_len_${MAX_SEQ_LEN}-block_${BLOCK_SIZE}"
echo "Compiling optimum model ${MODEL_ID} with the following arguments: ${OPTIMUM_RBLN_MODEL_PATH}"
python3 compile_optimum_rbln.py \
$MODEL_ID \
--output-dir $OPTIMUM_RBLN_MODEL_PATH \
--max-num-seqs ${MAX_NUM_SEQS} \
--max-model-len ${MAX_SEQ_LEN} \
--block-size ${BLOCK_SIZE} \
--enable-chunked-prefill \
--max-num-batched-tokens ${CHUNK_SIZE} \
--tensor-parallel-size ${TP_SIZE} \
--attn-impl ${attn_impl} >& ${output_dir}/compile_optimum_rbln.log
echo "Compiled model saved to ${OPTIMUM_RBLN_MODEL_PATH}"
MODEL_PATH=$OPTIMUM_RBLN_MODEL_PATH
else
USE_VLLM_MODEL=1
MODEL_PATH=$MODEL_ID
fi
echo "Starting server with max_num_sequences: ${MAX_NUM_SEQS} "
RBLN_KERNEL_MODE=triton VLLM_RBLN_SAMPLER=0 VLLM_RBLN_TP_SIZE=${TP_SIZE} VLLM_RBLN_USE_VLLM_MODEL=${USE_VLLM_MODEL} VLLM_DISABLE_COMPILE_CACHE=1 VLLM_USE_V1=1 \
vllm serve $MODEL_PATH \
--tokenizer $MODEL_ID \
--host ${host} \
--port ${port} \
--max-num-seqs ${MAX_NUM_SEQS} \
--max-model-len ${MAX_SEQ_LEN} \
--block-size ${BLOCK_SIZE} \
--enable-chunked-prefill \
--max-num-batched-tokens ${CHUNK_SIZE} \
>& ${output_dir}/vllm_server.log &
SERVER_PID=$!
echo "Server started with PID: $SERVER_PID"
# Wait for server to be ready
if ! check_server_health; then
echo "Failed to start server, skipping this configuration"
cleanup_server
continue
fi
echo "Starting benchmark with duration: ${DURATION} seconds"
guidellm benchmark \
--request-type text_completions \
--profile concurrent --rate ${MAX_NUM_SEQS} \
--backend-args "{\"timeout\": ${DURATION}}" \
--request-formatter-kwargs '{"extras":{"body":{"temperature":0.0}}}' \
--data "prompt_tokens=${LENGTH},output_tokens=${LENGTH},prompt_tokens_min=${LENGTH},prompt_tokens_max=${LENGTH},output_tokens_min=${LENGTH},output_tokens_max=${LENGTH}" \
--model $MODEL_PATH \
--target http://${host}:${port} \
--max-seconds ${DURATION} \
--warmup 1 --cooldown 1 \
--output-dir ${output_dir} \
>& ${output_dir}/guidellm_benchmark.log
if [ "$PLATFORM" == "optimum" ]; then
rm -rf $OPTIMUM_RBLN_MODEL_PATH
echo "Removed optimum model ${OPTIMUM_RBLN_MODEL_PATH}"
fi
cleanup_server
SERVER_PID=""
echo "Waiting a bit before next configuration..."