Download scripts/verify.py from HuggingFaceSwarms/SmallMath: direct link, hf CLI and curl.
- Browser
- Download file 2.23 kB
-
https://huggingface.co/datasets/HuggingFaceSwarms/SmallMath/resolve/main/scripts/verify.py
- Command line
-
hf download hf://datasets/HuggingFaceSwarms/SmallMath/scripts/verify.py
-
curl -L -o verify.py https://huggingface.co/datasets/HuggingFaceSwarms/SmallMath/resolve/main/scripts/verify.py
2.23 kB
| #!/usr/bin/env python3 | |
| """Run every oracle and sample rejection checks. Requires bash, python3 and timeout.""" | |
| import concurrent.futures, json, os, pathlib, subprocess, tempfile | |
| ROOT=pathlib.Path(__file__).resolve().parents[1] | |
| tasks=sorted(p for p in (ROOT/'tasks').iterdir() if p.is_dir()) | |
| assert len(tasks)==600 | |
| def run(task, case='oracle'): | |
| with tempfile.TemporaryDirectory(prefix='smallmath-check-') as tmp: | |
| p=pathlib.Path(tmp); answer=p/'answer.txt'; out=p/'verifier'; out.mkdir(); temp=p/'temp'; temp.mkdir() | |
| env={**os.environ,'ANSWER':str(answer),'VERIFIER_DIR':str(out),'TMPDIR':str(temp),'PYTHONDONTWRITEBYTECODE':'1'} | |
| if case=='oracle': subprocess.run(['bash',str(task/'solution/solve.sh')],env=env,check=True,capture_output=True) | |
| elif case=='wrong': answer.write_text(str(int(json.loads((task/'tests/reference.json').read_text())['answer'])+1)) | |
| elif case=='empty': answer.touch() | |
| elif case=='symlink': | |
| target=p/'target'; target.write_text(json.loads((task/'tests/reference.json').read_text())['answer']); answer.symlink_to(target) | |
| elif case=='oversized': answer.write_text('0'*10001) | |
| elif case=='fifo': os.mkfifo(answer) | |
| elif case!='missing': raise ValueError(case) | |
| result=subprocess.run(['bash',str(task/'tests/test.sh')],env=env,check=True,capture_output=True,text=True,timeout=180) | |
| reward=(out/'reward.txt').read_text().strip(); expected='1' if case=='oracle' else '0' | |
| return task.name,case,reward,expected,result.stdout.strip(),(out/'grade.json').read_text() | |
| if __name__=='__main__': | |
| failures=[] | |
| with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool: | |
| for i,r in enumerate(pool.map(run,tasks),1): | |
| if r[2]!=r[3]: failures.append(r); print('FAIL',r,flush=True) | |
| if i%50==0: print('oracle',i,'/',len(tasks),'failures',len(failures),flush=True) | |
| sample=[next(t for t in tasks if f'level = {i}\n' in (t/'task.toml').read_text()) for i in range(1,7)] | |
| results=[run(t,c) for t in sample for c in ['wrong','empty','missing','symlink','oversized','fifo']] | |
| failures.extend(r for r in results if r[2]!=r[3]); print('negative',len(results)-sum(r[2]!=r[3] for r in results),'/',len(results),flush=True) | |
| print('failures',json.dumps(failures),flush=True) | |
| assert not failures | |