- New experiments/dsv4_h200_sglang_vs_vllm/ with TP=8 on all 8 H200 cards - Phase1 short-context throughput + Phase2 long context up to 200k - Unified scenario matrix, warmup, parsing, and side-by-side comparison report - H200 SGLang vs vLLM entry added to root README
267 lines
7.4 KiB
Bash
Executable File
267 lines
7.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# SGLang vs vLLM controlled comparison on H200.
|
|
set -Eeuo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
EXPERIMENT_NAME="$(basename "$SCRIPT_DIR")"
|
|
|
|
# shellcheck source=/dev/null
|
|
source "${SCRIPT_DIR}/../../scripts/common/lib.sh"
|
|
# shellcheck source=/dev/null
|
|
source "${SCRIPT_DIR}/../../scripts/common/platform.sh"
|
|
# shellcheck source=/dev/null
|
|
source "${SCRIPT_DIR}/config.env"
|
|
|
|
RUN_ID="${RUN_ID:-$(date '+%Y%m%d-%H%M%S')}"
|
|
RESULT_BASE="${SCRIPT_DIR}/results"
|
|
|
|
log_dir_global="${RESULT_BASE}/${RUN_ID}/logs"
|
|
mkdir -p "$log_dir_global"
|
|
log_init "${log_dir_global}/orchestrator.log"
|
|
|
|
log "experiment=${EXPERIMENT_NAME}"
|
|
log "run_id=${RUN_ID}"
|
|
log "platform=${PLATFORM}"
|
|
log "hardware=${HARDWARE}"
|
|
log "model=${MODEL_PATH}"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Helpers
|
|
# ---------------------------------------------------------------------------
|
|
|
|
is_server_healthy() {
|
|
local port="$1"
|
|
curl --fail --silent --show-error --max-time 5 "http://127.0.0.1:${port}/health" >/dev/null 2>&1
|
|
}
|
|
|
|
stop_server() {
|
|
local backend="$1"
|
|
local pid_file="/data/user1/yy/dsv4_h200_sglang_vs_vllm_${backend}.pid"
|
|
if [[ -f "$pid_file" ]]; then
|
|
local pid
|
|
pid="$(cat "$pid_file")"
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
log "stopping ${backend} server pid=${pid}"
|
|
kill "$pid" 2>/dev/null || true
|
|
sleep 5
|
|
kill -9 "$pid" 2>/dev/null || true
|
|
fi
|
|
rm -f "$pid_file"
|
|
fi
|
|
# Fallback cleanup.
|
|
if [[ "$backend" == "sglang" ]]; then
|
|
pkill -9 -f "sglang serve.*DeepSeek-V4-Flash" 2>/dev/null || true
|
|
else
|
|
pkill -9 -f "vllm serve.*DeepSeek-V4-Flash" 2>/dev/null || true
|
|
fi
|
|
sleep 2
|
|
}
|
|
|
|
start_server() {
|
|
local backend="$1"
|
|
local phase="$2"
|
|
local start_script
|
|
if [[ "$backend" == "sglang" ]]; then
|
|
start_script="${SGLANG_START_SCRIPT}"
|
|
local port="$SGLANG_PORT"
|
|
else
|
|
start_script="${VLLM_START_SCRIPT}"
|
|
local port="$VLLM_PORT"
|
|
fi
|
|
|
|
log "starting ${backend} server (phase=${phase}) with ${start_script}"
|
|
bash "${start_script}" "$phase" >> "${log_dir_global}/${backend}_${phase}.server.outer.log" 2>&1
|
|
|
|
if ! is_server_healthy "$port"; then
|
|
log "error: ${backend} server (phase=${phase}) failed to become healthy"
|
|
return 1
|
|
fi
|
|
log "${backend} server is healthy on port ${port}"
|
|
}
|
|
|
|
run_warmup() {
|
|
local backend="$1"
|
|
local phase="$2"
|
|
local port input_len output_len num
|
|
if [[ "$backend" == "sglang" ]]; then
|
|
port="$SGLANG_PORT"
|
|
else
|
|
port="$VLLM_PORT"
|
|
fi
|
|
|
|
if [[ "$phase" == "phase1" ]]; then
|
|
input_len=4000
|
|
output_len=512
|
|
num=2
|
|
else
|
|
input_len=200000
|
|
output_len=1024
|
|
num=1
|
|
fi
|
|
|
|
log "warming up ${backend} (phase=${phase}, input=${input_len}, output=${output_len}, num=${num})"
|
|
"${VENV_CLIENT}/bin/python" "${SCRIPT_DIR}/warmup.py" \
|
|
--backend "$backend" \
|
|
--port "$port" \
|
|
--input-len "$input_len" \
|
|
--output-len "$output_len" \
|
|
--num "$num" \
|
|
--env-python "${VENV_CLIENT}/bin/python" \
|
|
>> "${log_dir_global}/${backend}_${phase}.warmup.log" 2>&1
|
|
log "warmup for ${backend} ${phase} completed"
|
|
}
|
|
|
|
run_phase() {
|
|
local backend="$1"
|
|
local phase="$2"
|
|
local result_root="${RESULT_BASE}/${RUN_ID}/${backend}"
|
|
local raw_dir="${result_root}/raw_outputs"
|
|
local phase_log_dir="${result_root}/logs"
|
|
|
|
mkdir -p "$raw_dir" "$phase_log_dir"
|
|
|
|
local -n scenarios
|
|
local max_model_len
|
|
if [[ "$phase" == "phase1" ]]; then
|
|
scenarios=PHASE1_SCENARIOS
|
|
max_model_len="$PHASE1_MAX_MODEL_LEN"
|
|
else
|
|
scenarios=PHASE2_SCENARIOS
|
|
max_model_len="$PHASE2_MAX_MODEL_LEN"
|
|
fi
|
|
|
|
local port
|
|
if [[ "$backend" == "sglang" ]]; then
|
|
port="$SGLANG_PORT"
|
|
else
|
|
port="$VLLM_PORT"
|
|
fi
|
|
|
|
log "===== ${backend} ${phase} START (max_model_len=${max_model_len}) ====="
|
|
|
|
stop_server "$backend"
|
|
start_server "$backend" "$phase"
|
|
run_warmup "$backend" "$phase"
|
|
|
|
for scenario in "${scenarios[@]}"; do
|
|
read -r concurrency input_len output_len num_prompts <<< "$scenario"
|
|
output_file="${raw_dir}/${backend}_${phase}_$(date '+%m%d')_${concurrency}_${input_len}_${output_len}.jsonl"
|
|
detail_log="${phase_log_dir}/${backend}_${phase}_c${concurrency}_i${input_len}_o${output_len}.log"
|
|
|
|
log "running ${backend} ${phase} scenario: c=${concurrency} i=${input_len} o=${output_len} n=${num_prompts}"
|
|
|
|
"${VENV_CLIENT}/bin/python" -m sglang.bench_serving \
|
|
--backend "$backend" \
|
|
--host 127.0.0.1 \
|
|
--port "$port" \
|
|
--dataset-name random \
|
|
--random-input-len "$input_len" \
|
|
--random-output-len "$output_len" \
|
|
--num-prompts "$num_prompts" \
|
|
--max-concurrency "$concurrency" \
|
|
--request-rate 10000 \
|
|
--output-file "$output_file" \
|
|
--output-details \
|
|
> "$detail_log" 2>&1 || {
|
|
log "ERROR: ${backend} ${phase} scenario c=${concurrency} i=${input_len} o=${output_len} failed; see ${detail_log}"
|
|
continue
|
|
}
|
|
|
|
log "finished ${backend} ${phase} scenario: output=${output_file}"
|
|
done
|
|
|
|
stop_server "$backend"
|
|
log "===== ${backend} ${phase} DONE ====="
|
|
}
|
|
|
|
parse_backend() {
|
|
local backend="$1"
|
|
local result_root="${RESULT_BASE}/${RUN_ID}/${backend}"
|
|
log "parsing ${backend} results in ${result_root}"
|
|
"${VENV_CLIENT}/bin/python" "${SCRIPT_DIR}/parse_backend.py" "$result_root" --backend "$backend" \
|
|
>> "${result_root}/logs/parse.log" 2>&1 || {
|
|
log "WARNING: parser failed for ${backend}; see ${result_root}/logs/parse.log"
|
|
}
|
|
}
|
|
|
|
write_backend_metadata() {
|
|
local backend="$1"
|
|
local result_root="${RESULT_BASE}/${RUN_ID}/${backend}"
|
|
ensure_result_root "$result_root"
|
|
local meta_json="${result_root}/results.json"
|
|
|
|
local env_path
|
|
if [[ "$backend" == "sglang" ]]; then
|
|
env_path="$VENV_SGLANG"
|
|
else
|
|
env_path="$VENV_VLLM"
|
|
fi
|
|
|
|
write_metadata_json \
|
|
"$meta_json" \
|
|
"${EXPERIMENT_NAME}_${backend}" \
|
|
"$RUN_ID" \
|
|
"$MODEL_PATH" \
|
|
"$backend" \
|
|
"$backend" \
|
|
"$HARDWARE" \
|
|
"$ACCELERATOR" \
|
|
"$CHIP" \
|
|
"experiments/${EXPERIMENT_NAME}/run_bench.sh" \
|
|
"$env_path" \
|
|
"H200 ${backend} TP=8 comparison benchmark for DeepSeek-V4-Flash"
|
|
|
|
# Embed config.
|
|
"${VENV_CLIENT}/bin/python" - "$meta_json" "$backend" <<'PY'
|
|
import json
|
|
import sys
|
|
|
|
path, backend = sys.argv[1], sys.argv[2]
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
|
|
data["config"] = {
|
|
"tp": 8,
|
|
"cuda_visible_devices": "0,1,2,3,4,5,6,7",
|
|
"phase1_max_model_len": 32768,
|
|
"phase2_max_model_len": 210000,
|
|
"backend": backend,
|
|
}
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
json.dump(data, f, indent=2, ensure_ascii=False)
|
|
PY
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Main
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Cleanup any leftovers.
|
|
stop_server sglang
|
|
stop_server vllm
|
|
|
|
write_backend_metadata sglang
|
|
write_backend_metadata vllm
|
|
|
|
# Run SGLang.
|
|
run_phase sglang phase1
|
|
run_phase sglang phase2
|
|
parse_backend sglang
|
|
|
|
# Run vLLM.
|
|
run_phase vllm phase1
|
|
run_phase vllm phase2
|
|
parse_backend vllm
|
|
|
|
# Generate comparison.
|
|
log "generating comparison report"
|
|
"${VENV_CLIENT}/bin/python" "${SCRIPT_DIR}/compare.py" \
|
|
--sglang "${RESULT_BASE}/${RUN_ID}/sglang" \
|
|
--vllm "${RESULT_BASE}/${RUN_ID}/vllm" \
|
|
--output "${RESULT_BASE}/${RUN_ID}/comparison.md" \
|
|
>> "${log_dir_global}/compare.log" 2>&1 || {
|
|
log "WARNING: comparison script failed; see ${log_dir_global}/compare.log"
|
|
}
|
|
|
|
log "all results saved to ${RESULT_BASE}/${RUN_ID}"
|