Create transformers-backend-vllm-benchmark.sh
Browse files
transformers-backend-vllm-benchmark.sh
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# =============================================================================
|
| 3 |
+
# Reproduce the benchmark behind vLLM PR #47187
|
| 4 |
+
# "Make the Transformers modeling backend as fast as native vLLM"
|
| 5 |
+
# =============================================================================
|
| 6 |
+
#
|
| 7 |
+
# What this measures
|
| 8 |
+
# ------------------
|
| 9 |
+
# For each model we compare THREE conditions on identical hardware, workload
|
| 10 |
+
# and flags — the only thing that changes is the code path:
|
| 11 |
+
#
|
| 12 |
+
# native --model-impl vllm vLLM's hand-written model (the bar to match)
|
| 13 |
+
# after --model-impl transformers generic Transformers backend, WITH PR #47187
|
| 14 |
+
# before --model-impl transformers generic Transformers backend, WITHOUT PR #47187
|
| 15 |
+
#
|
| 16 |
+
# PR #47187 is 100% Python and lives entirely under
|
| 17 |
+
# vllm/model_executor/models/transformers/ — no CUDA/C++/build changes. So the
|
| 18 |
+
# honest before/after delta is obtained by `git checkout`-ing just those files
|
| 19 |
+
# to the PR's parent commit and back. No recompile, nothing else moves.
|
| 20 |
+
#
|
| 21 |
+
# Every number the graphic reports is a WITHIN-model, WITHIN-harness ratio
|
| 22 |
+
# (% of native, and after/before), so the comparison is apples-to-apples even
|
| 23 |
+
# though absolute tok/s differ across model sizes and harnesses.
|
| 24 |
+
#
|
| 25 |
+
# Hardware used for the published figures: 8x NVIDIA H100 80GB.
|
| 26 |
+
#
|
| 27 |
+
# Usage
|
| 28 |
+
# -----
|
| 29 |
+
# ./benchmark.sh # run every condition for every model
|
| 30 |
+
# ./benchmark.sh q3_235b # run only conditions whose tag matches this
|
| 31 |
+
# Results (JSON + logs) land in ./results/. Re-running skips completed configs.
|
| 32 |
+
# =============================================================================
|
| 33 |
+
set -uo pipefail
|
| 34 |
+
|
| 35 |
+
# --- configure these two paths for your machine ------------------------------
|
| 36 |
+
VLLM=${VLLM:-/fsx/harry/vllm} # editable vLLM checkout on PR #47187
|
| 37 |
+
VENV=${VENV:-/fsx/harry/.venv/bin} # venv with that vLLM installed
|
| 38 |
+
# -----------------------------------------------------------------------------
|
| 39 |
+
PR=5bce653e09 # PR #47187 merge commit
|
| 40 |
+
PARENT="${PR}^" # its parent = "before"
|
| 41 |
+
TFDIR=vllm/model_executor/models/transformers/
|
| 42 |
+
OUT="$(cd "$(dirname "$0")" && pwd)/results"
|
| 43 |
+
PORT=8231
|
| 44 |
+
FILTER="${1:-}" # optional tag substring filter
|
| 45 |
+
mkdir -p "$OUT"
|
| 46 |
+
|
| 47 |
+
# Shared workload for every run: 1024-token prompts, 128-token generations.
|
| 48 |
+
INLEN=1024; OUTLEN=128; NPROMPTS=1000
|
| 49 |
+
|
| 50 |
+
# Model matrix that produced the graphic.
|
| 51 |
+
# tag | model | harness | tp | gpus | extra-flags
|
| 52 |
+
# harness = "throughput" (offline) or "serve" (online; required for data parallel).
|
| 53 |
+
MODELS=(
|
| 54 |
+
"q3_4b|Qwen/Qwen3-4B|throughput|1|0|"
|
| 55 |
+
"q3_32b|Qwen/Qwen3-32B|throughput|2|0,1|"
|
| 56 |
+
"q3_235b|Qwen/Qwen3-235B-A22B-FP8|serve|8|0,1,2,3,4,5,6,7|--data-parallel-size 8 --enable-expert-parallel --max-model-len 8192"
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# Always leave the tree back on the PR files, whatever happens.
|
| 60 |
+
restore(){ git -C "$VLLM" checkout "$PR" -- "$TFDIR" 2>/dev/null; }
|
| 61 |
+
trap restore EXIT
|
| 62 |
+
|
| 63 |
+
# Node-local compile caches on tmpfs. On a networked filesystem the multi-rank
|
| 64 |
+
# inductor/triton autotune cache races and throws "CUDA driver error: file not
|
| 65 |
+
# found"; keeping caches on /dev/shm with single-threaded compile avoids it.
|
| 66 |
+
setcache(){
|
| 67 |
+
local tag=$1 c=/dev/shm/benchcache/$1
|
| 68 |
+
rm -rf "$c"; mkdir -p "$c"/{triton,inductor,vllm}
|
| 69 |
+
export TRITON_CACHE_DIR="$c/triton" TORCHINDUCTOR_CACHE_DIR="$c/inductor"
|
| 70 |
+
export VLLM_CACHE_ROOT="$c/vllm" TORCHINDUCTOR_COMPILE_THREADS=1
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
free_gpus(){ # wait until the GPUs are actually released before the next run
|
| 74 |
+
pkill -9 -f "EngineCore" 2>/dev/null; pkill -9 -f "vllm serve" 2>/dev/null
|
| 75 |
+
pkill -9 -f "VLLM::" 2>/dev/null
|
| 76 |
+
for _ in $(seq 1 90); do
|
| 77 |
+
local u; u=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits \
|
| 78 |
+
| awk '{s+=$1} END{print s+0}')
|
| 79 |
+
[ "$u" -lt 3000 ] && break; sleep 2
|
| 80 |
+
done
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
# ---- offline throughput harness (dense models) ------------------------------
|
| 84 |
+
run_throughput(){ # tag model impl tp gpus extra...
|
| 85 |
+
local tag=$1 model=$2 impl=$3 tp=$4 gpus=$5; shift 5
|
| 86 |
+
local json="$OUT/$tag.json" log="$OUT/$tag.log"
|
| 87 |
+
grep -q tokens_per_second "$json" 2>/dev/null && { echo "SKIP $tag (done)"; return; }
|
| 88 |
+
setcache "$tag"
|
| 89 |
+
echo ">>> $tag : throughput impl=$impl tp=$tp gpus=$gpus"
|
| 90 |
+
CUDA_VISIBLE_DEVICES=$gpus VLLM_LOGGING_LEVEL=INFO timeout 5400 \
|
| 91 |
+
"$VENV/vllm" bench throughput \
|
| 92 |
+
--model "$model" --model-impl "$impl" --tensor-parallel-size "$tp" \
|
| 93 |
+
--dataset-name random --input-len $INLEN --output-len $OUTLEN \
|
| 94 |
+
--num-prompts $NPROMPTS --output-json "$json" "$@" > "$log" 2>&1
|
| 95 |
+
echo -n " "; grep -o '"tokens_per_second":[^,]*' "$json" 2>/dev/null || echo "NO RESULT"
|
| 96 |
+
echo " fused-op log lines: $(grep -cE '^Fused:' "$log")"
|
| 97 |
+
free_gpus
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
# ---- online serving harness (data-parallel MoE) -----------------------------
|
| 101 |
+
run_serve(){ # tag model impl tp gpus extra...
|
| 102 |
+
local tag=$1 model=$2 impl=$3 tp=$4 gpus=$5; shift 5
|
| 103 |
+
local json="$OUT/$tag.json" slog="$OUT/${tag}_server.log" clog="$OUT/${tag}_client.log"
|
| 104 |
+
grep -q total_token_throughput "$json" 2>/dev/null && { echo "SKIP $tag (done)"; return; }
|
| 105 |
+
setcache "$tag"; rm -f "$json"
|
| 106 |
+
echo ">>> $tag : serve impl=$impl gpus=$gpus"
|
| 107 |
+
CUDA_VISIBLE_DEVICES=$gpus VLLM_LOGGING_LEVEL=INFO \
|
| 108 |
+
"$VENV/vllm" serve "$model" --model-impl "$impl" --port $PORT "$@" > "$slog" 2>&1 &
|
| 109 |
+
local spid=$! ready=0
|
| 110 |
+
for _ in $(seq 1 400); do
|
| 111 |
+
[ "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:$PORT/health)" = 200 ] \
|
| 112 |
+
&& { ready=1; break; }
|
| 113 |
+
kill -0 $spid 2>/dev/null || { echo " server died (see $slog)"; break; }
|
| 114 |
+
sleep 3
|
| 115 |
+
done
|
| 116 |
+
if [ "$ready" = 1 ]; then
|
| 117 |
+
echo " server ready -> client"
|
| 118 |
+
"$VENV/vllm" bench serve --model "$model" --host 127.0.0.1 --port $PORT \
|
| 119 |
+
--dataset-name random --random-input-len $INLEN --random-output-len $OUTLEN \
|
| 120 |
+
--num-prompts $NPROMPTS --ignore-eos --save-result --result-filename "$json" > "$clog" 2>&1
|
| 121 |
+
echo -n " "; grep -oE '"total_token_throughput":[^,}]*' "$json" 2>/dev/null || echo "NO RESULT"
|
| 122 |
+
echo " fused-op log lines: $(grep -cE '^Fused:' "$slog")"
|
| 123 |
+
fi
|
| 124 |
+
kill -9 $spid 2>/dev/null; free_gpus
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
dispatch(){ # spec impl condtag
|
| 128 |
+
IFS='|' read -r tag model harness tp gpus extra <<< "$1"
|
| 129 |
+
[ -n "$FILTER" ] && [[ "$tag" != *"$FILTER"* ]] && return
|
| 130 |
+
# shellcheck disable=SC2086
|
| 131 |
+
run_"$harness" "${tag}_$3" "$model" "$2" "$tp" "$gpus" $extra
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
# === Phase A: native + after — run on the PR files ===========================
|
| 135 |
+
echo "######## PHASE A: native + after (PR #47187 files) ########"
|
| 136 |
+
git -C "$VLLM" checkout "$PR" -- "$TFDIR"
|
| 137 |
+
for spec in "${MODELS[@]}"; do
|
| 138 |
+
dispatch "$spec" vllm native
|
| 139 |
+
dispatch "$spec" transformers after
|
| 140 |
+
done
|
| 141 |
+
|
| 142 |
+
# === Phase B: before — swap ONLY the transformers/ dir to the parent commit ==
|
| 143 |
+
echo "######## PHASE B: before (parent commit ${PARENT}) ########"
|
| 144 |
+
git -C "$VLLM" checkout "$PARENT" -- "$TFDIR"
|
| 145 |
+
git -C "$VLLM" status --porcelain "$TFDIR"
|
| 146 |
+
for spec in "${MODELS[@]}"; do
|
| 147 |
+
dispatch "$spec" transformers before
|
| 148 |
+
done
|
| 149 |
+
|
| 150 |
+
restore
|
| 151 |
+
echo "######## DONE — results in $OUT ; tree restored to PR files ########"
|