Datasets:
Download leaderboard/check_coverage.py from MLL-Lab/embodied-exam-data: direct link, hf CLI and curl.
- Browser
- Download file 3 kB
-
https://huggingface.co/datasets/MLL-Lab/embodied-exam-data/resolve/main/leaderboard/check_coverage.py
- Command line
-
hf download hf://datasets/MLL-Lab/embodied-exam-data/leaderboard/check_coverage.py
-
curl -L -o check_coverage.py https://huggingface.co/datasets/MLL-Lab/embodied-exam-data/resolve/main/leaderboard/check_coverage.py
3 kB
| """Check that every counted leaderboard attempt has its run on HF (works without a token). | |
| usage: python3 check_coverage.py [trials.csv] [--revision REV] | |
| For each row of trials.csv (one row per counted attempt), it checks in the dataset MLL-Lab/embodied-exam-runs: | |
| - runs/<h2>/<slug>/run.json and trajectory.jsonl.gz exist, and replay.mp4 exists when has_video = 1; | |
| - the slug has a row in index/<suite>.json whose run and outcome equal the leaderboard's. | |
| It lists the runs/<h2>/ folders through the HF API (at most 256 calls) and reads the index files. Without a token, | |
| HF's rate limit may make it wait a few minutes; with HF_TOKEN set it runs in about a minute. | |
| Exit status 0 only at 100% coverage. | |
| """ | |
| import argparse, collections, csv, hashlib, json, sys, time, urllib.request | |
| from huggingface_hub import HfApi | |
| REPO = 'MLL-Lab/embodied-exam-runs' | |
| ap = argparse.ArgumentParser(); ap.add_argument('trials', nargs='?', default='trials.csv'); ap.add_argument('--revision', default='main') | |
| a = ap.parse_args() | |
| api = HfApi() | |
| rev = api.dataset_info(REPO, revision=a.revision).sha | |
| rows = list(csv.DictReader(open(a.trials))) | |
| h2 = lambda s: hashlib.sha1(s.encode()).hexdigest()[:2] | |
| files = set() | |
| def tree(d): # anonymous calls are rate limited (a few hundred per 5 min): wait and retry | |
| for k in range(20): | |
| try: | |
| return [e.path for e in api.list_repo_tree(REPO, path_in_repo=f'runs/{d}', recursive=True, repo_type='dataset', revision=rev)] | |
| except Exception as e: | |
| if '429' not in str(e) and 'rate limit' not in str(e).lower() or k == 19: raise | |
| print('rate limited, waiting 60 s', file=sys.stderr, flush=True); time.sleep(60) | |
| for d in sorted({h2(r['hf_slug']) for r in rows}): | |
| files.update(tree(d)) | |
| def get(path): # plain urllib: no compressed transfer | |
| return json.loads(urllib.request.urlopen(f'https://huggingface.co/datasets/{REPO}/resolve/{rev}/{path}', timeout=300).read()) | |
| idx = get('index.json') | |
| irow = {} | |
| for s in idx['suites']: | |
| for x in get(f'index/{s}.json')['runs']: | |
| irow[x['slug']] = x | |
| c = collections.Counter(); bad = [] | |
| for r in rows: | |
| s = r['hf_slug']; base = f'runs/{h2(s)}/{s}/' | |
| need = ['run.json', 'trajectory.jsonl.gz'] + (['replay.mp4'] if r['has_video'] == '1' else []) | |
| miss = [f for f in need if base + f not in files] | |
| x = irow.get(s) | |
| ok_idx = bool(x) and x['run'] == r['run_id'] and ((x.get('success') == 1 or x.get('state') == 'success') == (r['verdict'] == 'success')) | |
| if miss or not ok_idx: | |
| bad.append((r['run_id'], r['task_dir'], s, miss, 'index ok' if ok_idx else ('index outcome differs' if x else 'not in index'))) | |
| else: | |
| c['covered'] += 1 | |
| c['with video'] += r['has_video'] == '1' | |
| print(f'{REPO}@{rev[:10]}: {c["covered"]} of {len(rows)} counted attempts covered ' | |
| f'(run.json + trajectory + index row with the same outcome; replay.mp4 for the {c["with video"]} with a video)') | |
| for b in bad: print('MISSING', *b) | |
| sys.exit(0 if not bad else 1) | |