Files
xpu-llm-ports/lfm3/tests/compare_greedy_server.py
Pascal LinxweilerandClaude Opus 5.5 4e7a7ce903 Add LFM3-1.7B vLLM XPU plugin
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>
2026-10-28 22:06:44 +01:00

31 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Greedy-decode the ref_compare prompts on a running server and compare with a saved
ref_compare vLLM run (default: results/vllm_bf16.json, eager mode). repetition_penalty is
forced to 1.0: vLLM serve otherwise applies generation_config.json (1.1) as default.
python3 tests/compare_greedy_server.py [results/vllm_bf16.json] [--concurrent]
"""
import json, sys, urllib.request
from concurrent.futures import ThreadPoolExecutor
path = next((a for a in sys.argv[1:] if a.endswith(".json")), "results/vllm_bf16.json")
ref = json.load(open(path))["results"]
def gen(item):
name, r = item
body = {"model": "lfm3-1.7b", "prompt": r["prompt_ids"], "max_tokens": len(r["gen_ids"]),
"temperature": 0.0, "repetition_penalty": 1.0, "ignore_eos": True, "logprobs": 1, "return_tokens_as_token_ids": True}
req = urllib.request.Request("http://127.0.0.1:8000/v1/completions", json.dumps(body).encode(),
{"Content-Type": "application/json"})
out = json.loads(urllib.request.urlopen(req, timeout=300).read())
toks = [int(t.split(":")[1]) for t in out["choices"][0]["logprobs"]["tokens"]]
return name, toks
items = list(ref.items())
workers = len(items) if "--concurrent" in sys.argv else 1
with ThreadPoolExecutor(workers) as ex:
for name, toks in ex.map(gen, items):
want = ref[name]["gen_ids"]
same = next((i for i, (a, b) in enumerate(zip(toks, want)) if a != b), len(want))
print(f"{name:<15} identical prefix {same}/{len(want)}")