#!/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)}")