Download scripts/summarize_task0_baseline.py from myx160/rl-post-train-artifacts: direct link, hf CLI and curl.
- Browser
- Download file 4.84 kB
-
https://huggingface.co/datasets/myx160/rl-post-train-artifacts/resolve/main/scripts/summarize_task0_baseline.py
- Command line
-
hf download hf://datasets/myx160/rl-post-train-artifacts/scripts/summarize_task0_baseline.py
-
curl -L -o summarize_task0_baseline.py https://huggingface.co/datasets/myx160/rl-post-train-artifacts/resolve/main/scripts/summarize_task0_baseline.py
4.84 kB
| #!/usr/bin/env python | |
| """Build stable Task 0 baseline manifest and summary files.""" | |
| from __future__ import annotations | |
| import argparse | |
| import csv | |
| import json | |
| import sys | |
| from pathlib import Path | |
| SCRIPT_DIR = Path(__file__).resolve().parent | |
| if str(SCRIPT_DIR) not in sys.path: | |
| sys.path.insert(0, str(SCRIPT_DIR)) | |
| from task0_baseline_common import ( # noqa: E402 | |
| expected_keys, | |
| load_config, | |
| load_episode_records, | |
| parse_int_spec, | |
| protocol_hash, | |
| require_project_path, | |
| summarize_records, | |
| write_resolved_config, | |
| ) | |
| def _args() -> argparse.Namespace: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--input-dir", type=Path, required=True) | |
| parser.add_argument( | |
| "--config", | |
| type=Path, | |
| default=Path("configs/baseline/libero10_task0_pi05_sft_formal.yaml"), | |
| ) | |
| parser.add_argument("--seeds", default=None, help="Override expected seeds, e.g. 0,1") | |
| parser.add_argument("--trial-ids", default=None, help="Override expected trials, e.g. 0-49") | |
| return parser.parse_args() | |
| def _write_manifest(path: Path, records: list[dict]) -> None: | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| with path.open("w", encoding="utf-8") as handle: | |
| for record in sorted(records, key=lambda item: (item["policy_seed"], item["trial_id"])): | |
| handle.write(json.dumps(record, ensure_ascii=False, sort_keys=True)) | |
| handle.write("\n") | |
| def _write_csv(path: Path, summary: dict) -> None: | |
| rows = [ | |
| { | |
| "scope": "overall", | |
| "policy_seed": "", | |
| "planned": summary["planned_episode_count"], | |
| "completed": summary["completed_episode_count"], | |
| "errors": summary["error_episode_count"], | |
| "success_count": summary["success_count"], | |
| "failure_count": summary["failure_count"], | |
| "success_rate": summary["success_rate"], | |
| "wilson_95ci_low": summary["wilson_95ci"][0], | |
| "wilson_95ci_high": summary["wilson_95ci"][1], | |
| } | |
| ] | |
| for seed, values in sorted(summary["per_policy_seed"].items(), key=lambda item: int(item[0])): | |
| rows.append( | |
| { | |
| "scope": "policy_seed", | |
| "policy_seed": seed, | |
| "planned": values["planned"], | |
| "completed": values["completed"], | |
| "errors": values["error_count"], | |
| "success_count": values["success_count"], | |
| "failure_count": values["failure_count"], | |
| "success_rate": values["success_rate"], | |
| "wilson_95ci_low": values["wilson_95ci"][0], | |
| "wilson_95ci_high": values["wilson_95ci"][1], | |
| } | |
| ) | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| with path.open("w", encoding="utf-8", newline="") as handle: | |
| writer = csv.DictWriter(handle, fieldnames=list(rows[0])) | |
| writer.writeheader() | |
| writer.writerows(rows) | |
| def main() -> int: | |
| args = _args() | |
| root = require_project_path(args.input_dir, label="result directory") | |
| cfg = load_config(args.config) | |
| cfg_hash = protocol_hash(cfg) | |
| configured_seeds = [int(seed) for seed in cfg.policy_seeds] | |
| configured_trials = [int(trial) for trial in cfg.trial_ids] | |
| seeds = parse_int_spec(args.seeds, label="seeds") if args.seeds else configured_seeds | |
| trials = parse_int_spec(args.trial_ids, label="trial ids") if args.trial_ids else configured_trials | |
| records = load_episode_records(root, expected_protocol_hash=cfg_hash) | |
| summary = summarize_records( | |
| records, | |
| expected=expected_keys(seeds, trials), | |
| protocol_version=str(cfg.protocol_version), | |
| protocol_sha256=cfg_hash, | |
| ) | |
| summary["checkpoint_repo"] = str(cfg.model.checkpoint_repo) | |
| summary["checkpoint_revision"] = str(cfg.model.checkpoint_revision) | |
| summary["checkpoint_weight_sha256"] = str(cfg.model.checkpoint_weight_sha256) | |
| summary["source_commits"] = { | |
| "rlinf": "0505431899574619da86f551bad70b71e0ea2177", | |
| "openpi": "c5dc4b9296a1a4739bf52828f28a579f12dce763", | |
| "libero": "0c5e40cc4ae63e09c14e7df6f74481e9ee8585f7", | |
| } | |
| summary["expected_policy_seeds"] = seeds | |
| summary["expected_trial_ids"] = trials | |
| _write_manifest(root / "episode_manifest.jsonl", records) | |
| root.mkdir(parents=True, exist_ok=True) | |
| (root / "summary.json").write_text( | |
| json.dumps(summary, ensure_ascii=False, indent=2, sort_keys=True) + "\n", | |
| encoding="utf-8", | |
| ) | |
| _write_csv(root / "summary.csv", summary) | |
| write_resolved_config(root / "resolved_config.yaml", cfg) | |
| (root / "protocol.sha256").write_text(cfg_hash + "\n", encoding="utf-8") | |
| print(json.dumps(summary, ensure_ascii=False, sort_keys=True)) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |