Download mindxtrain/eval/inspect_ai_adapter.py from PYTHAI/mindXtrain: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/PYTHAI/mindXtrain/resolve/main/mindxtrain/eval/inspect_ai_adapter.py
- Command line
-
hf download hf://PYTHAI/mindXtrain/mindxtrain/eval/inspect_ai_adapter.py
-
curl -L -o inspect_ai_adapter.py https://huggingface.co/PYTHAI/mindXtrain/resolve/main/mindxtrain/eval/inspect_ai_adapter.py
1.42 kB
| """Inspect-AI adapter — agentic evaluations. | |
| Subprocess `inspect eval`; emits per-task JSON under `out_dir`. | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import shutil | |
| import subprocess | |
| from pathlib import Path | |
| def _inspect_available() -> bool: | |
| return shutil.which("inspect") is not None | |
| def run_inspect( | |
| checkpoint: Path, | |
| tasks: list[str], | |
| *, | |
| out_dir: Path | None = None, | |
| ) -> dict[str, float]: | |
| """Run an inspect-ai task suite; return summary metrics.""" | |
| if not _inspect_available(): | |
| msg = "inspect-ai not installed; run `uv sync --extra eval`." | |
| raise RuntimeError(msg) | |
| out_dir = Path(out_dir or checkpoint / "inspect") | |
| out_dir.mkdir(parents=True, exist_ok=True) | |
| cmd = [ | |
| "inspect", | |
| "eval", | |
| *tasks, | |
| "--model", | |
| f"hf/{checkpoint}", | |
| "--log-dir", | |
| str(out_dir), | |
| ] | |
| subprocess.run(cmd, check=True) | |
| out: dict[str, float] = {} | |
| for p in sorted(out_dir.glob("**/*.json")): | |
| try: | |
| raw = json.loads(p.read_text()) | |
| except (OSError, json.JSONDecodeError): | |
| continue | |
| scores = raw.get("results", {}).get("scores", {}) | |
| for k, v in scores.items(): | |
| if isinstance(v, dict) and "value" in v and isinstance(v["value"], int | float): | |
| out[f"{p.stem}/{k}"] = float(v["value"]) | |
| return out | |
| __all__ = ["run_inspect"] | |