davidheineman's picture
Publish coherent math-v1 datasets
8cd8c53 verified
Raw History Blame Contribute Delete
3.52 kB
import csv
import html
import importlib.util
import json
from pathlib import Path
import time
from refined_v4.report import curves
from refined_v4.study import read, write
def update(root: Path, results: Path):
plan = read(root / 'plan.json')
records = []
for case in plan['cases']:
folder = Path(case['output'])
points = curves(folder)
latest = (points['rl'] or points['sft'] or [None])[-1]
records.append(dict(case=case, curves=points, latest=latest,
complete=(folder / 'complete.json').exists(),
resume=read(folder / 'resume.json') if (folder / 'resume.json').exists() else {},
wandb=read(folder / 'wandb.json') if (folder / 'wandb.json').exists() else {}))
write(results / '.cache/runs.json', dict(updated=time.time(), protocol=plan, runs=records))
with (results / 'summary.csv').open('w', newline='') as stream:
writer = csv.DictWriter(stream, fieldnames=['task', 'model', 'phase', 'counter', 'pass1', 'complete', 'wandb'])
writer.writeheader()
for row in records:
latest = row['latest'] or {}
writer.writerow(dict(task=row['case']['task'], model=row['case']['model'],
phase='complete' if row['complete'] else row['resume'].get('phase', 'waiting'),
counter=latest.get('counter', ''), pass1=latest.get('metric', {}).get('pass1', ''),
complete=row['complete'], wandb=row['wandb'].get('url', '')))
script = results / '.plotting/plot.py'
spec = importlib.util.spec_from_file_location('math_revision_plot', script)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
module.plot(records, results, plan['sft_tokens'])
rows = []
for row in records:
metric = (row['latest'] or {}).get('metric', {})
url = row['wandb'].get('url', '')
score = f'{metric["pass1"]:.1%}' if metric.get('pass1') is not None else '—'
cells = [row['case']['label'], row['case']['model'], 'Complete' if row['complete'] else row['resume'].get('phase', 'Waiting'), score]
rows.append('<tr>' + ''.join('<td>' + html.escape(str(value)) + '</td>' for value in cells)
+ f'<td><a href="{html.escape(url)}">W&amp;B</a></td></tr>')
budget = plan['sft_tokens']
sibling = '../index.html' if root.name == 'pilot-2m' else 'pilot-2m/index.html'
(results / 'index.html').write_text(f'''<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="refresh" content="120">
<title>Math-v1</title><style>body{{font:15px system-ui;max-width:1100px;margin:30px auto;padding:20px}}img{{width:100%}}td,th{{padding:8px;text-align:left}}table{{width:100%;border-collapse:collapse}}tr{{border-bottom:1px solid #ddd}}</style></head><body>
<h1>Math-v1 · {budget:,} SFT tokens</h1><p>{sum(row['complete'] for row in records)}/16 complete. Four base models at 30 TPP; 65,536 RL samples with groups of 32.</p>
<p>Small arithmetic, locked GSM calculations, and uniform missing lengths 1–16 sampled before eligible questions. Native few-shot documents. Difficulty is logged separately from hint length.</p>
<p><a href="{sibling}">Other SFT budget</a> · <a href="https://huggingface.co/datasets/davidheineman/tiny-rl-refined-math-v1">Dataset</a> · <a href="summary.csv">CSV</a></p>
<img src="sft_and_rl.png"><img src="difficulty.png"><table><tr><th>Task</th><th>Model</th><th>Stage</th><th>Pass@1</th><th>Run</th></tr>{''.join(rows)}</table></body></html>''')