Out-of-tree vLLM 0.32 plugin for LiquidAI LFM3 on Intel XPU: model, width-7 short-conv Triton kernels, Dockerfile, reference/API/bench tests, working notes and benchmark results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
118 lines
5.2 KiB
Python
118 lines
5.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Quick prefill / decode benchmark against a running LFM3 server, via `vllm bench serve`.
|
|
|
|
Scenarios (each at concurrency 1 and 16):
|
|
prefill : 4096 input tokens, 1 output token -> TTFT, prefill tok/s
|
|
decode : 128 input tokens, 512 output tokens -> TPOT, decode tok/s
|
|
mixed : 1024 in / 256 out (the classic serving shape; optional, --mixed)
|
|
|
|
python3 tests/bench.py --label eager # server on 127.0.0.1:8000
|
|
-> results/bench_<label>.md (+ raw JSON per run in results/bench_<label>/)
|
|
"""
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
import urllib.request
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
IMAGE = "lfm3-vllm-xpu"
|
|
|
|
SCENARIOS = {
|
|
# name: (input_len, output_len, {concurrency: num_prompts})
|
|
"prefill": (4096, 1, {1: 8, 16: 64}),
|
|
"decode": (128, 512, {1: 4, 16: 32}),
|
|
"mixed": (1024, 256, {1: 8, 16: 64}),
|
|
}
|
|
|
|
|
|
def prefix_cache_hits(base_url):
|
|
text = urllib.request.urlopen(base_url + "/metrics").read().decode()
|
|
return sum(float(l.split()[-1]) for l in text.splitlines() if l.startswith("vllm:prefix_cache_hits_total"))
|
|
|
|
|
|
def run(label, scenario, conc, base_url):
|
|
inp, out, nprompts = SCENARIOS[scenario]
|
|
rdir = os.path.join(ROOT, "results", f"bench_{label}")
|
|
os.makedirs(rdir, exist_ok=True)
|
|
fname = f"{scenario}_c{conc}.json"
|
|
cmd = [
|
|
"docker", "run", "--rm", "--name", "lfm3-bench", "--network", "host",
|
|
"-v", "/models/LFM3-1.7B:/models/LFM3-1.7B:ro", "-v", f"{rdir}:/results",
|
|
"--entrypoint", "vllm", IMAGE, "bench", "serve",
|
|
"--backend", "openai", "--base-url", base_url, "--model", "lfm3-1.7b",
|
|
"--tokenizer", "/models/LFM3-1.7B", "--dataset-name", "random",
|
|
"--random-input-len", str(inp), "--random-output-len", str(out), "--ignore-eos",
|
|
"--num-prompts", str(nprompts[conc]), "--max-concurrency", str(conc),
|
|
# fresh seed per run: identical random prompts would be served from the prefix cache
|
|
"--seed", str(time.time_ns() % 2**31), "--save-result", "--result-dir", "/results", "--result-filename", fname,
|
|
]
|
|
t0, hits0 = time.time(), prefix_cache_hits(base_url)
|
|
p = subprocess.run(cmd, capture_output=True, text=True)
|
|
if p.returncode != 0:
|
|
sys.exit(f"bench failed ({scenario} c={conc}):\n{p.stdout[-2000:]}\n{p.stderr[-2000:]}")
|
|
r = json.load(open(os.path.join(rdir, fname)))
|
|
r["_wall"] = time.time() - t0
|
|
r["_cache_hit_frac"] = (prefix_cache_hits(base_url) - hits0) / max(1, r["total_input_tokens"])
|
|
return r
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--label", required=True, help="e.g. eager, compiled")
|
|
ap.add_argument("--base-url", default="http://127.0.0.1:8000")
|
|
ap.add_argument("--mixed", action="store_true", help="also run 1024/256 mixed")
|
|
ap.add_argument("--only", choices=list(SCENARIOS), help="run a single scenario")
|
|
a = ap.parse_args()
|
|
|
|
# warm up (first requests after server start JIT-compile the Triton conv kernels)
|
|
for n_tok in (1024, 4096):
|
|
req = urllib.request.Request(
|
|
a.base_url + "/v1/completions",
|
|
json.dumps({"model": "lfm3-1.7b", "prompt": "hello " * n_tok, "max_tokens": 8}).encode(),
|
|
{"Content-Type": "application/json"},
|
|
)
|
|
urllib.request.urlopen(req, timeout=300).read()
|
|
|
|
scen = [a.only] if a.only else ["prefill", "decode"] + (["mixed"] if a.mixed else [])
|
|
rows = []
|
|
for s in scen:
|
|
for c in (1, 16):
|
|
r = run(a.label, s, c, a.base_url)
|
|
inp, out, _ = SCENARIOS[s]
|
|
rows.append((s, c, inp, out, r))
|
|
print(f"{s:<8} c={c:<3} TTFT {r['median_ttft_ms']:8.1f} ms TPOT {r['median_tpot_ms']:6.2f} ms "
|
|
f"in {r['total_input_tokens'] / r['duration']:8.0f} tok/s out {r['output_throughput']:7.1f} tok/s "
|
|
f"cache-hits {100 * r['_cache_hit_frac']:.1f}%")
|
|
|
|
md = [
|
|
f"# LFM3-1.7B bench — {a.label} ({time.strftime('%Y-%m-%d %H:%M')})",
|
|
"",
|
|
"Server: lfm3-vllm-xpu, Arc Pro B65, bf16, `vllm bench serve` random dataset, `--ignore-eos`.",
|
|
"",
|
|
"| scenario | conc | in/out | requests | median TTFT ms | P99 TTFT ms | median TPOT ms | P99 ITL ms | prefill tok/s | decode tok/s | total tok/s | prefix-cache hits |",
|
|
"|---|---|---|---|---|---|---|---|---|---|---|---|",
|
|
]
|
|
for s, c, inp, out, r in rows:
|
|
md.append(
|
|
f"| {s} | {c} | {inp}/{out} | {r['completed']} | {r['median_ttft_ms']:.1f} | {r['p99_ttft_ms']:.1f} | "
|
|
f"{r['median_tpot_ms']:.2f} | {r['p99_itl_ms']:.2f} | {r['total_input_tokens'] / r['duration']:.0f} | "
|
|
f"{r['output_throughput']:.1f} | {r['total_token_throughput']:.0f} | {100 * r['_cache_hit_frac']:.1f}% |"
|
|
)
|
|
md += [
|
|
"",
|
|
"- prefill tok/s = input tokens / duration (meaningful for the prefill rows: 1 output token).",
|
|
"- decode tok/s = output tokens / duration (meaningful for the decode rows).",
|
|
f"- raw JSON: results/bench_{a.label}/",
|
|
]
|
|
path = os.path.join(ROOT, "results", f"bench_{a.label}.md")
|
|
open(path, "w").write("\n".join(md) + "\n")
|
|
print(f"\n-> {path}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|