"""greedy_compare.py URL_A URL_B [--max-tokens N] -- greedy decoding on two radiance servers, token for token. Milestone A's check (docs/SYCL_PROGRESS.md): the Intel (SYCL) backend and the host backend serve the same container; at temperature 0 their outputs must agree. Each prompt goes to both servers through /v1/completions with logprobs, so the comparison is on token ids as the servers report them (the `tokens` field) and their text, and the first divergence is reported with both sides' top candidates at that step: a near-tie that flips is told apart from a broken kernel by the logit gap. Exit status 0 when every prompt agrees, 1 otherwise. Standard library only. """ import argparse import json import sys import urllib.request PROMPTS = [ "The capital of France is", "def fibonacci(n):\n ", "Q: What is 17 times 23?\nA:", "Once upon a time, in a village by the sea,", "The three primary colors are", "Translate to German: 'The weather is nice today.'\nGerman:", "<|im_start|>user\nWrite one sentence about the ocean.<|im_end|>\n<|im_start|>assistant\n", "List the planets of the solar system in order from the sun:", ] def complete(url, prompt, max_tokens): body = json.dumps({"prompt": prompt, "max_tokens": max_tokens, "temperature": 0, "logprobs": 5}).encode() req = urllib.request.Request(url.rstrip("/") + "/v1/completions", data=body, headers={"Content-Type": "application/json"}) with urllib.request.urlopen(req, timeout=3600) as r: out = json.load(r) ch = out["choices"][0] lp = ch.get("logprobs") or {} return ch.get("text", ""), lp.get("tokens") or [], lp.get("top_logprobs") or [] def main(): ap = argparse.ArgumentParser() ap.add_argument("a") ap.add_argument("b") ap.add_argument("--max-tokens", type=int, default=64) args = ap.parse_args() bad = 0 for p in PROMPTS: ta, toks_a, top_a = complete(args.a, p, args.max_tokens) tb, toks_b, top_b = complete(args.b, p, args.max_tokens) same = ta == tb and toks_a == toks_b n = min(len(toks_a), len(toks_b)) first = next((i for i in range(n) if toks_a[i] != toks_b[i]), None) if first is None and len(toks_a) != len(toks_b): first = n print(f"{'SAME' if same else 'DIFF'} {len(toks_a):3d} tok {p[:48]!r}") print(f" A: {ta[:160]!r}") if not same: bad += 1 print(f" B: {tb[:160]!r}") print(f" first divergence at token {first}") if first is not None and first < len(top_a) and first < len(top_b): print(f" A top: {json.dumps(top_a[first])}") print(f" B top: {json.dumps(top_b[first])}") print(f"{len(PROMPTS) - bad}/{len(PROMPTS)} prompts identical") return 0 if bad == 0 else 1 if __name__ == "__main__": sys.exit(main())