Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4964a59
Added sglang workflow files
namanlalitnyu Aug 20, 2025
e6a91f9
fixing the source code location
namanlalitnyu Aug 20, 2025
843e7cc
fix source code location
namanlalitnyu Aug 20, 2025
8d4eac4
add missing json files
namanlalitnyu Aug 20, 2025
2230a99
update params
namanlalitnyu Aug 20, 2025
66d328f
only run on h100 for now
namanlalitnyu Aug 20, 2025
5938df2
fix serving model engine to sglang
namanlalitnyu Aug 21, 2025
56558ec
sanitized results section
namanlalitnyu Aug 21, 2025
0e0998a
fix sglang issues
namanlalitnyu Aug 21, 2025
5a18dc5
remove unused files for now
namanlalitnyu Aug 21, 2025
4b03ad0
updated workflow execution
namanlalitnyu Aug 22, 2025
de0d0f8
remove comment
namanlalitnyu Aug 22, 2025
2b4325a
trying a different method
namanlalitnyu Aug 22, 2025
5ca157c
fix numa installation issue
namanlalitnyu Aug 22, 2025
e40a38e
fix issues
namanlalitnyu Aug 22, 2025
7b763ac
fix package
namanlalitnyu Aug 22, 2025
79d4ccf
fix package
namanlalitnyu Aug 22, 2025
cd64568
fix package
namanlalitnyu Aug 22, 2025
aeecd6a
fix package
namanlalitnyu Aug 22, 2025
d121b34
fix package
namanlalitnyu Aug 22, 2025
2498860
fix package
namanlalitnyu Aug 22, 2025
b3800a2
fix package
namanlalitnyu Aug 22, 2025
564c0b5
fix process
namanlalitnyu Aug 22, 2025
2e0eb3d
replace sglang benchmarking command with vllm bench serve
namanlalitnyu Aug 22, 2025
1dd83dc
fix import
namanlalitnyu Aug 22, 2025
5aa0db1
running vllm through docker
namanlalitnyu Aug 25, 2025
403e20d
add docker image
namanlalitnyu Aug 25, 2025
f01f72f
test sglang docker image
namanlalitnyu Aug 25, 2025
0d0379c
test different approach - 1
namanlalitnyu Aug 25, 2025
3b99ff4
remove uv and use pip
namanlalitnyu Aug 25, 2025
8fc7488
try different approach
namanlalitnyu Aug 25, 2025
14d33f9
remove uv and use pip
namanlalitnyu Aug 25, 2025
017e252
remove uv and use pip
namanlalitnyu Aug 25, 2025
cac7fc1
create diff venvs
namanlalitnyu Aug 25, 2025
90f0493
update arguments
namanlalitnyu Aug 25, 2025
5160576
added max concurrency
namanlalitnyu Aug 25, 2025
110929b
add virtual env for sglang as well
namanlalitnyu Aug 25, 2025
33f9cbd
test
namanlalitnyu Aug 25, 2025
1bb0f34
trying with env variables
namanlalitnyu Aug 25, 2025
fc897ad
final touches
namanlalitnyu Aug 25, 2025
747817d
fix extra character
namanlalitnyu Aug 25, 2025
0fc1017
cleanup and adding more tests
namanlalitnyu Aug 25, 2025
545c19b
removing not needed files and tests
namanlalitnyu Aug 25, 2025
5b3f9f9
try running inside docker container
namanlalitnyu Aug 26, 2025
f8bd1c8
try sglang docker image
namanlalitnyu Aug 26, 2025
c3d6657
try with gpu cleaning
namanlalitnyu Aug 26, 2025
f877d7b
remove cuda check
namanlalitnyu Aug 26, 2025
f8912f4
try using vllm docker image
namanlalitnyu Aug 26, 2025
936bd02
check valid docker image
namanlalitnyu Aug 26, 2025
53d83bb
removing not needed tests and back to original implementation
namanlalitnyu Aug 26, 2025
9edcfaa
try after removing extra env variables
namanlalitnyu Aug 26, 2025
ca9c3d8
adding dynamo variable
namanlalitnyu Aug 26, 2025
a414e4b
run sglang in a diff venv
namanlalitnyu Aug 26, 2025
0b7f1cf
debug issue
namanlalitnyu Aug 26, 2025
81503c4
revert the changes
namanlalitnyu Aug 26, 2025
c1c13ba
address review comments
namanlalitnyu Aug 27, 2025
e2e6af0
add a todo for env variable
namanlalitnyu Aug 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
331 changes: 331 additions & 0 deletions .github/scripts/run-sglang-performance-benchmarks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
#!/bin/bash

# This script should be run inside the CI process
# This script assumes that we are already inside the sglang-benchmarks/benchmarks/ directory
# Benchmarking results will be available inside sglang-benchmarks/benchmarks/results/

# Do not set -e, as some models may crash occasionally
# and we still want to see other benchmarking results even when some models crash.
set -x
set -o pipefail

# The helper functions and their implementations are referred from the implementation
# of the run-performance-benchmarks.sh script in the official vllm repo
# Path:- .buildkite/nightly-benchmarks/scripts/run-performance-benchmarks.sh
check_gpus() {
if command -v nvidia-smi; then
# check the number of GPUs and GPU type.
declare -g gpu_count=$(nvidia-smi --list-gpus | wc -l)
elif command -v amd-smi; then
declare -g gpu_count=$(amd-smi list | grep 'GPU' | wc -l)
fi

if [[ $gpu_count -gt 0 ]]; then
echo "GPU found."
else
echo "Need at least 1 GPU to run benchmarking."
exit 1
fi
if command -v nvidia-smi; then
declare -g gpu_type=$(nvidia-smi --query-gpu=name --format=csv,noheader | awk '{print $2}')
elif command -v amd-smi; then
declare -g gpu_type=$(amd-smi static -g 0 -a | grep 'MARKET_NAME' | awk '{print $2}')
fi
echo "GPU type is $gpu_type"
}

check_cpus() {
# check the number of CPUs and NUMA Node and GPU type.
declare -g numa_count=$(lscpu | grep "NUMA node(s):" | awk '{print $3}')
if [[ $numa_count -gt 0 ]]; then
echo "NUMA found."
echo $numa_count
else
echo "Need at least 1 NUMA to run benchmarking."
exit 1
fi
declare -g gpu_type="cpu"
echo "GPU type is $gpu_type"
}

check_hf_token() {
# check if HF_TOKEN is available and valid
if [[ -z "$HF_TOKEN" ]]; then
echo "Error: HF_TOKEN is not set."
exit 1
elif [[ ! "$HF_TOKEN" =~ ^hf_ ]]; then
echo "Error: HF_TOKEN does not start with 'hf_'."
exit 1
else
echo "HF_TOKEN is set and valid."
fi
}

ensure_sharegpt_downloaded() {
local FILE=ShareGPT_V3_unfiltered_cleaned_split.json
if [ ! -f "$FILE" ]; then
wget https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered/resolve/main/$FILE
else
echo "$FILE already exists."
fi
}

json2args() {
# transforms the JSON string to command line args, and '_' is replaced to '-'
# example:
# input: { "model": "meta-llama/Llama-2-7b-chat-hf", "tensor_parallel_size": 1 }
# output: --model meta-llama/Llama-2-7b-chat-hf --tensor-parallel-size 1
local json_string=$1
local args=$(
echo "$json_string" | jq -r '
to_entries |
map("--" + (.key | gsub("_"; "-")) + " " + (.value | tostring)) |
join(" ")
'
)
echo "$args"
}

json2envs() {
# transforms the JSON string to environment variables.
# example:
# input: { "SGLANG_DISABLE_CUDA_GRAPH": 1 }
# output: SGLANG_DISABLE_CUDA_GRAPH=1
local json_string=$1
local args=$(
echo "$json_string" | jq -r '
to_entries |
map((.key ) + "=" + (.value | tostring)) |
join(" ")
'
)
echo "$args"
}

wait_for_server() {
# wait for sglang server to start
# return 1 if sglang server crashes
timeout 1200 bash -c '
until curl -s localhost:30000/v1/completions > /dev/null; do
sleep 1
done' && return 0 || return 1
}

kill_processes_launched_by_current_bash() {
# Kill all python processes launched from current bash script
current_shell_pid=$$
processes=$(ps -eo pid,ppid,command | awk -v ppid="$current_shell_pid" -v proc="$1" '$2 == ppid && $3 ~ proc {print $1}')
if [ -n "$processes" ]; then
echo "Killing the following processes matching '$1':"
echo "$processes"
echo "$processes" | xargs kill -9
else
echo "No processes found matching '$1'."
fi
}

kill_gpu_processes() {
ps -aux
lsof -t -i:30000 | xargs -r kill -9
pgrep python3 | xargs -r kill -9
pgrep python | xargs -r kill -9
pgrep VLLM | xargs -r kill -9

# wait until GPU memory usage smaller than 1GB
if command -v nvidia-smi; then
while [ "$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits | head -n 1)" -ge 1000 ]; do
sleep 1
done
elif command -v amd-smi; then
while [ "$(amd-smi metric -g 0 | grep 'USED_VRAM' | awk '{print $2}')" -ge 1000 ]; do
sleep 1
done
fi
}

run_serving_tests() {
# run serving tests using `sglang.bench_serving` command
# $1: a json file specifying serving test cases

local serving_test_file
serving_test_file=$1

# Iterate over serving tests
jq -c '.[]' "$serving_test_file" | while read -r params; do
# get the test name, and append the GPU type back to it.
test_name=$(echo "$params" | jq -r '.test_name')
if [[ ! "$test_name" =~ ^serving_ ]]; then
echo "In serving-test.json, test_name must start with \"serving_\"."
exit 1
fi

# if TEST_SELECTOR is set, only run the test cases that match the selector
if [[ -n "$TEST_SELECTOR" ]] && [[ ! "$test_name" =~ $TEST_SELECTOR ]]; then
echo "Skip test case $test_name."
continue
fi

# get client and server arguments
server_params=$(echo "$params" | jq -r '.server_parameters')
server_envs=$(echo "$params" | jq -r '.server_environment_variables')
client_params=$(echo "$params" | jq -r '.client_parameters')
server_args=$(json2args "$server_params")
server_envs=$(json2envs "$server_envs")
client_args=$(json2args "$client_params")
qps_list=$(echo "$params" | jq -r '.qps_list')
qps_list=$(echo "$qps_list" | jq -r '.[] | @sh')
echo "Running over qps list $qps_list"

# Extract only specific SGLang server parameters
model_path=$(echo "$server_params" | jq -r '.model_path // .model')
context_length=$(echo "$server_params" | jq -r '.context_length // 4096')

# check if there is enough resources to run the test
tp=$(echo "$server_params" | jq -r '.tp // 1')
if [ "$ON_CPU" == "1" ]; then
if [[ $numa_count -lt $tp ]]; then
echo "Required tensor-parallel-size $tp but only $numa_count NUMA nodes found. Skip testcase $test_name."
continue
fi
else
if [[ $gpu_count -lt $tp ]]; then
echo "Required tensor-parallel-size $tp but only $gpu_count GPU found. Skip testcase $test_name."
continue
fi
fi

# check if server model and client model is aligned
server_model="$model_path"
client_model=$(echo "$client_params" | jq -r '.model // .model_path')
if [[ $server_model != "$client_model" ]]; then
echo "Server model and client model must be the same. Skip testcase $test_name."
continue
fi

server_command="python3 -m sglang.launch_server --model-path $model_path --context-length $context_length --tp $tp"

# run the server
echo "Running test case $test_name"
echo "Server command: $server_command"
bash -c "$server_command" &
server_pid=$!

# wait until the server is alive
if wait_for_server; then
echo ""
echo "SGLang server is up and running."
else
echo ""
echo "SGLang failed to start within the timeout period."
kill -9 $server_pid
continue
fi

# Create a new uv environment for vllm client (once per test case)
echo "Creating new uv environment for vllm client..."
uv venv vllm_client_env

# Activate the environment and install vllm
echo "Installing vllm in the new environment..."
source vllm_client_env/bin/activate
pip install vllm

# iterate over different QPS
for qps in $qps_list; do
# remove the surrounding single quote from qps
if [[ "$qps" == *"inf"* ]]; then
echo "qps was $qps"
qps="inf"
echo "now qps is $qps"
fi

new_test_name=$test_name"_qps_"$qps
echo " new test name $new_test_name"

# pass the tensor parallel size to the client so that it can be displayed
# on the benchmark dashboard
client_command="vllm bench serve \
--save-result \
--result-dir $RESULTS_FOLDER \
--result-filename ${new_test_name}.json \
--request-rate $qps \
--metadata "tensor_parallel_size=$tp" \
--port 30000 \
$client_args "

echo "Running test case $test_name with qps $qps"
echo "Client command: $client_command"

bash -c "$client_command"

# record the benchmarking commands
jq_output=$(jq -n \
--arg server "$server_command" \
--arg client "$client_command" \
--arg gpu "$gpu_type" \
'{
server_command: $server,
client_command: $client,
gpu_type: $gpu
}')
echo "$jq_output" >"$RESULTS_FOLDER/${new_test_name}.commands"
done

# Deactivate and clean up the environment after all QPS tests
deactivate
rm -rf vllm_client_env

# clean up
kill -9 $server_pid
kill_gpu_processes
done
}

main() {
check_gpus
check_hf_token

# dependencies
(which wget && which curl) || (apt-get update && apt-get install -y wget curl)
(which jq) || (apt-get update && apt-get -y install jq)
(which lsof) || (apt-get update && apt-get install -y lsof)

# get the current IP address, required by SGLang bench commands
export SGLANG_HOST_IP=$(hostname -I | awk '{print $1}')
# turn off the reporting of the status of each request, to clean up the terminal output
export SGLANG_LOGGING_LEVEL="WARNING"

# prepare for benchmarking
ensure_sharegpt_downloaded
declare -g RESULTS_FOLDER=results/
mkdir -p $RESULTS_FOLDER
BENCHMARK_ROOT=tests/

# benchmarking - look for test files in the tests/ directory
if [ -f "$BENCHMARK_ROOT/serving-tests.json" ]; then
run_serving_tests "$BENCHMARK_ROOT/serving-tests.json"
else
echo "No serving test file found"
fi

# postprocess benchmarking results
pip install tabulate pandas

# Create a simple markdown summary of results
echo "# SGLang Benchmark Results" > "$RESULTS_FOLDER/benchmark_results.md"
echo "" >> "$RESULTS_FOLDER/benchmark_results.md"
echo "## Test Results Summary" >> "$RESULTS_FOLDER/benchmark_results.md"
echo "" >> "$RESULTS_FOLDER/benchmark_results.md"

# List all JSON result files
if ls "$RESULTS_FOLDER"/*.json 1> /dev/null 2>&1; then
echo "### Generated Result Files:" >> "$RESULTS_FOLDER/benchmark_results.md"
for file in "$RESULTS_FOLDER"/*.json; do
echo "- $(basename "$file")" >> "$RESULTS_FOLDER/benchmark_results.md"
done
else
echo "No JSON result files were generated." >> "$RESULTS_FOLDER/benchmark_results.md"
fi
}

main "$@"
Loading
Loading