Datasets:
Download crosscodeeval_v2/patch.py from FWeindel/validated-tasks: direct link, hf CLI and curl.
- Browser
- Download file 7.78 kB
-
https://huggingface.co/datasets/FWeindel/validated-tasks/resolve/refs%2Fpr%2F20/crosscodeeval_v2/patch.py
- Command line
-
hf download hf://datasets/FWeindel/validated-tasks@refs/pr/20/crosscodeeval_v2/patch.py
-
curl -L -o patch.py https://huggingface.co/datasets/FWeindel/validated-tasks/resolve/refs%2Fpr%2F20/crosscodeeval_v2/patch.py
7.78 kB
| """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() | |