Datasets:
Download source/tools/watch.py from Syndicate604/science-desk: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/datasets/Syndicate604/science-desk/resolve/main/source/tools/watch.py
- Command line
-
hf download hf://datasets/Syndicate604/science-desk/source/tools/watch.py
-
curl -L -o watch.py https://huggingface.co/datasets/Syndicate604/science-desk/resolve/main/source/tools/watch.py
1.82 kB
| """Poll the submission and its run once a minute; print one line per state change. Exits on a terminal run state or rejection.""" | |
| import json | |
| import sys | |
| import time | |
| sys.path.insert(0, "tools") | |
| import httpx # noqa: E402 | |
| from orkey import env_key # noqa: E402 | |
| BASE = "https://openenvarena-arena.hf.space/api/openenv" | |
| H = {"Authorization": "Bearer " + env_key("HF_TOKEN")} | |
| sid = sys.argv[1] | |
| last = None | |
| while True: | |
| try: | |
| s = httpx.get(f"{BASE}/submissions/{sid}", headers=H, timeout=60).json() | |
| run = s.get("run") or {} | |
| line = f"submission={s.get('state')} slot={(s.get('slot') or {}).get('state')} errors={s.get('report', {}).get('errors')} origin={s.get('error_origin')} run={run.get('run_id')}" | |
| if run.get("run_id"): | |
| r = httpx.get(f"{BASE}/runs/{run['run_id']}", headers=H, timeout=60).json() | |
| state = "training" if r.get("state") in ("rolling", "updating") else r.get("state") | |
| line += f" run_state={state}" | |
| step = r.get("policy_version") or 0 | |
| if r.get("state") in ("completed", "failed", "cancelled"): | |
| print(line, flush=True) | |
| print("DASHBOARD", run.get("dashboard"), flush=True) | |
| break | |
| if line != last: | |
| print(line, flush=True) | |
| last = line | |
| if run.get("run_id") and step // 50 > globals().get("_bucket", 0): | |
| globals()["_bucket"] = step // 50 | |
| print(f"step {step}", flush=True) | |
| if s.get("state") == "rejected": | |
| print("REJECTED", json.dumps(s.get("report", {}).get("error_details"))[:800], flush=True) | |
| break | |
| except Exception as exc: # transient proxy 502/503/504: the guide says retry unchanged | |
| print(f"poll error {type(exc).__name__}", flush=True) | |
| time.sleep(60) | |