RoboRACE-Bench / kaggle /replicate /replicate.py
Nabidnur's picture
RoboRACE: code, cached agent outputs, results, media, SO-101 renders (part 8)
f5c9954 verified
Raw History Blame Contribute Delete
3.21 kB
# RoboRACE: independent replication on Kaggle CPU.
# Pulls code + cached agent outputs from the public Hugging Face dataset, runs the test-suite, and recomputes
# the whole leaderboard from scratch (no reuse of saved per-cell rows).
import json, os, platform, shutil, subprocess, sys, time
def sh(cmd, check=True):
print("$", cmd, flush=True)
return subprocess.run(cmd, shell=True, check=check)
info = {"platform": platform.platform(), "cpus": os.cpu_count(), "python": sys.version.split()[0]}
info["cpu_model"] = subprocess.run("grep -m1 'model name' /proc/cpuinfo | cut -d: -f2", shell=True, capture_output=True, text=True).stdout.strip()
print(info, flush=True)
sh(f"{sys.executable} -m pip install -q crowd-kit==1.4.2 mujoco pytest safetensors")
from huggingface_hub import snapshot_download
root = snapshot_download("Nabidnur/RoboRACE-Bench", repo_type="dataset", local_dir="/kaggle/working/robotics",
allow_patterns=["src/**", "scripts/**", "tests/**", "results/**", "models/**", "pyproject.toml", "requirements.txt"])
os.chdir(root)
published = json.load(open("results/leaderboard.json"))
os.environ["MUJOCO_GL"] = "egl"
t = time.time()
r = subprocess.run(f"{sys.executable} -m pytest -q -p no:cacheprovider tests 2>&1 | tail -3", shell=True, capture_output=True, text=True)
info["pytest"] = r.stdout.strip().splitlines()[-1] if r.stdout.strip() else "no output"
print("pytest:", info["pytest"], flush=True)
for d in ("so101", "panda", "trackA", "so101_holdout", "panda_holdout", "trackB", "trackD"): # force a full recomputation
p = f"results/{d}/rows.json"
if os.path.exists(p):
os.remove(p)
sh(f"{sys.executable} scripts/run_benchmark.py > /kaggle/working/run_benchmark.log 2>&1")
info["benchmark_minutes"] = round((time.time() - t) / 60, 1)
mine = json.load(open("results/leaderboard.json"))
def leaves(x, path=""):
if isinstance(x, dict):
for k, v in x.items():
yield from leaves(v, f"{path}/{k}")
elif isinstance(x, list):
for i, v in enumerate(x):
key = v.get("method", v.get("system", v.get("agent", i))) if isinstance(v, dict) else i
yield from leaves(v, f"{path}[{key}]")
elif isinstance(x, (int, float)) and not isinstance(x, bool):
yield path, float(x)
a, b = dict(leaves(published)), dict(leaves(mine))
common = [k for k in a if k in b and a[k] == a[k] and b[k] == b[k]]
diffs = sorted(((abs(a[k] - b[k]), k) for k in common), reverse=True)
info.update(n_values=len(common), n_only_published=len(set(a) - set(b)), n_only_kaggle=len(set(b) - set(a)),
max_abs_diff=diffs[0][0] if diffs else None, n_diff_gt_1e_3=sum(d > 1e-3 for d, _ in diffs),
largest=[{"key": k, "published": a[k], "kaggle": b[k]} for d, k in diffs[:10]])
info["cpu"] = f"{info['cpus']} vCPU, {info['cpu_model']}"
info["tests"] = info["pytest"]
print(json.dumps(info, indent=1), flush=True)
json.dump(info, open("/kaggle/working/replication.json", "w"), indent=1)
shutil.copy("results/leaderboard.json", "/kaggle/working/leaderboard_kaggle.json")
shutil.copy("results/LEADERBOARD.md", "/kaggle/working/LEADERBOARD_kaggle.md")
shutil.rmtree("/kaggle/working/robotics")