"""Replay a downloaded v3 export. Requires Linux chroot/seccomp setup privileges. Example (from the downloaded HF repository root): python curation/v3/scripts/reverify_export.py --repo-root . Only the messages field is counted as training input. No source-provided scripts are imported or executed in the host process. Candidate Python runs in the restricted worker, never with an HF token. No credentials are read by this tool. """ import argparse import gzip import hashlib import json from pathlib import Path import jsonschema from transformers import AutoTokenizer from verify import self_test, static_check, verify_suite, sha def main(): parser = argparse.ArgumentParser() parser.add_argument('--repo-root', type=Path, required=True) parser.add_argument('--tokenizer-dir', type=Path, help='Optional local copy of the pinned tokenizer') args = parser.parse_args() root = args.repo_root.resolve() self_test() meta = json.loads((root/'curation/v3/tokenization.json').read_text()) if args.tokenizer_dir: tokenizer = AutoTokenizer.from_pretrained(args.tokenizer_dir, local_files_only=True, trust_remote_code=False) else: tokenizer = AutoTokenizer.from_pretrained(meta['model'],revision=meta['revision'],trust_remote_code=False,token=False) if sha(tokenizer.chat_template) != meta['chat_template_sha256']: raise RuntimeError('Wrong tokenizer/chat template') validator = jsonschema.Draft202012Validator(json.loads((root/'schemas/python_verified_v3.schema.json').read_text())) rows = total = 0 paths = sorted(root.glob('data/16k_context/taco_v3_pilot_*.jsonl')) + sorted(root.glob('data/above_16k/taco_v3_pilot_*.jsonl')) for path in paths: for line in path.read_text().splitlines(): if not line.strip(): continue row = json.loads(line); validator.validate(row); static_check(row['code']) count = len(tokenizer.apply_chat_template(row['messages'], tokenize=True, add_generation_prompt=False)) if count != row['token_counts']['training_total']: raise RuntimeError('Stale token count: '+row['id']) if ('16k_context' if count<=16384 else 'above_16k') != row['context_bucket']: raise RuntimeError('Wrong bucket') artifact = root/row['tests']['artifact_path'] if hashlib.sha256(artifact.read_bytes()).hexdigest() != row['tests']['artifact_sha256']: raise RuntimeError('Test artifact hash mismatch') suite = json.loads(gzip.decompress(artifact.read_bytes())) result = verify_suite(row['code'],suite['entry_point'],suite['cases']) if result['failed']: raise RuntimeError(json.dumps(result,indent=2)) rows+=1; total+=result['total'] print(row['id'],f"{result['passed']}/{result['total']}",count,'tokens',flush=True) print(f'Reverified {rows} Python rows; {total} successful test-case executions.') if __name__ == '__main__': main()