Download scripts/check_bench2drive_complete.py from ZenoNing/ConsDrive: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/ZenoNing/ConsDrive/resolve/main/scripts/check_bench2drive_complete.py
- Command line
-
hf download hf://ZenoNing/ConsDrive/scripts/check_bench2drive_complete.py
-
curl -L -o check_bench2drive_complete.py https://huggingface.co/ZenoNing/ConsDrive/resolve/main/scripts/check_bench2drive_complete.py
1.73 kB
| #!/usr/bin/env python3 | |
| """Return 0 when all Bench2Drive worker checkpoints in a result root are finished.""" | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| def load_json(path: Path): | |
| try: | |
| with open(path, encoding="utf-8") as handle: | |
| return json.load(handle) | |
| except (OSError, json.JSONDecodeError): | |
| return None | |
| def main() -> int: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("result_root", type=Path) | |
| parser.add_argument( | |
| "--workers", | |
| type=int, | |
| default=8, | |
| help="Expected number of bench2drive220_worker_*.json files.", | |
| ) | |
| args = parser.parse_args() | |
| result_root = args.result_root.expanduser().resolve() | |
| worker_files = sorted(result_root.glob("bench2drive220_worker_*.json")) | |
| if len(worker_files) < args.workers: | |
| print( | |
| f"waiting: found {len(worker_files)}/{args.workers} worker checkpoints", | |
| file=sys.stderr, | |
| ) | |
| return 1 | |
| total_records = 0 | |
| for worker_file in worker_files: | |
| data = load_json(worker_file) | |
| if not isinstance(data, dict): | |
| print(f"waiting: invalid checkpoint {worker_file.name}", file=sys.stderr) | |
| return 1 | |
| if data.get("entry_status") != "Finished": | |
| print( | |
| f"waiting: {worker_file.name} entry_status={data.get('entry_status')}", | |
| file=sys.stderr, | |
| ) | |
| return 1 | |
| records = data.get("_checkpoint", {}).get("records", []) | |
| total_records += len(records) | |
| print(f"complete: {len(worker_files)} workers, {total_records} route records") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |