Download tools/run_cycle_offline.py from adamm-hf/P-NP: direct link, hf CLI and curl.
- Browser
- Download file 2.39 kB
-
https://huggingface.co/spaces/adamm-hf/P-NP/resolve/main/tools/run_cycle_offline.py
- Command line
-
hf download hf://spaces/adamm-hf/P-NP/tools/run_cycle_offline.py
-
curl -L -o run_cycle_offline.py https://huggingface.co/spaces/adamm-hf/P-NP/resolve/main/tools/run_cycle_offline.py
2.39 kB
| """Run one full cycle offline with canned model replies (no HF_TOKEN needed). | |
| python tools/run_cycle_offline.py # one cycle into a temp root, print the record | |
| python tools/run_cycle_offline.py --serve # then serve the dashboard on :7860 | |
| python tools/run_cycle_offline.py --root /tmp/pnp-demo --cycles 3 | |
| Useful to see the dashboard with data before spending a cent. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import os | |
| import sys | |
| import tempfile | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| sys.path.insert(0, str(ROOT / "src")) | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--root", default="") | |
| parser.add_argument("--cycles", type=int, default=1) | |
| parser.add_argument("--serve", action="store_true") | |
| parser.add_argument("--disagree", action="store_true", help="make the replica disagree (DISCREPANCY path)") | |
| args = parser.parse_args() | |
| root = args.root or tempfile.mkdtemp(prefix="pnp-lab-v2-") | |
| os.environ["PERSISTENT_ROOT"] = root | |
| os.environ.setdefault("HF_TOKEN", "offline-fake-token") | |
| os.environ["AUTO_START"] = "false" | |
| from pnp_lab.config import Settings | |
| from pnp_lab.fakes import fake_replies | |
| from pnp_lab.models import FakeModelClient | |
| from pnp_lab.orchestrator import Lab | |
| settings = Settings() | |
| client = FakeModelClient(settings, fake_replies(replica_disagree=args.disagree)) | |
| lab = Lab(settings, client=client) | |
| for _ in range(args.cycles): | |
| client.replies = fake_replies(replica_disagree=args.disagree) | |
| record = lab.runner.run(lab.state()) | |
| lab.refresh_mirrors() | |
| print(json.dumps({k: record.get(k) for k in ("cycle_id", "verdict", "result_id", "one_line", "replication_agree", "instances_verified", "seconds", "overrides")}, indent=2)) | |
| metrics = lab.snapshot()["metrics"] | |
| print("score:", metrics["score"], "banked:", metrics["banked"], "instances:", metrics["instances_verified"]) | |
| print("persistent root:", root) | |
| if args.serve: | |
| from pnp_lab.dashboard import build_dashboard | |
| demo, css = build_dashboard(lab) | |
| demo.queue().launch(server_name="0.0.0.0", server_port=int(os.getenv("PORT", "7860")), css=css, | |
| allowed_paths=[str(settings.exports_dir.resolve())]) | |
| if __name__ == "__main__": | |
| main() | |