Download code/gke/fetch_artifacts.py from EdwardoSunny/agent-cwm-rubrics-debug: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/datasets/EdwardoSunny/agent-cwm-rubrics-debug/resolve/main/code/gke/fetch_artifacts.py
- Command line
-
hf download hf://datasets/EdwardoSunny/agent-cwm-rubrics-debug/code/gke/fetch_artifacts.py
-
curl -L -o fetch_artifacts.py https://huggingface.co/datasets/EdwardoSunny/agent-cwm-rubrics-debug/resolve/main/code/gke/fetch_artifacts.py
2.33 kB
| #!/usr/bin/env python3 | |
| """Download cmd-shard artifacts from GCS, preserving their repo-relative paths. | |
| gke/.venv/bin/python gke/fetch_artifacts.py --run tgt10-dog-breed-identification | |
| gke/.venv/bin/python gke/fetch_artifacts.py --prefix tgt10- # every matching run | |
| `submit_eval.py collect` concatenates every *.jsonl under a run into one file, | |
| which is right for eval rows and wrong for cmd artifacts: a collection run | |
| uploads tgt_<comp>.jsonl AND its summary sidecars, and a pool run uploads both | |
| the raw states and the scored states — merging those duplicates every row. | |
| This keeps each artifact as the file the pod wrote it as. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| from pathlib import Path | |
| from google.cloud import storage | |
| from settings import BUCKET, PROJECT | |
| REPO = Path(__file__).resolve().parent.parent | |
| def main() -> int: | |
| ap = argparse.ArgumentParser(description=__doc__) | |
| ap.add_argument("--run", action="append", default=[]) | |
| ap.add_argument("--prefix", default="", | |
| help="fetch every run whose name starts with this") | |
| ap.add_argument("--dest", default=str(REPO), | |
| help="artifact paths are repo-relative; default writes " | |
| "them into the repo tree") | |
| args = ap.parse_args() | |
| client = storage.Client(project=PROJECT) | |
| bucket = client.bucket(BUCKET) | |
| runs = list(args.run) | |
| if args.prefix: | |
| seen = set() | |
| for bl in client.list_blobs(BUCKET, prefix="runs/"): | |
| name = bl.name.split("/")[1] | |
| if name.startswith(args.prefix): | |
| seen.add(name) | |
| runs += sorted(seen - set(runs)) | |
| if not runs: | |
| raise SystemExit("nothing to fetch: pass --run or --prefix") | |
| n = 0 | |
| for run in runs: | |
| for bl in client.list_blobs(BUCKET, prefix=f"runs/{run}/shards/"): | |
| if "-artifacts/" not in bl.name: | |
| continue | |
| rel = bl.name.split("-artifacts/", 1)[1] | |
| dest = Path(args.dest) / rel | |
| dest.parent.mkdir(parents=True, exist_ok=True) | |
| bl.download_to_filename(dest) | |
| print(f"[{run}] {rel} ({(bl.size or 0)/1e6:.1f} MB)") | |
| n += 1 | |
| print(f"{n} artifacts from {len(runs)} runs") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |