Datasets:
File size: 7,776 Bytes
6a0f908 f68e6b9 6a0f908 f68e6b9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | """Reproduce CrossCodeEval v2 from pinned v1 Parquets and the recorded pass@16 results.
pip install pyarrow huggingface_hub
python patch.py --out ./rebuilt
Use --source-dir PATH to reuse the two original v1 Parquets locally.
"""
import argparse
import copy
import hashlib
import json
import io
import tarfile
from pathlib import Path
import pyarrow as pa
import pyarrow.parquet as pq
MODELS = {'instruct_successes': 'qwen3-30b-instruct-2507',
'thinking_successes': 'qwen3-30b-thinking'}
def rows(path):
table = pq.ParquetFile(path)
for i in range(table.num_row_groups):
yield from table.read_row_group(i).to_pylist()
def restrict_images(manifest, names):
result = copy.deepcopy(manifest)
result['tasks'] = {k: v for k, v in manifest['tasks'].items() if k in names}
bundles = {e['bundle'] for t in result['tasks'].values() for e in t['environments']}
result['bundles'] = {k: v for k, v in manifest['bundles'].items() if k in bundles}
result['missing'] = []
return result
def build(source_dir, out, selection_path):
selection = json.loads(selection_path.read_text())
out.mkdir(parents=True, exist_ok=True)
if any((out / n).exists() for n in ('tasks.parquet', 'archive.parquet')):
raise ValueError('Output Parquets already exist; choose an empty output directory')
sources = {}
for name in ('tasks.parquet', 'archive.parquet'):
if source_dir is None:
from huggingface_hub import hf_hub_download
path = Path(hf_hub_download(selection['repo_id'], selection['source_folder'] + '/' + name,
repo_type='dataset', revision=selection['source_revision'], cache_dir=out / '.source-cache'))
else:
path = source_dir / name
with path.open('rb') as handle:
digest = hashlib.file_digest(handle, 'sha256').hexdigest()
if digest != selection['source_sha256'][name]:
raise ValueError('Pinned source hash mismatch: ' + name)
sources[name] = path
tasks = selection['tasks']
kept = {name for name, task in tasks.items() if task['kept']}
assert len(tasks) == 6710 and len(kept) == 863
original_schema = pq.read_schema(sources['tasks.parquet'])
image_manifest = json.loads(original_schema.metadata[b'ot.images.v1'])
images = restrict_images(image_manifest, kept)
assert set(images['tasks']) == kept
release = {k: v for k, v in selection.items() if k != 'tasks'}
release['selection_file'] = 'assets/selection.json'
metadata = {b'ot.release.v2': json.dumps(release).encode(), b'ot.images.v1': json.dumps(images).encode()}
schema = original_schema.remove_metadata().append(pa.field('instruct_successes', pa.int64())).append(
pa.field('thinking_successes', pa.int64())).append(pa.field('attempts_per_model', pa.int64())).append(pa.field('archive_category', pa.string()))
seen, audit = set(), {}
with pq.ParquetWriter(out / 'tasks.parquet', schema.with_metadata(metadata), compression='zstd') as retain, \
pq.ParquetWriter(out / 'archive.parquet', schema.with_metadata({b'ot.release.v2': json.dumps(release).encode()}), compression='zstd') as archive:
counts = {'retained': 0, 'newly_archived': 0, 'prior_archived': 0}
for row in rows(sources['tasks.parquet']):
name = row['path']
if name in seen or name not in tasks:
raise ValueError('Duplicate or unexpected task: ' + name)
seen.add(name)
result = tasks[name]
assert row['content_sha256'] == result['content_sha256']
for column, model in MODELS.items():
rewards = result['models'][model]['rewards']
assert len(rewards) == 16 and result['models'][model]['complete'] and result['models'][model]['missing'] == 0
row[column] = sum(reward >= 1 for reward in rewards)
assert row[column] == result['models'][model]['solved_attempts']
row['attempts_per_model'] = 16
selected = row['instruct_successes'] > 0 or row['thinking_successes'] > 0
assert selected == result['kept']
audit[name] = {'binary_sha256': hashlib.sha256(row['task_binary']).hexdigest(),
'content_sha256': row['content_sha256'], 'kept': selected}
if selected:
row['stages_passed'] = ','.join(dict.fromkeys(row['stages_passed'].split(',') + ['6']))
retain.write_table(pa.Table.from_pylist([row], schema=schema.with_metadata(metadata)))
counts['retained'] += 1
else:
row['archive_stage'] = 6
row['archive_reason'] = 'pass16-unsolved: no successful attempt in 16 Instruct and 16 Thinking trials; this is not a confirmed task defect.'
row['archive_labels'] = list(row.get('archive_labels') or []) + ['pass16-unsolved']
archive.write_table(pa.Table.from_pylist([row], schema=schema))
counts['newly_archived'] += 1
assert seen == set(tasks)
for row in rows(sources['archive.parquet']):
assert row['path'] not in seen
seen.add(row['path'])
# V1's original-source archive predates the validation columns.
# Preserve its category and reason while computing its content hash.
with tarfile.open(fileobj=io.BytesIO(row['task_binary']), mode='r:*') as archive_tar:
files = [(str(Path(m.name)), archive_tar.extractfile(m).read())
for m in archive_tar.getmembers() if m.isfile()]
digest = hashlib.sha256()
for name, content in sorted(files):
encoded = name.encode()
digest.update(len(encoded).to_bytes(8, 'big')); digest.update(encoded)
digest.update(len(content).to_bytes(8, 'big')); digest.update(content)
row['content_sha256'] = digest.hexdigest()
row['archive_stage'] = 0
row['stages_passed'] = ''
for column in MODELS:
row[column] = None
row['attempts_per_model'] = None
audit[row['path']] = {'binary_sha256': hashlib.sha256(row['task_binary']).hexdigest(),
'content_sha256': row['content_sha256'], 'kept': False}
archive.write_table(pa.Table.from_pylist([row], schema=schema))
counts['prior_archived'] += 1
assert counts == {'retained': 863, 'newly_archived': 5847, 'prior_archived': 1053}
checked = set()
for filename, expected_kept in [('tasks.parquet', True), ('archive.parquet', False)]:
for row in rows(out / filename):
prior = audit[row['path']]
assert row['path'] not in checked and prior['kept'] == expected_kept
assert hashlib.sha256(row['task_binary']).hexdigest() == prior['binary_sha256']
assert row['content_sha256'] == prior['content_sha256']
checked.add(row['path'])
assert checked == seen
print(json.dumps(dict(counts, preserved_task_payloads=len(checked), cached_bundles_reused=len(images['bundles']))))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--source-dir', type=Path)
parser.add_argument('--out', type=Path, required=True)
parser.add_argument('--selection', type=Path, default=Path(__file__).parent / 'assets' / 'selection.json')
parser.add_argument('--include-archive', action='store_true', help='Also reconstruct excluded payloads locally')
args = parser.parse_args()
build(args.source_dir, args.out, args.selection)
if not args.include_archive:
(args.out / 'archive.parquet').unlink()
|