okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6e1085c1d
main
1"""WSL-only evaluation using EvalPlus 0.3.1's official checking functions.""" 2import argparse 3import hashlib 4import json 5from pathlib import Path 6import sys 7import time 8 9from evalplus .data import get_human_eval_plus ,get_human_eval_plus_hash 10from evalplus .eval import PASS ,untrusted_check 11from evalplus .evaluate import get_groundtruth 12 13 14def main (): 15ap = argparse .ArgumentParser () 16ap .add_argument ("--out" ,required = True ,type = Path ) 17ap .add_argument ("--sanity" ,action = "store_true" ) 18ap .add_argument ("--limit-seconds" ,type = float ,default = 720 ) 19a = ap .parse_args () 20a .out .mkdir (parents = True ,exist_ok = True ) 21all_problems = get_human_eval_plus () 22ids = sorted (all_problems ,key = lambda x :int (x .split ("/" )[- 1 ]))[:40 ] 23problems = {k :all_problems [k ]for k in ids } 24digest = get_human_eval_plus_hash () 25if not a .sanity : 26saved_dataset = json .loads ((a .out / "humaneval-subset.json" ).read_text (encoding = "utf-8" )) 27if saved_dataset ["dataset_hash" ]!= digest or saved_dataset ["ids" ]!= ids : 28raise RuntimeError ("Evaluation dataset differs from the saved generation dataset" ) 29if a .sanity : 30 (a .out / "humaneval-subset.json" ).write_text (json .dumps ({"dataset_hash" :digest , 31"ids" :ids ,"problems" :problems },ensure_ascii = False ),encoding = "utf-8" ) 32oracle = get_groundtruth (problems ,digest + "-numeric-first40-strata0141" , []) 33p = problems [ids [0 ]] 34o = oracle [ids [0 ]] 35 36def check (code ,problem ,ref ,part ): 37status ,details = untrusted_check ("humaneval" ,code ,problem [part + "_input" ], 38problem ["entry_point" ],ref [part ],problem ["atol" ],ref [part + "_time" ],fast_check = True ) 39return {"status" :status ,"tested_inputs" :len (details ),"passed_inputs" :sum (map (bool ,details ))} 40 41if a .sanity : 42correct = check (p ["prompt" ]+ p ["canonical_solution" ],p ,o ,"base" ) 43wrong = check (p ["prompt" ]+ f"\n return None\n" ,p ,o ,"base" ) 44ready = correct ["status" ]== PASS and wrong ["status" ]!= PASS 45 (a .out / "eval-ready.json" ).write_text (json .dumps ({"ready" :ready ,"version" :"0.3.1" , 46"dataset_hash" :digest ,"canonical" :correct ,"intentional_wrong" :wrong }),encoding = "utf-8" ) 47json .dumps ({"evaluator_ready" :ready ,"subset" :len (ids )}),flush = True ) 48return 0 if ready else 1 49deadline = time .monotonic ()+ a .limit_seconds 50def save_results (path ,rows ): 51temporary = path .with_suffix (".json.tmp" ) 52temporary .write_text (json .dumps (rows ,indent = 2 ),encoding = "utf-8" ) 53temporary .replace (path ) 54 55for file in sorted ((a .out / "code" ).glob ("*-samples.jsonl" )): 56samples = {s ["task_id" ]:s for s in (json .loads (line )for line in file .read_text (encoding = "utf-8" ).splitlines ()if line .strip ())} 57hashes = {tid :hashlib .sha256 (s ["solution" ].encode ("utf-8" )).hexdigest ()for tid ,s in samples .items ()} 58result_path = a .out / "code" / (file .stem + "-eval.json" ) 59old = json .loads (result_path .read_text (encoding = "utf-8" ))if result_path .exists ()else [] 60checked = {r ["task_id" ]:r for r in old if r .get ("solution_sha256" )== hashes .get (r ["task_id" ]) 61and r .get ("dataset_hash" )== digest and r .get ("evalplus_version" )== "0.3.1" } 62for tid ,sample in samples .items (): 63if tid in checked : 64continue 65if time .monotonic ()>= deadline : 66break 67base = check (sample ["solution" ],problems [tid ],oracle [tid ],"base" ) 68plus = check (sample ["solution" ],problems [tid ],oracle [tid ],"plus" ) 69checked [tid ]= {"task_id" :tid ,"base" :base ,"plus" :plus , 70"solution_sha256" :hashes [tid ],"dataset_hash" :digest ,"evalplus_version" :"0.3.1" , 71"base_and_plus_pass" :base ["status" ]== plus ["status" ]== PASS } 72save_results (result_path ,list (checked .values ())) 73results = list (checked .values ()) 74save_results (result_path ,results ) 75json .dumps ({"file" :file .name ,"evaluated" :len (results ), 76"base_pass" :sum (r ["base" ]["status" ]== PASS for r in results ), 77"plus_pass" :sum (r ["base_and_plus_pass" ]for r in results )}),flush = True ) 78return 0 79 80 81if __name__ == "__main__" : 82sys .exit (main ())