eac123 commited on
Commit
cc18230
·
verified ·
1 Parent(s): be78ac8

run_eval now uploads eval JSONs to the Hub; stage_eval recovery covers ckpts/

Browse files
Files changed (1) hide show
  1. run_all.py +19 -13
run_all.py CHANGED
@@ -25,10 +25,20 @@ def run(cmd):
25
  subprocess.run(cmd, check=True)
26
 
27
 
28
- def run_eval(ckpt, out_dir="results"):
29
- """Run evaluate.py on one checkpoint and upload the JSON to the Hub
30
- (evaluate.py reads HUB_REPO from the environment, set in main())."""
 
 
 
 
31
  run([sys.executable, "evaluate.py", "--ckpt", ckpt, "--out-dir", out_dir])
 
 
 
 
 
 
32
 
33
 
34
  def train_cmd(a, run_name, steps, lr, hub_repo):
@@ -90,8 +100,7 @@ def stage1(args):
90
  continue
91
  run(train_cmd({"arch": arch, "depth": depth, "iters": iters,
92
  "seed": s}, name, STEPS, lr, args.hub_repo))
93
- run([sys.executable, "evaluate.py", "--ckpt", ck,
94
- "--out-dir", "results"])
95
 
96
 
97
  def stage2(args):
@@ -101,15 +110,13 @@ def stage2(args):
101
  if not os.path.exists(f"out/{name}.pt"):
102
  run(train_cmd({"arch": "rec", "depth": 4, "iters": "4",
103
  "seed": s}, name, STEPS, lr, args.hub_repo))
104
- run([sys.executable, "evaluate.py", "--ckpt", f"out/{name}.pt",
105
- "--out-dir", "results"])
106
  for s in (0, 1):
107
  name = f"fixed4-long-seed{s}"
108
  if not os.path.exists(f"out/{name}.pt"):
109
  run(train_cmd({"arch": "fixed", "depth": 4, "iters": "1",
110
  "seed": s}, name, 4 * STEPS, lr, args.hub_repo))
111
- run([sys.executable, "evaluate.py", "--ckpt", f"out/{name}.pt",
112
- "--out-dir", "results"])
113
 
114
 
115
  def stage_eval(args):
@@ -118,12 +125,12 @@ def stage_eval(args):
118
  from huggingface_hub import snapshot_download
119
  snapshot_download(repo_id=args.hub_repo, repo_type="model",
120
  allow_patterns=["ckpts/*.pt"], local_dir=".")
121
- for ck in sorted(glob.glob("out/*.pt")):
 
122
  name = os.path.splitext(os.path.basename(ck))[0]
123
  if os.path.exists(f"results/{name}_eval.json"):
124
  continue
125
- run([sys.executable, "evaluate.py", "--ckpt", ck,
126
- "--out-dir", "results"])
127
 
128
 
129
  def main():
@@ -132,7 +139,6 @@ def main():
132
  p.add_argument("--hub-repo", default=None)
133
  a = p.parse_args()
134
  if a.hub_repo:
135
- os.environ["HUB_REPO"] = a.hub_repo # evaluate.py uploads when set
136
  os.environ.setdefault("TRACKIO_HUB_REPO", a.hub_repo)
137
  {"lrsweep": stage_lrsweep, "stage1": stage1, "stage2": stage2,
138
  "eval": stage_eval}[a.stage](a)
 
25
  subprocess.run(cmd, check=True)
26
 
27
 
28
+ def run_eval(args, ckpt, out_dir="results"):
29
+ """Run evaluate.py on one checkpoint, then upload the JSON to the Hub.
30
+ Without the upload the eval JSONs die with the job's ephemeral disk."""
31
+ name = os.path.splitext(os.path.basename(ckpt))[0]
32
+ out = f"{out_dir}/{name}_eval.json"
33
+ if os.path.exists(out):
34
+ return
35
  run([sys.executable, "evaluate.py", "--ckpt", ckpt, "--out-dir", out_dir])
36
+ if args.hub_repo:
37
+ run([sys.executable, "-c",
38
+ f"from huggingface_hub import HfApi; HfApi().upload_file("
39
+ f"path_or_fileobj={out!r}, "
40
+ f"path_in_repo='results/{name}_eval.json', "
41
+ f"repo_id='{args.hub_repo}', repo_type='model')"])
42
 
43
 
44
  def train_cmd(a, run_name, steps, lr, hub_repo):
 
100
  continue
101
  run(train_cmd({"arch": arch, "depth": depth, "iters": iters,
102
  "seed": s}, name, STEPS, lr, args.hub_repo))
103
+ run_eval(args, ck)
 
104
 
105
 
106
  def stage2(args):
 
110
  if not os.path.exists(f"out/{name}.pt"):
111
  run(train_cmd({"arch": "rec", "depth": 4, "iters": "4",
112
  "seed": s}, name, STEPS, lr, args.hub_repo))
113
+ run_eval(args, f"out/{name}.pt")
 
114
  for s in (0, 1):
115
  name = f"fixed4-long-seed{s}"
116
  if not os.path.exists(f"out/{name}.pt"):
117
  run(train_cmd({"arch": "fixed", "depth": 4, "iters": "1",
118
  "seed": s}, name, 4 * STEPS, lr, args.hub_repo))
119
+ run_eval(args, f"out/{name}.pt")
 
120
 
121
 
122
  def stage_eval(args):
 
125
  from huggingface_hub import snapshot_download
126
  snapshot_download(repo_id=args.hub_repo, repo_type="model",
127
  allow_patterns=["ckpts/*.pt"], local_dir=".")
128
+ cks = sorted(glob.glob("out/*.pt") + glob.glob("ckpts/*.pt"))
129
+ for ck in cks:
130
  name = os.path.splitext(os.path.basename(ck))[0]
131
  if os.path.exists(f"results/{name}_eval.json"):
132
  continue
133
+ run_eval(args, ck)
 
134
 
135
 
136
  def main():
 
139
  p.add_argument("--hub-repo", default=None)
140
  a = p.parse_args()
141
  if a.hub_repo:
 
142
  os.environ.setdefault("TRACKIO_HUB_REPO", a.hub_repo)
143
  {"lrsweep": stage_lrsweep, "stage1": stage1, "stage2": stage2,
144
  "eval": stage_eval}[a.stage](a)