File size: 5,501 Bytes
688186a | 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 | #!/usr/bin/env bash
# Perf against the already-running vLLM server container: batch-1 decode, prefill at 2k/32k, throughput at c=8/32,
# plus spec-decode acceptance scraped from /metrics before/after.
# Usage: run_perf.sh LABEL (env: NAME, PORT, SERVED_NAME, MODEL_DIR (tokenizer), SPEC (label only), REASONING_EFFORT)
# Runs `vllm bench serve` inside the server container via docker exec (so the same image/version is used).
# Results: results/<LABEL>/perf/*.json and perf_summary.json. LABEL should encode the config, e.g. official_mtp1.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
LABEL="${1:?LABEL}"
NAME="${NAME:-inkling-vllm}"
PORT="${PORT:-8000}"
SERVED_NAME="${SERVED_NAME:-inkling}"
OUT="$ROOT/results/$LABEL/perf"
mkdir -p "$OUT"
PY="${EVAL_PY:-$ROOT/.venv-eval/bin/python}"
BASE="http://localhost:8000" # inside the container
scrape() { # snapshot all spec_decode counters
curl -sf "localhost:${PORT}/metrics" | grep -E '^vllm:spec_decode' > "$OUT/metrics_$1.txt" || : > "$OUT/metrics_$1.txt"
}
bench() { # name in out conc prompts [backend endpoint]
echo "=== bench $1 ($LABEL) ==="
docker exec "$NAME" vllm bench serve \
--backend "${6:-openai-chat}" --endpoint "${7:-/v1/chat/completions}" \
--model "$SERVED_NAME" --tokenizer /model --base-url "$BASE" \
--dataset-name random --random-input-len "$2" --random-output-len "$3" --ignore-eos \
--max-concurrency "$4" --num-prompts "$5" --seed 42 \
--extra-body "{\"chat_template_kwargs\": {\"reasoning_effort\": \"${REASONING_EFFORT:-low}\"}}" \
--save-result --result-dir /tmp/bench --result-filename "$1.json"
docker cp "$NAME:/tmp/bench/$1.json" "$OUT/$1.json"
}
# the image lacks vllm[bench] extras
docker exec "$NAME" python3 -m pip install -q pandas datasets >/dev/null 2>&1 || true
bench warmup 512 64 4 8
# realistic-text decode at batch 1: DSpark acceptance on random tokens is ~0, so MTP speed/acceptance come from this one
docker cp "$ROOT/configs/decode_prompts.jsonl" "$NAME:/tmp/decode_prompts.jsonl"
scrape before
echo "=== bench decode_real_c1 ($LABEL) ==="
docker exec "$NAME" vllm bench serve \
--backend openai-chat --endpoint /v1/chat/completions \
--model "$SERVED_NAME" --tokenizer /model --base-url "$BASE" \
--dataset-name custom --dataset-path /tmp/decode_prompts.jsonl --custom-output-len 512 --ignore-eos \
--max-concurrency 1 --num-prompts 16 --seed 42 \
--extra-body "{\"chat_template_kwargs\": {\"reasoning_effort\": \"${REASONING_EFFORT:-low}\"}}" \
--save-result --result-dir /tmp/bench --result-filename decode_real_c1.json
docker cp "$NAME:/tmp/bench/decode_real_c1.json" "$OUT/decode_real_c1.json"
scrape mid
bench decode_c1 1024 512 1 8
bench prefill_2k 2048 1 1 8 openai /v1/completions
bench prefill_32k 32768 1 1 4 openai /v1/completions
bench thr_c8 1024 512 8 32
bench thr_c32 1024 512 32 64
scrape after
docker logs "$NAME" 2>&1 | grep -iE "model loading took|KV cache|maximum concurrency|memory" > "$OUT/server_memory.log" || true
"$PY" - "$OUT" "$LABEL" "${SPEC:-unknown}" <<'PYEOF'
import json, re, sys
from pathlib import Path
out, label, spec = Path(sys.argv[1]), sys.argv[2], sys.argv[3]
def counters(p: Path) -> dict[str, float]:
d: dict[str, float] = {}
for line in p.read_text().splitlines():
m = re.match(r"(vllm:spec_decode\w*?)(\{[^}]*\})?\s+([0-9.eE+-]+)$", line)
if not m:
continue
name, labels, val = m.groups()
# Keep per-position series separate, sum duplicate engine/model labels otherwise.
key = name + (labels if "position" in (labels or "") else "")
d[key] = d.get(key, 0.0) + float(val)
return d
b, a = counters(out / "metrics_before.txt"), counters(out / "metrics_mid.txt") # acceptance on realistic text only
delta = {k: a[k] - b.get(k, 0.0) for k in a}
res: dict = {"label": label, "spec": spec, "spec_decode_delta": delta}
# Metric names are version dependent; confirm against metrics_after.txt on the real server.
drafts = next((v for k, v in delta.items() if k.startswith("vllm:spec_decode_num_drafts")), None)
draft_toks = next((v for k, v in delta.items() if k.startswith("vllm:spec_decode_num_draft_tokens")), None)
acc_toks = next((v for k, v in delta.items() if k.startswith("vllm:spec_decode_num_accepted_tokens") and "position" not in k), None)
if draft_toks:
res["acceptance_rate"] = acc_toks / draft_toks
if drafts:
res["mean_accepted_per_draft"] = acc_toks / drafts
res["mean_acceptance_length"] = 1 + acc_toks / drafts
for name in ("decode_real_c1", "decode_c1", "prefill_2k", "prefill_32k", "thr_c8", "thr_c32"):
f = out / f"{name}.json"
if f.exists():
j = json.loads(f.read_text())
res[name] = {
k: j.get(k)
for k in ("output_throughput", "total_token_throughput", "request_throughput",
"mean_ttft_ms", "median_ttft_ms", "mean_tpot_ms", "median_tpot_ms", "completed")
}
for name in ("decode_real_c1", "decode_c1"):
if name in res and res[name].get("median_tpot_ms"):
res[f"{name}_tok_s"] = 1000.0 / res[name]["median_tpot_ms"]
for name, n in (("prefill_2k", 2048), ("prefill_32k", 32768)):
if name in res and res[name].get("median_ttft_ms"):
res[f"{name}_tok_s"] = n / (res[name]["median_ttft_ms"] / 1000.0)
(out / "perf_summary.json").write_text(json.dumps(res, indent=2) + "\n")
print(json.dumps({k: v for k, v in res.items() if k != "spec_decode_delta"}, indent=1))
PYEOF
echo "done $LABEL"
|