﻿# E17: MATH-500 greedy baseline, 14B Q4_K_M-imat (+0.5B draft for speed only; greedy spec decoding is output-equivalent), 2048-token cap.
# Reason: E16 showed GSM8K-128 is ~95% once not truncated, so reasoning methods need a benchmark with headroom.
import json, time, requests
from datasets import load_dataset
URL="http://127.0.0.1:8093"; OUT="results/quality/e17_math500_greedy.jsonl"
ds=load_dataset("HuggingFaceH4/MATH-500",split="test")
with open(OUT,"w",encoding="utf-8") as f:
  for k in range(len(ds)):
    ex=ds[k]
    p=("<|im_start|>system\nPlease reason step by step, and put your final answer within \\boxed{}.<|im_end|>\n<|im_start|>user\n"+ex["problem"]+
       "<|im_end|>\n<|im_start|>assistant\n")
    t=time.time(); j=requests.post(URL+"/completion",json={"prompt":p,"n_predict":2048,"cache_prompt":False,"temperature":0,"top_k":1,"seed":0},timeout=3600).json()
    tm=j.get("timings",{})
    rec={"item":k,"unique_id":ex["unique_id"],"level":ex["level"],"subject":ex["subject"],"gold":ex["answer"],"text":j.get("content",""),"timings":tm,"wall":round(time.time()-t,2)}
    f.write(json.dumps(rec)+"\n"); f.flush()
    print(k, tm.get("predicted_n"), tm.get("draft_n_accepted"), tm.get("predicted_per_second"), flush=True)
print("E17PYDONE", flush=True)
