@@ -34,8 +34,62 @@ HOST=${HOST:-localhost}
3434PORT=${PORT:- 8000}
3535NUM_PROMPTS=${NUM_PROMPTS:- 100}
3636
37- # Run the vLLM profiling command
38- echo " Starting vLLM bench serve profiling..."
37+ # Helper functions
38+ wait_for_server () {
39+ # Wait for vLLM server to start
40+ # Return 1 if vLLM server crashes
41+ timeout 1200 bash -c "
42+ until curl -s ${HOST} :${PORT} /v1/models > /dev/null; do
43+ sleep 1
44+ done" && return 0 || return 1
45+ }
46+
47+ kill_gpu_processes () {
48+ echo " Cleaning up processes..."
49+ lsof -t -i:${PORT} | xargs -r kill -9 2> /dev/null || true
50+ pgrep -f " vllm serve" | xargs -r kill -9 2> /dev/null || true
51+ pgrep python3 | xargs -r kill -9 2> /dev/null || true
52+ pgrep python | xargs -r kill -9 2> /dev/null || true
53+
54+ # Wait until GPU memory usage decreases
55+ if command -v nvidia-smi; then
56+ echo " Waiting for GPU memory to clear..."
57+ while [ " $( nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits | head -n 1) " -ge 1000 ]; do
58+ sleep 1
59+ done
60+ fi
61+ }
62+
63+ # Clean up any existing processes first
64+ kill_gpu_processes
65+
66+ # Start vLLM server in the background
67+ echo " Starting vLLM server..."
68+ echo " Server command: VLLM_USE_V1=${VLLM_USE_V1} vllm serve ${MODEL_NAME} --swap-space 16 --disable-log-requests --host :: --port ${PORT} --dtype float16"
69+
70+ VLLM_USE_V1=${VLLM_USE_V1} vllm serve " ${MODEL_NAME} " \
71+ --swap-space 16 \
72+ --disable-log-requests \
73+ --host :: \
74+ --port " ${PORT} " \
75+ --dtype float16 &
76+
77+ server_pid=$!
78+ echo " vLLM server started with PID: ${server_pid} "
79+
80+ # Wait for server to be ready
81+ echo " Waiting for vLLM server to be ready..."
82+ if wait_for_server; then
83+ echo " vLLM server is up and running!"
84+ else
85+ echo " vLLM server failed to start within the timeout period."
86+ kill -9 $server_pid 2> /dev/null || true
87+ exit 1
88+ fi
89+
90+ # Run the load generation/profiling command
91+ echo " Starting load generation for profiling..."
92+ echo " Load gen command: vllm bench serve --dataset-name ${DATASET_NAME} --model ${SERVED_MODEL_NAME} --random-input-len ${RANDOM_INPUT_LEN} --random-output-len ${RANDOM_OUTPUT_LEN} --endpoint ${ENDPOINT} --ignore-eos --host ${HOST} --port ${PORT} --num-prompts ${NUM_PROMPTS} "
3993
4094vllm bench serve \
4195 --dataset-name " ${DATASET_NAME} " \
@@ -50,7 +104,10 @@ vllm bench serve \
50104 --num-prompts " ${NUM_PROMPTS} " \
51105 --profile
52106
53- echo " vLLM profiling completed successfully!"
107+ # Clean up the server
108+ echo " Stopping vLLM server..."
109+ kill -9 $server_pid 2> /dev/null || true
110+ kill_gpu_processes
54111
55112# Copy any generated profiling results to the profiling-results directory
56113if [ -d " ${VLLM_TORCH_PROFILER_DIR:- } " ]; then
0 commit comments