Download verify_release.py from KyleZ0906/rap_data_eval: direct link, hf CLI and curl.
- Browser
- Download file 4.95 kB
-
https://huggingface.co/datasets/KyleZ0906/rap_data_eval/resolve/main/verify_release.py
- Command line
-
hf download hf://datasets/KyleZ0906/rap_data_eval/verify_release.py
-
curl -L -o verify_release.py https://huggingface.co/datasets/KyleZ0906/rap_data_eval/resolve/main/verify_release.py
4.95 kB
| """Offline integrity and metric audit for the public six-arm release (stdlib only).""" | |
| from collections import Counter | |
| import hashlib | |
| from html.parser import HTMLParser | |
| import json | |
| from pathlib import Path | |
| import re | |
| import tarfile | |
| def main(): | |
| root = Path(__file__).resolve().parent | |
| release = root / 'e1-luna-six-way-20261003' | |
| def sha(data): | |
| return hashlib.sha256(data).hexdigest() | |
| checksums = {} | |
| for line in (root / 'SHA256SUMS').read_text().splitlines(): | |
| expected, name = line.split(' ', 1) | |
| assert not Path(name).is_absolute() and '..' not in Path(name).parts | |
| assert sha((root / name).read_bytes()) == expected, name | |
| checksums[name] = expected | |
| manifest = json.loads((release / 'manifest.json').read_text()) | |
| expected_members = {(m['archive'], m['path']): m for m in manifest['members'] if 'archive' in m} | |
| seen, archive_totals = set(), {} | |
| credential = re.compile(rb'\b(?:hf_[A-Za-z0-9]{10,}|sk-[A-Za-z0-9_-]{10,})\b') | |
| for name in checksums: | |
| path = root / name | |
| if path.suffix != '.gz': | |
| assert not credential.search(path.read_bytes()), 'Credential-like string in ' + name | |
| for archive_path in sorted((release / 'raw').glob('*.tar.gz')): | |
| arm = archive_path.name.removesuffix('.tar.gz') | |
| totals = Counter() | |
| with tarfile.open(archive_path, 'r:gz') as archive: | |
| for member in archive: | |
| assert member.isfile() and not Path(member.name).is_absolute() and '..' not in Path(member.name).parts | |
| key = (str(archive_path.relative_to(release)), member.name) | |
| assert key not in seen and key in expected_members | |
| seen.add(key) | |
| raw = archive.extractfile(member).read() | |
| assert sha(raw) == expected_members[key]['published_sha256'], key | |
| assert not credential.search(raw), 'Credential-like string in ' + member.name | |
| value = json.loads(raw) | |
| if member.name.endswith('/episode.json') or (arm.startswith('harbor') and member.name.endswith('/summary.json')): | |
| totals['n'] += 1 | |
| if arm.startswith('paper'): | |
| passed, tokens, calls = value['clean_pass'], value['tokens_in'] + value['tokens_out'], value['llm_calls'] | |
| elif arm.startswith('native'): | |
| passed, tokens, calls = value['status'] == 'pass', value['usage']['total_tokens'], value['usage']['model_responses'] | |
| else: | |
| passed, tokens, calls = value['grade']['status'] == 'pass', value['tokens']['total_tokens'], value['api_calls'] | |
| totals['passed'] += int(passed) | |
| totals['total_tokens'] += tokens | |
| totals['model_calls'] += calls | |
| archive_totals[arm] = totals | |
| assert seen == set(expected_members) | |
| rows = [json.loads(line) for line in (release / 'results.jsonl').read_text().splitlines()] | |
| assert len(rows) == len({(r['arm'], r['task']) for r in rows}) == 588 | |
| summary = json.loads((release / 'summary.json').read_text()) | |
| tasks = set(json.loads((release / 'tasks/selected-task-ids.json').read_text())) | |
| assert len(tasks) == 98 | |
| assert {json.loads(line)['tid'] for line in (release / 'tasks/tasks.jsonl').read_text().splitlines()} == tasks | |
| for arm, expected in summary['groups'].items(): | |
| group = [r for r in rows if r['arm'] == arm] | |
| assert len(group) == 98 and {r['task'] for r in group} == tasks | |
| assert all(r['total_tokens'] == r['input_tokens'] + r['output_tokens'] for r in group) | |
| totals = {'n': len(group), 'passed': sum(r['status'] == 'pass' for r in group), | |
| 'total_tokens': sum(r['total_tokens'] for r in group), 'model_calls': sum(r['api_calls'] for r in group)} | |
| assert totals == dict(archive_totals[arm]), arm | |
| assert all(expected[k] == v for k, v in totals.items()), arm | |
| class Links(HTMLParser): | |
| def __init__(self): | |
| super().__init__() | |
| self.hrefs, self.ids = [], set() | |
| def handle_starttag(self, tag, attrs): | |
| a = dict(attrs) | |
| if 'id' in a: | |
| self.ids.add(a['id']) | |
| if tag == 'a' and 'href' in a: | |
| self.hrefs.append(a['href']) | |
| for path in release.glob('*.html'): | |
| parsed = Links() | |
| parsed.feed(path.read_text()) | |
| for href in parsed.hrefs: | |
| if href.startswith('#'): | |
| assert href[1:] in parsed.ids, href | |
| elif not href.startswith(('http:', 'https:')): | |
| assert (path.parent / href.split('#')[0]).exists(), href | |
| print(json.dumps({'verified_files': len(checksums), 'verified_archive_members': len(seen), | |
| 'episodes': len(rows), 'groups': archive_totals, 'status': 'PASS'}, indent=2)) | |
| if __name__ == '__main__': | |
| main() | |