Datasets:
File size: 9,964 Bytes
9379442 | 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | """Validate every row and recorded identity; optionally load all HF configs."""
from __future__ import annotations
import argparse
import json
import sys
from collections import Counter
from pathlib import Path
import pyarrow.parquet as pq
import yaml
from release_utils import ROOT, id_hash, load_json, normalized_prompt, sha256, write_json
EXPECTED = {'kodcode_sft': (35974, 100), 'kodcode_rl': (35974, 100),
'taco_leetcode_sft': (21779, 100), 'taco_leetcode_rl': (17249, 100)}
def check_file(path, family, kind, allowed):
parquet = pq.ParquetFile(path)
cols = ['problem_id', 'primary_category', 'prompt']
cols += ['response', 'messages'] if kind == 'sft' else ['reward_model', 'extra_info']
if family == 'kodcode' and kind == 'sft':
cols += ['original_question_id']
if family == 'taco_leetcode':
cols += ['overlap_categories']
ids, prompts, originals, categories, overlaps = [], {}, set(), {}, {}
verification = Counter()
tests_total = 0
for batch in parquet.iter_batches(batch_size=64, columns=cols):
for row in batch.to_pylist():
problem_id = row['problem_id']
assert isinstance(problem_id, str) and problem_id
assert row['primary_category'] in allowed, (problem_id, row['primary_category'])
ids.append(problem_id)
categories[problem_id] = row['primary_category']
if family == 'taco_leetcode':
assert row['overlap_categories'] and set(row['overlap_categories']) <= allowed
overlaps[problem_id] = row['overlap_categories']
if kind == 'sft':
assert isinstance(row['prompt'], str) and row['prompt'].strip()
assert isinstance(row['response'], str) and row['response'].strip()
messages = row['messages']
assert messages and messages[-1]['role'] == 'assistant'
assert messages[-1]['content'] == row['response']
users = [m['content'] for m in messages if m['role'] == 'user']
assert users and users[-1] == row['prompt']
text = row['prompt']
if family == 'kodcode':
originals.add(row['original_question_id'])
else:
messages = row['prompt']
assert messages and all(m['role'] in ('user', 'system') for m in messages)
assert any(m['role'] == 'user' and m['content'].strip() for m in messages)
info = row['extra_info']
assert info['problem_id'] == problem_id
ground = row['reward_model']['ground_truth']
ground = json.loads(ground) if isinstance(ground, str) else ground
assert ground['problem_id'] == problem_id
if family == 'kodcode':
assert ground['test_code'].strip() and ground['test_functions']
n = len(ground['test_functions'])
assert info['source_full_execution_verified'] is True
originals.add(info['original_question_id'])
else:
assert ground['tests']
assert ground['mode'] in ('stdin', 'function'), ground['mode']
n = len(ground['tests'])
verification['reference_execution' if info['canonical_verified'] else 'structural_only'] += 1
assert n == info['test_count_used'], (problem_id, n, info['test_count_used'])
tests_total += n
text = '\n'.join(m['content'] for m in messages if m['role'] == 'user')
prompts[problem_id] = normalized_prompt(text)
assert len(set(ids)) == len(ids), f'Duplicate IDs in {path}'
return {'ids': ids, 'prompts': prompts, 'originals': originals, 'categories': categories,
'overlaps': overlaps, 'verification': dict(verification), 'tests': tests_total}
def check_members(members, pool, *, overlap_removal=False):
for name, item in members.items():
ids = item['problem_ids']
assert len(ids) == item['rows'] == len(set(ids))
assert id_hash(ids) == item['problem_id_set_sha256']
assert set(ids) <= pool['categories'].keys(), name
removed = item['removed_category']
if removed:
for pid in ids:
labels = pool['overlaps'][pid] if overlap_removal else [pool['categories'][pid]]
assert removed not in labels, (name, pid)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--root', type=Path, default=ROOT)
parser.add_argument('--hf', action='store_true', help='Load all four configurations using datasets')
parser.add_argument('--cache-dir', type=Path, help='HF cache outside the release directory')
parser.add_argument('--report', type=Path)
args = parser.parse_args()
root = args.root.resolve()
file_index = root / 'metadata/release_files.json'
if file_index.exists():
for relpath, identity in load_json(file_index)['files'].items():
path = root / relpath
assert path.is_file() and path.stat().st_size == identity['bytes'], relpath
assert sha256(path) == identity['sha256'], relpath
print('RELEASE_FILE_INDEX_PASS', flush=True)
header = root.joinpath('README.md').read_text(encoding='utf-8').split('---', 2)[1]
configs = yaml.safe_load(header)['configs']
assert {x['config_name'] for x in configs} == set(EXPECTED)
report = {'status': 'PASS', 'configs': {}, 'checks': ['hashes', 'every-row schema', 'split IDs',
'split prompts', 'original question IDs', 'reward test structure', 'all ablation memberships']}
checked = {}
for family in ['kodcode', 'taco_leetcode']:
manifest = load_json(root / 'metadata' / family / 'dataset_manifest.json')
taxonomy = load_json(root / 'metadata' / family / 'taxonomy.json')
allowed = {x['id'] for x in taxonomy['categories']} if family == 'kodcode' else set(taxonomy['categories']) | {'no_tags'}
for kind in ['sft', 'rl']:
name = family + '_' + kind
results = {}
for split, expected_rows in zip(['train', 'validation'], EXPECTED[name]):
item = manifest['files'][kind + '/' + split]
path = root / item['path']
assert path.stat().st_size == item['bytes']
assert sha256(path) == item['sha256'], path
result = check_file(path, family, kind, allowed)
assert len(result['ids']) == expected_rows == item['rows']
assert id_hash(result['ids']) == item['problem_id_set_sha256']
results[split] = result
checked[name, split] = result
assert not set(results['train']['ids']) & set(results['validation']['ids'])
assert not results['train']['originals'] & results['validation']['originals']
shared_prompts = set(results['train']['prompts'].values()) & set(results['validation']['prompts'].values())
assert not shared_prompts, (name, 'duplicate prompts across splits', len(shared_prompts))
report['configs'][name] = {'train_rows': len(results['train']['ids']),
'validation_rows': len(results['validation']['ids']),
'train_validation_id_overlap': 0, 'train_validation_prompt_overlap': 0}
if kind == 'rl':
report['configs'][name]['test_cases'] = {s: r['tests'] for s, r in results.items()}
report['configs'][name]['verification'] = {s: r['verification'] for s, r in results.items()}
print(name, 'PASS', flush=True)
for split in ['train', 'validation']:
assert set(checked['kodcode_sft', split]['ids']) == set(checked['kodcode_rl', split]['ids'])
kod_members = load_json(root / 'metadata/kodcode/ablation_membership.json')['arms']
check_members(kod_members, checked['kodcode_sft', 'train'])
legacy = load_json(root / 'metadata/taco_leetcode/ablation_membership.json')
original_sft = {key: {**checked['taco_leetcode_sft', 'train'][key], **checked['taco_leetcode_sft', 'validation'][key]}
for key in ['categories', 'overlaps']}
check_members(legacy['sft_historical'], original_sft, overlap_removal=True)
check_members(legacy['sft_release'], checked['taco_leetcode_sft', 'train'], overlap_removal=True)
check_members(legacy['rl_historical'], checked['taco_leetcode_rl', 'train'], overlap_removal=True)
report['cross_config_id_overlap'] = {
'taco_sft_train_vs_rl_validation': len(set(checked['taco_leetcode_sft', 'train']['ids']) & set(checked['taco_leetcode_rl', 'validation']['ids'])),
'taco_sft_validation_vs_rl_train': len(set(checked['taco_leetcode_sft', 'validation']['ids']) & set(checked['taco_leetcode_rl', 'train']['ids'])),
'note': 'Independent historical experiments; not a joint multi-stage holdout.',
}
if args.hf:
from datasets import get_dataset_config_names, load_dataset
cache = str(args.cache_dir.resolve()) if args.cache_dir else None
assert set(get_dataset_config_names(str(root), cache_dir=cache)) == set(EXPECTED)
for name, sizes in EXPECTED.items():
ds = load_dataset(str(root), name, cache_dir=cache)
assert set(ds) == {'train', 'validation'}
for split, expected in zip(['train', 'validation'], sizes):
assert len(ds[split]) == expected
assert ds[split][0]['problem_id']
report['configs'][name]['huggingface_load'] = 'PASS'
print(name, 'HF_LOAD_PASS', flush=True)
if args.report:
write_json(args.report, report)
print(json.dumps({'status': report['status'], 'configs': len(report['configs'])}))
if __name__ == '__main__':
main()
|