FWeindel's picture
Publish partial CalibForge v2 and verified SETA and CalibForge traces
2c4a6c3 verified
Raw History Blame
2.05 kB
"""Reproduce CalibForge v2 from pinned v1 and a frozen partial-results snapshot."""
import argparse,json,hashlib
from pathlib import Path
import pyarrow as pa,pyarrow.parquet as pq
from huggingface_hub import hf_hub_download
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--out',type=Path,required=True);p.add_argument('--source',type=Path);a=p.parse_args();a.out.mkdir(parents=True,exist_ok=True)
assert not (a.out/'tasks.parquet').exists()
m=json.loads((Path(__file__).parent/'assets/selection.json').read_text());f=a.source or Path(hf_hub_download(m['repo_id'],m['source_folder']+'/tasks.parquet',revision=m['source_revision'],repo_type='dataset',cache_dir=a.out/'.source-cache'));assert hashlib.sha256(f.read_bytes()).hexdigest()==m['source_sha256']
src=pq.ParquetFile(f);schema=src.schema_arrow.remove_metadata()
for name in ['instruct_successes','instruct_graded_attempts','instruct_missing_attempts','target_attempts_per_model']:schema=schema.append(pa.field(name,pa.int64()))
rows=[]
for batch in src.iter_batches(batch_size=32):
for r in batch.to_pylist():
s=m['tasks'][r['path']];assert r['content_sha256']==s['content_sha256']
if not s['kept']:continue
for k in ['instruct_successes','instruct_graded_attempts','instruct_missing_attempts']:r[k]=s[k]
assert r['instruct_successes']>0;r['target_attempts_per_model']=8;rows.append(r)
assert len(rows)==84
names={r['path'] for r in rows};im=json.loads(src.schema_arrow.metadata[b'ot.images.v1']);im['tasks']={k:v for k,v in im['tasks'].items() if k in names};assert set(im['tasks'])==names
bundles={e['bundle'] for v in im['tasks'].values() for e in v['environments']};im['bundles']={k:v for k,v in im['bundles'].items() if k in bundles};im['missing']=[]
meta={b'ot.images.v1':json.dumps(im).encode(),b'ot.release.v2':json.dumps({k:v for k,v in m.items() if k!='tasks'}).encode()};pq.write_table(pa.Table.from_pylist(rows,schema=schema).replace_schema_metadata(meta),a.out/'tasks.parquet',compression='zstd');print('Retained',len(rows),'images reused',len(bundles))