Datasets:
Download endless_v3/patch.py from FWeindel/validated-tasks: direct link, hf CLI and curl.
- Browser
- Download file 3.94 kB
-
https://huggingface.co/datasets/FWeindel/validated-tasks/resolve/refs%2Fpr%2F30/endless_v3/patch.py
- Command line
-
hf download hf://datasets/FWeindel/validated-tasks@refs/pr/30/endless_v3/patch.py
-
curl -L -o patch.py https://huggingface.co/datasets/FWeindel/validated-tasks/resolve/refs%2Fpr%2F30/endless_v3/patch.py
3.94 kB
| """Rebuild Endless v3 tasks.parquet and archive.parquet from pinned v2 Parquets and metadata/selection.json. | |
| pip install pyarrow huggingface_hub | |
| python patch.py --out rebuilt | |
| Optional --source-dir holds v2 tasks.parquet and archive.parquet for offline reproduction. | |
| """ | |
| import argparse, json | |
| from pathlib import Path | |
| import pyarrow as pa | |
| import pyarrow.parquet as pq | |
| def build(out, source_dir=None): | |
| m = json.loads((Path(__file__).parent / 'metadata/selection.json').read_text()) | |
| def source(name): | |
| if source_dir: | |
| return source_dir / name | |
| from huggingface_hub import hf_hub_download | |
| return Path(hf_hub_download(m['repo_id'], f'endless_v2/{name}', repo_type='dataset', | |
| revision=m['v2_revision'], cache_dir=out / '.source-cache')) | |
| out.mkdir(parents=True, exist_ok=True) | |
| assert not any((out / n).exists() for n in ['tasks.parquet', 'archive.parquet']) | |
| old, arch = pq.read_table(source('tasks.parquet')), pq.read_table(source('archive.parquet')) | |
| extra = [pa.field('qwen38_attempts', pa.int64()), pa.field('qwen38_successes', pa.int64()), | |
| pa.field('qwen38_target_attempts', pa.int64()), pa.field('kept_from_v2', pa.bool_())] | |
| kept, excluded = [], [] | |
| for r in old.to_pylist(): | |
| assert m['tasks'][r['path']]['kept_from_v2'] | |
| kept.append({**r, 'qwen38_attempts': 0, 'qwen38_successes': None, 'qwen38_target_attempts': None, 'kept_from_v2': True}) | |
| for r in arch.to_pylist(): | |
| e = m['tasks'][r['path']] | |
| assert r['content_sha256'] == e['qwen38_evaluated_content_sha256'] | |
| r.update(qwen38_attempts=e['qwen38_attempts'], qwen38_successes=e['qwen38_successes'], | |
| qwen38_target_attempts=m['attempts'], kept_from_v2=False) | |
| if e['kept']: | |
| r.update(archive_stage=None, archive_reason=None, archive_labels=[]) | |
| kept.append(r) | |
| else: | |
| r.update(archive_reason='zero_success_three_models', archive_labels=['zero_success_three_models']) | |
| excluded.append(r) | |
| def images(rows): | |
| merged = json.loads(old.schema.metadata[b'ot.images.v1']) | |
| other = json.loads(arch.schema.metadata[b'ot.images.v1']) | |
| merged['tasks'].update(other['tasks']) | |
| merged['bundles'].update(other['bundles']) | |
| names = {r['path'] for r in rows} | |
| merged['tasks'] = {t: e for t, e in merged['tasks'].items() if t in names} | |
| used = {e['bundle'] for t in merged['tasks'].values() for e in t['environments']} | |
| merged['bundles'] = {k: v for k, v in merged['bundles'].items() if k in used} | |
| if 'uncached_task_ids' in merged: | |
| merged['uncached_task_ids'] = sorted(names - set(merged['tasks'])) | |
| merged['coverage'] = {'cached_tasks': len(merged['tasks']), 'total_tasks': len(names)} | |
| return json.dumps(merged).encode() | |
| s = m['summary'] | |
| release = json.dumps({k: s[k] for k in ['previous_revision', 'source_folder', 'source_revision', 'new_model', 'attempts', | |
| 'evaluated', 'v2_kept', 'newly_solved', 'kept', 'reward_policy']}).encode() | |
| for name, table, rows in [('tasks.parquet', old, kept), ('archive.parquet', arch, excluded)]: | |
| schema = pa.schema([*table.schema, *extra]) | |
| pq.write_table(pa.Table.from_pylist(sorted(rows, key=lambda r: r['path']), schema=schema) | |
| .replace_schema_metadata({b'ot.images.v1': images(rows), b'ot.release.v3': release}), | |
| out / name, compression='zstd') | |
| assert len(kept) == s['kept'] and len(excluded) == s['excluded'] | |
| print(json.dumps({'kept': len(kept), 'excluded': len(excluded)})) | |
| if __name__ == '__main__': | |
| p = argparse.ArgumentParser(description=__doc__) | |
| p.add_argument('--out', type=Path, required=True) | |
| p.add_argument('--source-dir', type=Path) | |
| a = p.parse_args() | |
| build(a.out, a.source_dir) | |