Download run_suite.py from vanshnawander/structured-diffusion-eval: direct link, hf CLI and curl.
- Browser
- Download file 4.83 kB
-
https://huggingface.co/datasets/vanshnawander/structured-diffusion-eval/resolve/main/run_suite.py
- Command line
-
hf download hf://datasets/vanshnawander/structured-diffusion-eval/run_suite.py
-
curl -L -o run_suite.py https://huggingface.co/datasets/vanshnawander/structured-diffusion-eval/resolve/main/run_suite.py
4.83 kB
| """Run disjoint checkpoint/task assignments on Kaggle, Colab, or another GPU.""" | |
| import argparse | |
| from dataclasses import asdict | |
| import hashlib | |
| import json | |
| import os | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| import time | |
| from runner import DiffusionEvalConfig, evaluation_units, write_json | |
| def assignments(catalog, worker_index=0, num_workers=1, tasks=None, run_ppl=True): | |
| if num_workers < 1 or not 0 <= worker_index < num_workers: | |
| raise ValueError("Require 0 <= worker-index < num-workers") | |
| cfg = DiffusionEvalConfig() | |
| cfg.skip_ppl = not run_ppl | |
| work = [] | |
| for item in catalog: | |
| if not item.get("ready", True): | |
| continue | |
| family = "dream" if item.get("model", "").startswith("Dream-org/") or "structured-dream-" in item["repo_id"] else "llada" | |
| work.extend({"repo_id": item["repo_id"], "revision": item.get("revision"), | |
| "unit": unit, "family": family} | |
| for unit in evaluation_units(cfg, family, selected_tasks=tasks)) | |
| return work[worker_index::num_workers] | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--catalog", default=str(Path(__file__).with_name("models.json"))) | |
| parser.add_argument("--repos", nargs="+", help="Select one or more original or fine-tuned public repositories") | |
| parser.add_argument("--worker-index", type=int, default=0) | |
| parser.add_argument("--num-workers", type=int, default=1) | |
| parser.add_argument("--tasks", nargs="+") | |
| parser.add_argument("--skip-ppl", action="store_true") | |
| parser.add_argument("--plan", action="store_true") | |
| parser.add_argument("--batch-size", type=int) | |
| parser.add_argument("--dtype", choices=["auto", "bfloat16", "float16", "float32"]) | |
| parser.add_argument("--device", default="cuda") | |
| parser.add_argument("--device-map", choices=["auto", "single"], default="auto") | |
| parser.add_argument("--gpu-memory-ratio", type=float, default=.65) | |
| parser.add_argument("--output", default="results") | |
| parser.add_argument("--cache-dir", default=".eval_cache") | |
| parser.add_argument("--offload-dir", default=".eval_offload") | |
| parser.add_argument("--time-budget-seconds", type=float, default=8*3600) | |
| parser.add_argument("--request-chunk-size", type=int, default=1) | |
| parser.add_argument("--require-finetuned-slice", action="store_true") | |
| args = parser.parse_args() | |
| catalog = json.loads(Path(args.catalog).read_text()) | |
| if args.repos: | |
| selected = {r["repo_id"]: r for r in catalog} | |
| catalog = [selected.get(repo, {"repo_id": repo, "ready": True}) for repo in args.repos] | |
| work = assignments(catalog, args.worker_index, args.num_workers, args.tasks, not args.skip_ppl) | |
| if args.plan: | |
| print(json.dumps({"assignments": work, "units": len(work), | |
| "shared_config": asdict(DiffusionEvalConfig())}, indent=2)) | |
| return | |
| deadline = time.monotonic() + args.time_budget_seconds | |
| grouped = {} | |
| for item in work: | |
| grouped.setdefault((item["repo_id"], item["revision"]), []).append(item["unit"]) | |
| status = {"worker_index": args.worker_index, "num_workers": args.num_workers, | |
| "assigned_units": len(work), "models_attempted": [], "errors": []} | |
| runner = str(Path(__file__).with_name("runner.py")) | |
| for (repo, revision), units in grouped.items(): | |
| remaining = deadline - time.monotonic() | |
| if remaining <= 0: | |
| break | |
| cmd = [sys.executable, runner, "--repo", repo, "--units", *units, | |
| "--device", args.device, "--device-map", args.device_map, | |
| "--gpu-memory-ratio", str(args.gpu_memory_ratio), "--output", args.output, | |
| "--cache-dir", args.cache_dir, "--offload-dir", args.offload_dir, | |
| "--time-budget-seconds", str(remaining), "--request-chunk-size", str(args.request_chunk_size)] | |
| if revision: | |
| cmd += ["--revision", revision] | |
| if args.batch_size is not None: | |
| cmd += ["--batch-size", str(args.batch_size)] | |
| if args.dtype: | |
| cmd += ["--dtype", args.dtype] | |
| if args.skip_ppl: | |
| cmd += ["--skip-ppl"] | |
| if args.require_finetuned_slice: | |
| cmd += ["--require-finetuned-slice"] | |
| status["models_attempted"].append(repo) | |
| write_json(Path(args.output) / ("worker_" + str(args.worker_index) + "_status.json"), status) | |
| result = subprocess.run(cmd) | |
| if result.returncode: | |
| status["errors"].append({"repo_id": repo, "exit_code": result.returncode}) | |
| break | |
| write_json(Path(args.output) / ("worker_" + str(args.worker_index) + "_status.json"), status) | |
| if status["errors"]: | |
| raise SystemExit(status["errors"][-1]["exit_code"]) | |
| if __name__ == "__main__": | |
| main() | |